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>
102 lines
4.1 KiB
PHP
102 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Console\Commands;
|
|
|
|
use Application\Health\Contracts\HealthChecker;
|
|
use Application\Health\Dto\ArcadiaConformityResult;
|
|
use Application\Health\Dto\DirectoryConformityCheck;
|
|
use Application\Health\Enums\ComponentStatus;
|
|
use Application\Health\Enums\HealthStatus;
|
|
use Presentation\Console\Commands\CheckArcadiaConformityCommand;
|
|
use Shared\Time\Utc;
|
|
|
|
covers(CheckArcadiaConformityCommand::class);
|
|
|
|
describe('CheckArcadiaConformityCommand', function (): void {
|
|
it('returns success and renders table when database is conform', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$healthChecker = mock(HealthChecker::class);
|
|
$result = new ArcadiaConformityResult(
|
|
status: HealthStatus::HEALTHY,
|
|
timestamp: Utc::now(),
|
|
checks: [
|
|
new DirectoryConformityCheck('brands', ComponentStatus::UP, 'MARQUE', 10),
|
|
new DirectoryConformityCheck('employees', ComponentStatus::UP, 'RU_PERSONNE_SIRH', 5),
|
|
],
|
|
);
|
|
$healthChecker->shouldReceive('checkArcadiaConformity')->once()->andReturn($result);
|
|
$this->app->instance(HealthChecker::class, $healthChecker);
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:arcadia:database:check-conformity')
|
|
// THEN
|
|
->expectsOutput('Arcadia database conformity check passed. All directory probes are conform.')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('returns failure and renders table when database has dissonances', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$healthChecker = mock(HealthChecker::class);
|
|
$result = new ArcadiaConformityResult(
|
|
status: HealthStatus::UNHEALTHY,
|
|
timestamp: Utc::now(),
|
|
checks: [
|
|
new DirectoryConformityCheck('brands', ComponentStatus::DOWN, 'MARQUE', 0, 'Column LIB_MARQ missing'),
|
|
],
|
|
);
|
|
$healthChecker->shouldReceive('checkArcadiaConformity')->once()->andReturn($result);
|
|
$this->app->instance(HealthChecker::class, $healthChecker);
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:arcadia:database:check-conformity')
|
|
// THEN
|
|
->expectsOutput('Arcadia database conformity check failed. Dissonances detected.')
|
|
->assertFailed();
|
|
});
|
|
|
|
it('outputs JSON when --json option is passed and succeeds when conform', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$healthChecker = mock(HealthChecker::class);
|
|
$result = new ArcadiaConformityResult(
|
|
status: HealthStatus::HEALTHY,
|
|
timestamp: Utc::now(),
|
|
checks: [
|
|
new DirectoryConformityCheck('brands', ComponentStatus::UP, 'MARQUE', 10),
|
|
],
|
|
);
|
|
$healthChecker->shouldReceive('checkArcadiaConformity')->once()->andReturn($result);
|
|
$this->app->instance(HealthChecker::class, $healthChecker);
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:arcadia:database:check-conformity', ['--json' => true])
|
|
// THEN
|
|
->expectsOutputToContain('"status": "healthy"')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('outputs JSON when --json option is passed and fails when non-conform', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$healthChecker = mock(HealthChecker::class);
|
|
$result = new ArcadiaConformityResult(
|
|
status: HealthStatus::UNHEALTHY,
|
|
timestamp: Utc::now(),
|
|
checks: [
|
|
new DirectoryConformityCheck('brands', ComponentStatus::DOWN, 'MARQUE', 0, 'Table MARQUE not found'),
|
|
],
|
|
);
|
|
$healthChecker->shouldReceive('checkArcadiaConformity')->once()->andReturn($result);
|
|
$this->app->instance(HealthChecker::class, $healthChecker);
|
|
|
|
// WHEN
|
|
$this->artisan('uwil:arcadia:database:check-conformity', ['--json' => true])
|
|
// THEN
|
|
->expectsOutputToContain('"status": "unhealthy"')
|
|
->assertFailed();
|
|
});
|
|
});
|