Updated ApiClient and Employee models to include created_at and updated_at fields for better tracking of records.
97 lines
3.3 KiB
PHP
97 lines
3.3 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 no clients found when database is empty', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
ApiClient::query()->delete();
|
|
|
|
// WHEN
|
|
$this->artisan('client:list')
|
|
// THEN
|
|
->expectsOutput('No clients found.')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('outputs table of clients when clients exist', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
ApiClient::query()->delete();
|
|
|
|
$client1 = ApiClient::factory()->create([
|
|
'id' => (string) Uuid::uuid7(),
|
|
'name' => 'Production Gateway',
|
|
'slug' => 'test-' . uniqid(),
|
|
'identifier' => 'arcadia_id_' . str_repeat('a', 32),
|
|
'secret' => 'arcadia_sec_' . str_repeat('b', 86),
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$client2 = ApiClient::factory()->create([
|
|
'id' => (string) Uuid::uuid7(),
|
|
'name' => 'Backup Gateway',
|
|
'slug' => 'test-' . uniqid(),
|
|
'identifier' => 'arcadia_id_' . str_repeat('c', 32),
|
|
'secret' => 'arcadia_sec_' . str_repeat('d', 86),
|
|
'is_active' => false,
|
|
]);
|
|
|
|
// WHEN
|
|
$this->artisan('client:list')
|
|
// THEN
|
|
->expectsTable(
|
|
['ID', 'Name', 'Identifier', 'Status', 'Last Updated At'],
|
|
[
|
|
[
|
|
(string) $client1->id,
|
|
(string) $client1->name->value,
|
|
(string) $client1->identifier->value,
|
|
'Active',
|
|
$client1->updated_at->format('Y-m-d H:i:s'),
|
|
],
|
|
[
|
|
(string) $client2->id,
|
|
(string) $client2->name->value,
|
|
(string) $client2->identifier->value,
|
|
'Inactive',
|
|
$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
|
|
/** @var \Tests\TestCase $this */
|
|
ApiClient::query()->delete();
|
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
ApiClient::factory()->create([
|
|
'id' => (string) Uuid::uuid7(),
|
|
'name' => "Client {$i}",
|
|
'slug' => 'test-' . uniqid(),
|
|
'identifier' => 'arcadia_id_' . str_repeat((string) $i, 32),
|
|
'secret' => 'arcadia_sec_' . str_repeat((string) $i, 86),
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
// WHEN
|
|
$this->artisan('client:list', ['--page' => '2', '--per-page' => '2'])
|
|
// THEN
|
|
->expectsOutput('Showing page 2/2 (Total: 3 client(s))')
|
|
->assertSuccessful();
|
|
});
|
|
});
|