72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Console\Commands;
|
|
|
|
use Infra\Database\Models\ApiClient;
|
|
use Presentation\Console\Commands\CreateClientCommand;
|
|
|
|
covers(CreateClientCommand::class);
|
|
|
|
describe('CreateClientCommand', function (): void {
|
|
it('creates a client through the wizard', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$clientName = 'Production Gateway';
|
|
|
|
// WHEN
|
|
$this->artisan('client:create')
|
|
// THEN
|
|
->expectsQuestion('Client name (e.g. "Ones Branding website")', $clientName)
|
|
->expectsConfirmation('Create this API client?', 'yes')
|
|
->expectsOutputToContain("API client '{$clientName}' created successfully.")
|
|
->expectsOutputToContain('Store the secret securely')
|
|
->assertSuccessful();
|
|
|
|
$client = ApiClient::query()->where('name', $clientName)->first();
|
|
expect($client)->not->toBeNull()
|
|
->and($client->is_active)->toBeTrue()
|
|
->and($client->name->value)->toBe($clientName)
|
|
->and((string) $client->identifier->value)->toStartWith('arcadia_id_')
|
|
->and((string) $client->secret->value)->toStartWith('arcadia_sec_');
|
|
});
|
|
|
|
it('aborts when user cancels confirmation', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$clientName = 'Cancelled Gateway';
|
|
|
|
// WHEN
|
|
$this->artisan('client:create')
|
|
// THEN
|
|
->expectsQuestion('Client name (e.g. "Ones Branding website")', $clientName)
|
|
->expectsConfirmation('Create this API client?', 'no')
|
|
->expectsOutput('Client creation cancelled.')
|
|
->assertSuccessful();
|
|
|
|
$client = ApiClient::query()->where('name', $clientName)->first();
|
|
expect($client)->toBeNull();
|
|
});
|
|
|
|
it('fails when an empty name is provided', function (): void {
|
|
// GIVEN & WHEN & THEN
|
|
$this->artisan('client:create')
|
|
->expectsQuestion('Client name (e.g. "Ones Branding website")', '')
|
|
->assertFailed();
|
|
});
|
|
|
|
it('fails when the client name already exists', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
ApiClient::factory()->create([
|
|
'name' => 'Existing Gateway',
|
|
'slug' => 'existing-gateway',
|
|
]);
|
|
|
|
// WHEN & THEN
|
|
$this->artisan('client:create')
|
|
->expectsQuestion('Client name (e.g. "Ones Branding website")', 'Existing Gateway')
|
|
->assertFailed();
|
|
});
|
|
});
|