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>
103 lines
3.7 KiB
PHP
103 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Health;
|
|
|
|
use Application\Health\Dto\CacheCheckResult;
|
|
use Application\Health\Dto\DatabaseCheckResult;
|
|
use Application\Health\Dto\HealthCheckResult;
|
|
use Application\Health\Dto\MailCheckResult;
|
|
use Application\Health\Enums\ComponentStatus;
|
|
use Application\Health\Enums\HealthStatus;
|
|
|
|
describe('Health Check DTOs & Enums Unit Tests', function (): void {
|
|
it('instantiates DatabaseCheckResult as a pure DTO', function (): void {
|
|
// GIVEN
|
|
$dbUp = new DatabaseCheckResult(
|
|
status: ComponentStatus::UP,
|
|
connection: 'mysql',
|
|
);
|
|
|
|
$dbDown = new DatabaseCheckResult(
|
|
status: ComponentStatus::DOWN,
|
|
connection: 'mysql',
|
|
message: 'Connection refused',
|
|
);
|
|
|
|
// WHEN & THEN
|
|
expect($dbUp->status)->toBe(ComponentStatus::UP)
|
|
->and($dbUp->connection)->toBe('mysql')
|
|
->and($dbUp->message)->toBeNull()
|
|
->and($dbDown->status)->toBe(ComponentStatus::DOWN)
|
|
->and($dbDown->connection)->toBe('mysql')
|
|
->and($dbDown->message)->toBe('Connection refused');
|
|
});
|
|
|
|
it('instantiates CacheCheckResult as a pure DTO', function (): void {
|
|
// GIVEN
|
|
$cacheUp = new CacheCheckResult(
|
|
status: ComponentStatus::UP,
|
|
store: 'redis',
|
|
);
|
|
|
|
$cacheDown = new CacheCheckResult(
|
|
status: ComponentStatus::DOWN,
|
|
store: 'redis',
|
|
message: 'Redis server down',
|
|
);
|
|
|
|
// WHEN & THEN
|
|
expect($cacheUp->status)->toBe(ComponentStatus::UP)
|
|
->and($cacheUp->store)->toBe('redis')
|
|
->and($cacheUp->message)->toBeNull()
|
|
->and($cacheDown->status)->toBe(ComponentStatus::DOWN)
|
|
->and($cacheDown->store)->toBe('redis')
|
|
->and($cacheDown->message)->toBe('Redis server down');
|
|
});
|
|
|
|
it('instantiates MailCheckResult as a pure DTO', function (): void {
|
|
// GIVEN
|
|
$mailSmtp = new MailCheckResult(
|
|
status: ComponentStatus::UP,
|
|
transport: 'smtp',
|
|
);
|
|
|
|
$mailFailed = new MailCheckResult(
|
|
status: ComponentStatus::DOWN,
|
|
transport: 'smtp',
|
|
message: 'Connection refused',
|
|
);
|
|
|
|
// WHEN & THEN
|
|
expect($mailSmtp->status)->toBe(ComponentStatus::UP)
|
|
->and($mailSmtp->transport)->toBe('smtp')
|
|
->and($mailSmtp->message)->toBeNull()
|
|
->and($mailFailed->status)->toBe(ComponentStatus::DOWN)
|
|
->and($mailFailed->transport)->toBe('smtp')
|
|
->and($mailFailed->message)->toBe('Connection refused');
|
|
});
|
|
|
|
it('instantiates HealthCheckResult and evaluates isHealthy', function (): void {
|
|
// GIVEN
|
|
$date = new \DateTimeImmutable('2026-08-21 14:30:00 UTC');
|
|
$checks = [
|
|
'database_default' => new DatabaseCheckResult(ComponentStatus::UP, 'sqlite'),
|
|
'database_arcadia' => new DatabaseCheckResult(ComponentStatus::DOWN, 'arcadia', 'Timeout connecting to DB'),
|
|
'cache' => new CacheCheckResult(ComponentStatus::UP, 'database'),
|
|
'mail_smtp' => new MailCheckResult(ComponentStatus::UP, 'smtp'),
|
|
];
|
|
|
|
$result = new HealthCheckResult(
|
|
status: HealthStatus::UNHEALTHY,
|
|
timestamp: $date,
|
|
checks: $checks,
|
|
);
|
|
|
|
// WHEN & THEN
|
|
expect($result->isHealthy())->toBeFalse()
|
|
->and($result->status)->toBe(HealthStatus::UNHEALTHY)
|
|
->and($result->timestamp)->toBe($date)
|
|
->and($result->checks['database_arcadia']->message)->toBe('Timeout connecting to DB');
|
|
});
|
|
});
|