ldc-arcadia-api/tests/Feature/Console/Commands/ToggleClientStatusCommandTest.php
Jérémy Munsch 62c221f6b6
feat(health): add oracle probe and normalize health checks
Refactor health check DTOs around a common CheckResult contract and remove the\nlegacy HealthChecks aggregate object.\n\nAdd a dedicated /api/v1/health/oracle endpoint with response mapping, OpenAPI\nschema updates, and Bruno request coverage.\n\nAlign feature, unit, integration, architecture and OpenAPI tests with the new\nset-based checks representation and make Oracle health tests deterministic in CI.\n\nUpdate command documentation to the uwil:* command namespace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-06 14:51:46 +02:00

226 lines
8.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Console\Commands;
use Infra\Database\Models\ApiClient;
use Presentation\Console\Commands\ToggleClientStatusCommand;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Console\Tester\CommandCompletionTester;
covers(ToggleClientStatusCommand::class);
describe('ToggleClientStatusCommand', function (): void {
it('errors when an invalid identifier is provided', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$invalidId = 'not-a-valid-identifier';
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status', ['identifier' => $invalidId])
// THEN
->expectsOutput("Invalid client identifier '{$invalidId}'. Expected a valid client identifier.")
->assertFailed();
});
it('errors when client does not exist', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$nonExistentId = 'arcadia_id_' . str_repeat('9', 32);
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status', ['identifier' => $nonExistentId])
// THEN
->expectsOutput("Client '{$nonExistentId}' not found.")
->assertFailed();
});
it('toggles an active client to inactive when no status argument is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = 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,
]);
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status', ['identifier' => (string) $client->identifier->value])
// THEN
->expectsOutput("Client 'Production Gateway' (ID: {$client->id}) is now Inactive.")
->assertSuccessful();
$client->refresh();
expect($client->is_active)->toBeFalse();
});
it('toggles an inactive client to active when no status argument is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = 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('uwil:arcadia:client:toggle-status', ['identifier' => (string) $client->identifier->value])
// THEN
->expectsOutput("Client 'Backup Gateway' (ID: {$client->id}) is now Active.")
->assertSuccessful();
$client->refresh();
expect($client->is_active)->toBeTrue();
});
it('activates an inactive client when activate status is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Special Gateway',
'slug' => 'test-' . uniqid(),
'identifier' => 'arcadia_id_' . str_repeat('e', 32),
'secret' => 'arcadia_sec_' . str_repeat('f', 86),
'is_active' => false,
]);
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status', ['identifier' => (string) $client->identifier->value, 'status' => 'activate'])
// THEN
->expectsOutput("Client 'Special Gateway' (ID: {$client->id}) is now Active.")
->assertSuccessful();
$client->refresh();
expect($client->is_active)->toBeTrue();
});
it('deactivates an active client when deactivate status is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Special Gateway',
'slug' => 'test-' . uniqid(),
'identifier' => 'arcadia_id_' . str_repeat('g', 32),
'secret' => 'arcadia_sec_' . str_repeat('h', 86),
'is_active' => true,
]);
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status', ['identifier' => (string) $client->identifier->value, 'status' => 'deactivate'])
// THEN
->expectsOutput("Client 'Special Gateway' (ID: {$client->id}) is now Inactive.")
->assertSuccessful();
$client->refresh();
expect($client->is_active)->toBeFalse();
});
it('errors when an invalid status is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$identifier = 'arcadia_id_' . str_repeat('z', 32);
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Some Gateway',
'slug' => 'test-' . uniqid(),
'identifier' => $identifier,
'secret' => 'arcadia_sec_' . str_repeat('z', 86),
'is_active' => true,
]);
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status', ['identifier' => $identifier, 'status' => 'unknown'])
// THEN
->expectsOutput("Invalid status 'unknown'. Expected 'activate' or 'deactivate'.")
->assertFailed();
});
it('prompts and searches client interactively when no identifier is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$identifier = 'arcadia_id_' . str_repeat('k', 32);
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Interactive Gateway',
'slug' => 'interactive-gateway',
'identifier' => $identifier,
'secret' => 'arcadia_sec_' . str_repeat('k', 86),
'is_active' => true,
]);
// WHEN
$this->artisan('uwil:arcadia:client:toggle-status')
// THEN
->expectsQuestion('Search client (by name, ID, identifier, or slug):', $identifier)
->expectsChoice('Search client (by name, ID, identifier, or slug):', $identifier, [
$identifier => "Interactive Gateway (Active) - {$identifier}",
])
->expectsOutput("Client 'Interactive Gateway' (ID: {$client->id}) is now Inactive.")
->assertSuccessful();
$client->refresh();
expect($client->is_active)->toBeFalse();
});
it('provides autocompletion suggestions for identifier', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
ApiClient::query()->delete();
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,
]);
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,
]);
/** @var ToggleClientStatusCommand $command */
$command = app(ToggleClientStatusCommand::class);
$tester = new CommandCompletionTester($command);
// WHEN
$suggestions = $tester->complete(['']);
// THEN
expect($suggestions)
->toContain('arcadia_id_' . str_repeat('a', 32))
->toContain('arcadia_id_' . str_repeat('c', 32));
});
it('provides autocompletion suggestions for status argument', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
/** @var ToggleClientStatusCommand $command */
$command = app(ToggleClientStatusCommand::class);
$tester = new CommandCompletionTester($command);
$someId = 'arcadia_id_' . str_repeat('1', 32);
// WHEN
$suggestions = $tester->complete([$someId, '']);
// THEN
expect($suggestions)
->toContain('activate')
->toContain('deactivate');
});
});