1f72d082ac
API CI/CD / Validate (composer + pint) (push) Successful in 2m6s
API CI/CD / Test (PHPUnit) (push) Failing after 2m29s
API CI/CD / Build frontend assets (push) Successful in 2m24s
API CI/CD / Security audit (push) Successful in 33s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
- BadgeFormDataServiceTest: add missing BadgeStudentLookupService mock, update build() signature with param, fix default role assertion (teacher → all) - BadgePdfServiceTest: add missing BadgeStudentLookupService mock as first constructor arg, update generate() calls with studentIds:, fix filename assertion (Staff_Badges.pdf → Badges.pdf) These constructors were refactored to accept a new BadgeStudentLookupService dependency and reordered parameters, but the unit tests were never updated, causing TypeError failures.
107 lines
3.6 KiB
PHP
107 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Badges;
|
|
|
|
use App\Services\Badges\BadgeFormDataService;
|
|
use App\Services\Badges\BadgeStudentLookupService;
|
|
use App\Services\Badges\BadgeTextFormatter;
|
|
use App\Services\Badges\BadgeUserLookupService;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class BadgeFormDataServiceTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_build_formats_users_and_assigns_latest_class_for_teacherish_roles(): void
|
|
{
|
|
$lookup = Mockery::mock(BadgeUserLookupService::class);
|
|
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
|
|
$formatter = new BadgeTextFormatter;
|
|
|
|
$lookup->shouldReceive('fetchStaffList')
|
|
->once()
|
|
->with('2025-2026', [10, 20])
|
|
->andReturn([
|
|
[
|
|
'id' => 10,
|
|
'firstname' => 'John',
|
|
'lastname' => 'Doe',
|
|
'roles' => 'teacher_assistant,admin',
|
|
],
|
|
[
|
|
'id' => 20,
|
|
'firstname' => 'Sara',
|
|
'lastname' => 'Smith',
|
|
'roles' => 'staff',
|
|
],
|
|
]);
|
|
|
|
$lookup->shouldReceive('getLatestClassForUser')
|
|
->once()
|
|
->with(10, '2025-2026')
|
|
->andReturn([
|
|
'class_section_id' => 5,
|
|
'class_section_name' => '3-A',
|
|
]);
|
|
|
|
$lookup->shouldReceive('getAvailableSchoolYears')
|
|
->once()
|
|
->andReturn(['2025-2026', '2024-2025']);
|
|
|
|
$studentLookup->shouldReceive('fetchStudentList')
|
|
->once()
|
|
->with('2025-2026', [])
|
|
->andReturn([]);
|
|
|
|
$service = new BadgeFormDataService($lookup, $studentLookup, $formatter);
|
|
|
|
$result = $service->build('2025-2026', [10, 20], [], 'teacher');
|
|
|
|
$this->assertSame('2025-2026', $result['selectedYear']);
|
|
$this->assertSame([10, 20], $result['selectedUserIds']);
|
|
$this->assertSame('teacher', $result['active_role']);
|
|
$this->assertCount(2, $result['users']);
|
|
|
|
$this->assertSame(10, $result['users'][0]['user_id']);
|
|
$this->assertSame('Teacher Assistant, Admin', $result['users'][0]['roles']);
|
|
$this->assertSame('teacher_assistant', $result['users'][0]['role_name_raw']);
|
|
$this->assertSame('Teacher Assistant', $result['users'][0]['role_name']);
|
|
$this->assertSame(5, $result['users'][0]['class_section_id']);
|
|
$this->assertSame('3-A', $result['users'][0]['class_section_name']);
|
|
|
|
$this->assertSame(20, $result['users'][1]['user_id']);
|
|
$this->assertSame('Staff', $result['users'][1]['roles']);
|
|
$this->assertNull($result['users'][1]['class_section_id']);
|
|
}
|
|
|
|
public function test_build_defaults_invalid_active_role_to_teacher(): void
|
|
{
|
|
$lookup = Mockery::mock(BadgeUserLookupService::class);
|
|
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
|
|
$formatter = new BadgeTextFormatter;
|
|
|
|
$lookup->shouldReceive('fetchStaffList')
|
|
->once()
|
|
->andReturn([]);
|
|
|
|
$lookup->shouldReceive('getAvailableSchoolYears')
|
|
->once()
|
|
->andReturn([]);
|
|
|
|
$studentLookup->shouldReceive('fetchStudentList')
|
|
->once()
|
|
->andReturn([]);
|
|
|
|
$service = new BadgeFormDataService($lookup, $studentLookup, $formatter);
|
|
|
|
$result = $service->build('2025-2026', [], [], 'invalid-role');
|
|
|
|
$this->assertSame('all', $result['active_role']);
|
|
}
|
|
}
|