ldc-arcadia-api/tests/Feature/Console/Commands/ListClientsCommandTest.php
Jérémy Munsch 2ac8578fe0
feat(console): add ListClients command and related presenters
- Implemented ListClientsCommand to list API clients with pagination.
- Created ClientRow, ListClientsPresenter, and ListClientsView for structured output.
- Added tests for ListClientsCommand to ensure correct functionality.
2026-08-18 12:50:55 +02:00

90 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Console\Commands;
use Infra\Database\Models\ApiClient;
use Presentation\Console\Commands\ListClientsCommand;
use Ramsey\Uuid\Uuid;
covers(ListClientsCommand::class);
describe('ListClientsCommand', function (): void {
it('outputs message when no clients exist', function (): void {
// GIVEN
ApiClient::query()->delete();
// WHEN & THEN
$this->artisan('client:list')
->expectsOutput('No clients found.')
->assertSuccessful();
});
it('lists clients in a table when clients exist', function (): void {
// GIVEN
ApiClient::query()->delete();
$client1 = ApiClient::query()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Gateway Alpha',
'identifier' => 'arcadia_id_' . str_repeat('a', 32),
'secret' => 'arcadia_sec_' . str_repeat('b', 86),
'is_active' => true,
]);
$client2 = ApiClient::query()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Gateway Beta',
'identifier' => 'arcadia_id_' . str_repeat('c', 32),
'secret' => 'arcadia_sec_' . str_repeat('d', 86),
'is_active' => false,
]);
// WHEN & THEN
$this->artisan('client:list')
->expectsTable(
['ID', 'Name', 'Identifier', 'Status', 'Created At', 'Updated At'],
[
[
(string) $client1->id,
(string) $client1->name->value,
(string) $client1->identifier->value,
'Active',
$client1->created_at->format('Y-m-d H:i:s'),
$client1->updated_at->format('Y-m-d H:i:s'),
],
[
(string) $client2->id,
(string) $client2->name->value,
(string) $client2->identifier->value,
'Inactive',
$client2->created_at->format('Y-m-d H:i:s'),
$client2->updated_at->format('Y-m-d H:i:s'),
],
]
)
->expectsOutput('Showing page 1/1 (Total: 2 client(s))')
->assertSuccessful();
});
it('respects pagination options', function (): void {
// GIVEN
ApiClient::query()->delete();
for ($i = 1; $i <= 3; $i++) {
ApiClient::query()->create([
'id' => (string) Uuid::uuid7(),
'name' => "Client {$i}",
'identifier' => 'arcadia_id_' . str_repeat((string) $i, 32),
'secret' => 'arcadia_sec_' . str_repeat((string) $i, 86),
'is_active' => true,
]);
}
// WHEN & THEN
$this->artisan('client:list', ['--page' => '2', '--per-page' => '2'])
->expectsOutput('Showing page 2/2 (Total: 3 client(s))')
->assertSuccessful();
});
});