ldc-arcadia-api/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php

63 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Presentation\Console\Presenters\Clients;
use Application\Security\Models\Entities\Client;
use Application\Security\Models\ValueObjects\ClientIdentifier;
use Application\Security\Models\ValueObjects\ClientName;
use Application\Security\Models\ValueObjects\ClientSecret;
use Application\Security\Models\ValueObjects\Entities\ClientId;
use Application\Security\Usecases\FindClient\Output;
use Presentation\Console\Presenters\Clients\FindClientPresenter;
use Presentation\Console\Presenters\Clients\FindClientView;
use Presentation\Console\Presenters\Clients\FoundClientItem;
use Ramsey\Uuid\Uuid;
use Shared\Paginated;
use Shared\Pagination;
use Shared\Pagination\PageNumber;
use Shared\Pagination\PageSize;
covers(
FindClientPresenter::class,
FindClientView::class,
FoundClientItem::class,
);
describe('FindClientPresenter Unit Tests', function (): void {
it('transforms Output into FindClientView with formatted client items', function (): void {
// GIVEN
$clientId = new ClientId(Uuid::uuid7());
$name = new ClientName('Test Client');
$identifier = new ClientIdentifier('arcadia_id_' . str_repeat('a', 32));
$secret = new ClientSecret('arcadia_sec_' . str_repeat('b', 86));
$client = Client::hydrate(
id: $clientId,
name: $name,
identifier: $identifier,
secret: $secret,
isActive: true,
updatedAt: new \DateTimeImmutable('2024-01-01'),
);
$paginated = new Paginated(Pagination::ofPage(new PageNumber(1), new PageSize(10)), [$client], 1);
$output = new Output($paginated);
$presenter = new FindClientPresenter();
// WHEN
$view = $presenter->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}");
});
});