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>
77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Console\Commands;
|
|
|
|
use Illuminate\Support\Facades\Config;
|
|
use Presentation\Console\Commands\HealthCheckCommand;
|
|
|
|
covers(HealthCheckCommand::class);
|
|
|
|
describe('HealthCheckCommand', function (): void {
|
|
$originalDbDefault = null;
|
|
$originalArcadiaDb = null;
|
|
$originalCache = null;
|
|
$originalMail = null;
|
|
|
|
beforeEach(function () use (&$originalDbDefault, &$originalArcadiaDb, &$originalCache, &$originalMail): void {
|
|
$originalDbDefault = Config::get('database.default');
|
|
$originalArcadiaDb = Config::get('database.arcadia_meta_model');
|
|
$originalCache = Config::get('cache.default');
|
|
$originalMail = Config::get('mail.default');
|
|
});
|
|
|
|
afterEach(function () use (&$originalDbDefault, &$originalArcadiaDb, &$originalCache, &$originalMail): void {
|
|
Config::set('database.default', $originalDbDefault);
|
|
Config::set('database.arcadia_meta_model', $originalArcadiaDb);
|
|
Config::set('cache.default', $originalCache);
|
|
Config::set('mail.default', $originalMail);
|
|
});
|
|
|
|
it('returns success when all components are healthy', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:health:check')
|
|
// THEN
|
|
->expectsOutput('Health check passed. All components are healthy.')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('returns failure when a component is unhealthy', function () use (&$originalDbDefault): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
Config::set('database.default', 'invalid_connection');
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:health:check')
|
|
// THEN
|
|
->expectsOutput('Health check failed. One or more components are unhealthy.')
|
|
->assertFailed();
|
|
});
|
|
|
|
it('outputs JSON when --json option is passed and succeeds when healthy', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:health:check', ['--json' => true])
|
|
// THEN
|
|
->expectsOutputToContain('"status": "healthy"')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('outputs JSON when --json option is passed and fails when unhealthy', function () use (&$originalDbDefault): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
Config::set('database.default', 'invalid_connection');
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:health:check', ['--json' => true])
|
|
// THEN
|
|
->expectsOutputToContain('"status": "unhealthy"')
|
|
->assertFailed();
|
|
});
|
|
});
|