From aca627ff78b4a376298fc3716ef450d8721d833b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 20 Aug 2026 18:22:20 +0200 Subject: [PATCH] test(presentation): add missing unit tests for API and Console presenters --- .../Employees/EmployeeShowPresenterTest.php | 54 ++++++++++ .../Employees/EmployeesIndexPresenterTest.php | 53 ++++++++++ .../IncoCompositionShowPresenterTest.php | 89 +++++++++++++++++ .../IncoSheetsIndexPresenterTest.php | 49 +++++++++ .../IncoSheetsSearchPresenterTest.php | 49 +++++++++ .../IncoSheetsShowPresenterTest.php | 59 +++++++++++ .../Clients/CreateClientPresenterTest.php | 49 +++++++++ .../Clients/FindClientPresenterTest.php | 61 ++++++++++++ .../Clients/ListClientsPresenterTest.php | 99 +++++++++++++++++++ .../RegenerateClientSecretPresenterTest.php | 40 ++++++++ .../Clients/SetClientStatusPresenterTest.php | 73 ++++++++++++++ 11 files changed, 675 insertions(+) create mode 100644 tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeeShowPresenterTest.php create mode 100644 tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeesIndexPresenterTest.php create mode 100644 tests/Unit/Presentation/Api/V1/Presenters/IncoCompositions/IncoCompositionShowPresenterTest.php create mode 100644 tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexPresenterTest.php create mode 100644 tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsSearchPresenterTest.php create mode 100644 tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsShowPresenterTest.php create mode 100644 tests/Unit/Presentation/Console/Presenters/Clients/CreateClientPresenterTest.php create mode 100644 tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php create mode 100644 tests/Unit/Presentation/Console/Presenters/Clients/ListClientsPresenterTest.php create mode 100644 tests/Unit/Presentation/Console/Presenters/Clients/RegenerateClientSecretPresenterTest.php create mode 100644 tests/Unit/Presentation/Console/Presenters/Clients/SetClientStatusPresenterTest.php diff --git a/tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeeShowPresenterTest.php b/tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeeShowPresenterTest.php new file mode 100644 index 0000000..6caaad5 --- /dev/null +++ b/tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeeShowPresenterTest.php @@ -0,0 +1,54 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(EmployeeShowView::class) + ->and($view->id)->toBe($id) + ->and($view->firstName)->toBe('Jean') + ->and($view->lastName)->toBe('DUPONT') + ->and($view->establishment)->toBe('01') + ->and($view->site)->toBe('LDCSER') + ->and($view->service)->toBe('097') + ->and($view->startDate)->toBe($startDate) + ->and($view->endDate)->toBe($endDate) + ->and($view->plannedEndDate)->toBe($plannedEndDate); + }); +}); diff --git a/tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeesIndexPresenterTest.php b/tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeesIndexPresenterTest.php new file mode 100644 index 0000000..0a7a05b --- /dev/null +++ b/tests/Unit/Presentation/Api/V1/Presenters/Employees/EmployeesIndexPresenterTest.php @@ -0,0 +1,53 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(EmployeesIndexView::class) + ->and($view->employees)->toHaveCount(1) + ->and($view->employees[0])->toBe($employee) + ->and($view->total)->toBe(1) + ->and($view->page)->toBe(1) + ->and($view->perPage)->toBe(25); + }); +}); diff --git a/tests/Unit/Presentation/Api/V1/Presenters/IncoCompositions/IncoCompositionShowPresenterTest.php b/tests/Unit/Presentation/Api/V1/Presenters/IncoCompositions/IncoCompositionShowPresenterTest.php new file mode 100644 index 0000000..72ac134 --- /dev/null +++ b/tests/Unit/Presentation/Api/V1/Presenters/IncoCompositions/IncoCompositionShowPresenterTest.php @@ -0,0 +1,89 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(IncoCompositionShowView::class) + ->and($view->output)->toBe($output); + }); +}); diff --git a/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexPresenterTest.php b/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexPresenterTest.php new file mode 100644 index 0000000..b048ae6 --- /dev/null +++ b/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexPresenterTest.php @@ -0,0 +1,49 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(IncoSheetsIndexView::class) + ->and($view->incoSheets)->toHaveCount(1) + ->and($view->incoSheets[0])->toBe($sheet) + ->and($view->total)->toBe(1) + ->and($view->page)->toBe(1) + ->and($view->perPage)->toBe(25); + }); +}); diff --git a/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsSearchPresenterTest.php b/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsSearchPresenterTest.php new file mode 100644 index 0000000..5193495 --- /dev/null +++ b/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsSearchPresenterTest.php @@ -0,0 +1,49 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(IncoSheetsSearchView::class) + ->and($view->incoSheets)->toHaveCount(1) + ->and($view->incoSheets[0])->toBe($sheet) + ->and($view->total)->toBe(1) + ->and($view->page)->toBe(1) + ->and($view->perPage)->toBe(25); + }); +}); diff --git a/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsShowPresenterTest.php b/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsShowPresenterTest.php new file mode 100644 index 0000000..f0af8a4 --- /dev/null +++ b/tests/Unit/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsShowPresenterTest.php @@ -0,0 +1,59 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(IncoSheetsShowView::class) + ->and($view->output)->toBe($output); + }); +}); diff --git a/tests/Unit/Presentation/Console/Presenters/Clients/CreateClientPresenterTest.php b/tests/Unit/Presentation/Console/Presenters/Clients/CreateClientPresenterTest.php new file mode 100644 index 0000000..1a57323 --- /dev/null +++ b/tests/Unit/Presentation/Console/Presenters/Clients/CreateClientPresenterTest.php @@ -0,0 +1,49 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(CreateClientView::class) + ->and($view->id)->toBe($clientId->value) + ->and($view->name)->toBe('Test Client') + ->and($view->identifier)->toBe($identifier->value) + ->and($view->secret)->toBe($secret->value) + ->and($view->message)->toBe("API client 'Test Client' created successfully."); + }); +}); diff --git a/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php b/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php new file mode 100644 index 0000000..3560b97 --- /dev/null +++ b/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php @@ -0,0 +1,61 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(FindClientView::class) + ->and($view->total)->toBe(1) + ->and($view->clients)->toHaveCount(1) + ->and($view->clients[0]->id)->toBe($clientId->value) + ->and($view->clients[0]->name)->toBe('Test Client') + ->and($view->clients[0]->identifier)->toBe($identifier->value) + ->and($view->clients[0]->isActive)->toBeTrue() + ->and($view->clients[0]->display)->toBe("Test Client (Active) - {$identifier->value}"); + }); +}); diff --git a/tests/Unit/Presentation/Console/Presenters/Clients/ListClientsPresenterTest.php b/tests/Unit/Presentation/Console/Presenters/Clients/ListClientsPresenterTest.php new file mode 100644 index 0000000..5920f91 --- /dev/null +++ b/tests/Unit/Presentation/Console/Presenters/Clients/ListClientsPresenterTest.php @@ -0,0 +1,99 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(ListClientsView::class) + ->and($view->total)->toBe(1) + ->and($view->page)->toBe(1) + ->and($view->perPage)->toBe(25) + ->and($view->totalPages)->toBe(1) + ->and($view->rows)->toHaveCount(1) + ->and($view->rows[0]->id)->toBe($clientId->value) + ->and($view->rows[0]->name)->toBe('Client 1') + ->and($view->rows[0]->identifier)->toBe($identifier->value) + ->and($view->rows[0]->status)->toBe('Active') + ->and($view->rows[0]->lastUpdatedAt)->toBe('2024-01-15 10:30:00'); + }); + + it('handles inactive client status and calculates total pages correctly', function (): void { + // GIVEN + $clientId = new ClientId(Uuid::uuid7()); + $identifier = new ClientIdentifier('arcadia_id_' . str_repeat('b', 32)); + $name = new ClientName('Inactive Client'); + $updatedAt = new \DateTimeImmutable('2024-01-15 10:30:00'); + + $client = new PaginatedClient( + id: $clientId, + identifier: $identifier, + name: $name, + isActive: false, + createdAt: new \DateTimeImmutable('2024-01-01 08:00:00'), + updatedAt: $updatedAt, + ); + + $output = new Output( + clients: [$client], + total: 55, + page: 1, + perPage: 25, + ); + + $presenter = new ListClientsPresenter(); + + // WHEN + $view = $presenter->present($output); + + // THEN + expect($view)->toBeInstanceOf(ListClientsView::class) + ->and($view->totalPages)->toBe(3) + ->and($view->rows[0]->status)->toBe('Inactive'); + }); +}); diff --git a/tests/Unit/Presentation/Console/Presenters/Clients/RegenerateClientSecretPresenterTest.php b/tests/Unit/Presentation/Console/Presenters/Clients/RegenerateClientSecretPresenterTest.php new file mode 100644 index 0000000..9906f0b --- /dev/null +++ b/tests/Unit/Presentation/Console/Presenters/Clients/RegenerateClientSecretPresenterTest.php @@ -0,0 +1,40 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(RegenerateClientSecretView::class) + ->and($view->identifier)->toBe($identifier->value) + ->and($view->secret)->toBe($newSecret->value) + ->and($view->message)->toBe("Secret for client '{$identifier->value}' regenerated successfully."); + }); +}); diff --git a/tests/Unit/Presentation/Console/Presenters/Clients/SetClientStatusPresenterTest.php b/tests/Unit/Presentation/Console/Presenters/Clients/SetClientStatusPresenterTest.php new file mode 100644 index 0000000..bb19a8c --- /dev/null +++ b/tests/Unit/Presentation/Console/Presenters/Clients/SetClientStatusPresenterTest.php @@ -0,0 +1,73 @@ +present($output); + + // THEN + expect($view)->toBeInstanceOf(ToggleClientStatusView::class) + ->and($view->id)->toBe($clientId->value) + ->and($view->name)->toBe('Client 1') + ->and($view->identifier)->toBe($identifier->value) + ->and($view->isActive)->toBeTrue() + ->and($view->statusLabel)->toBe('Active') + ->and($view->message)->toBe("Client 'Client 1' (ID: {$clientId->value}) is now Active."); + }); + + it('transforms Output into ToggleClientStatusView for inactive status', function (): void { + // GIVEN + $clientId = new ClientId(Uuid::uuid7()); + $identifier = new ClientIdentifier('arcadia_id_' . str_repeat('b', 32)); + $name = new ClientName('Client 2'); + + $output = new Output( + clientId: $clientId, + clientIdentifier: $identifier, + clientName: $name, + isActive: false, + ); + + $presenter = new SetClientStatusPresenter(); + + // WHEN + $view = $presenter->present($output); + + // THEN + expect($view)->toBeInstanceOf(ToggleClientStatusView::class) + ->and($view->isActive)->toBeFalse() + ->and($view->statusLabel)->toBe('Inactive') + ->and($view->message)->toBe("Client 'Client 2' (ID: {$clientId->value}) is now Inactive."); + }); +});