diff --git a/tests/Unit/Services/Badges/BadgeFormDataServiceTest.php b/tests/Unit/Services/Badges/BadgeFormDataServiceTest.php index 36d0f65f..e34b79b1 100644 --- a/tests/Unit/Services/Badges/BadgeFormDataServiceTest.php +++ b/tests/Unit/Services/Badges/BadgeFormDataServiceTest.php @@ -3,6 +3,7 @@ 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; @@ -19,6 +20,7 @@ class BadgeFormDataServiceTest extends TestCase 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') @@ -51,9 +53,14 @@ class BadgeFormDataServiceTest extends TestCase ->once() ->andReturn(['2025-2026', '2024-2025']); - $service = new BadgeFormDataService($lookup, $formatter); + $studentLookup->shouldReceive('fetchStudentList') + ->once() + ->with('2025-2026', []) + ->andReturn([]); - $result = $service->build('2025-2026', [10, 20], 'teacher'); + $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']); @@ -75,6 +82,7 @@ class BadgeFormDataServiceTest extends TestCase 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') @@ -85,10 +93,14 @@ class BadgeFormDataServiceTest extends TestCase ->once() ->andReturn([]); - $service = new BadgeFormDataService($lookup, $formatter); + $studentLookup->shouldReceive('fetchStudentList') + ->once() + ->andReturn([]); - $result = $service->build('2025-2026', [], 'invalid-role'); + $service = new BadgeFormDataService($lookup, $studentLookup, $formatter); - $this->assertSame('teacher', $result['active_role']); + $result = $service->build('2025-2026', [], [], 'invalid-role'); + + $this->assertSame('all', $result['active_role']); } } diff --git a/tests/Unit/Services/Badges/BadgePdfServiceTest.php b/tests/Unit/Services/Badges/BadgePdfServiceTest.php index 787ae2af..5433cafc 100644 --- a/tests/Unit/Services/Badges/BadgePdfServiceTest.php +++ b/tests/Unit/Services/Badges/BadgePdfServiceTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit\Services\Badges; use App\Services\Badges\BadgePdfService; use App\Services\Badges\BadgePrintLogService; +use App\Services\Badges\BadgeStudentLookupService; use App\Services\Badges\BadgeTextFormatter; use App\Services\Badges\BadgeUserLookupService; use Mockery; @@ -20,10 +21,16 @@ class BadgePdfServiceTest extends TestCase public function test_generate_returns_pdf_response_and_logs_prints(): void { + $studentLookup = Mockery::mock(BadgeStudentLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class); $printLog = Mockery::mock(BadgePrintLogService::class); $formatter = new BadgeTextFormatter; + $studentLookup->shouldReceive('fetchForBadges') + ->once() + ->with([], '2025-2026') + ->andReturn([]); + $lookup->shouldReceive('getUserInfoById') ->once() ->with(10, '2025-2026') @@ -45,9 +52,10 @@ class BadgePdfServiceTest extends TestCase ->once() ->with([10], 1, '2025-2026', [], [], 1); - $service = new BadgePdfService($lookup, $printLog, $formatter); + $service = new BadgePdfService($studentLookup, $lookup, $printLog, $formatter); $response = $service->generate( + studentIds: [], userIds: [10], schoolYear: '2025-2026', rolesMap: [], @@ -57,16 +65,22 @@ class BadgePdfServiceTest extends TestCase $this->assertInstanceOf(SymfonyResponse::class, $response); $this->assertSame('application/pdf', $response->headers->get('Content-Type')); - $this->assertStringContainsString('inline; filename="Staff_Badges.pdf"', $response->headers->get('Content-Disposition')); + $this->assertStringContainsString('inline; filename="Badges.pdf"', $response->headers->get('Content-Disposition')); $this->assertNotEmpty($response->getContent()); } public function test_generate_returns_empty_state_pdf_when_no_valid_users_found(): void { + $studentLookup = Mockery::mock(BadgeStudentLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class); $printLog = Mockery::mock(BadgePrintLogService::class); $formatter = new BadgeTextFormatter; + $studentLookup->shouldReceive('fetchForBadges') + ->once() + ->with([], null) + ->andReturn([]); + $lookup->shouldReceive('getUserInfoById') ->once() ->with(99, null) @@ -76,9 +90,10 @@ class BadgePdfServiceTest extends TestCase ->once() ->with([99], null, null, [], [], 1); - $service = new BadgePdfService($lookup, $printLog, $formatter); + $service = new BadgePdfService($studentLookup, $lookup, $printLog, $formatter); $response = $service->generate( + studentIds: [], userIds: [99], schoolYear: null, rolesMap: [], @@ -92,6 +107,7 @@ class BadgePdfServiceTest extends TestCase public function test_generate_deduplicates_same_badge_content(): void { + $studentLookup = Mockery::mock(BadgeStudentLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class); $printLog = Mockery::mock(BadgePrintLogService::class); $formatter = new BadgeTextFormatter; @@ -110,15 +126,21 @@ class BadgePdfServiceTest extends TestCase 'school_year' => '2025-2026', ]; + $studentLookup->shouldReceive('fetchForBadges') + ->once() + ->with([], '2025-2026') + ->andReturn([]); + $lookup->shouldReceive('getUserInfoById')->once()->andReturn($userInfo); $printLog->shouldReceive('logSafely') ->once() ->with([10], 7, '2025-2026', [], [], 1); - $service = new BadgePdfService($lookup, $printLog, $formatter); + $service = new BadgePdfService($studentLookup, $lookup, $printLog, $formatter); $response = $service->generate( + studentIds: [], userIds: [10, 10], schoolYear: '2025-2026', rolesMap: [],