ldc-arcadia-api/tests/Unit/Application/Health/ArcadiaConformityResultTest.php

72 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Health;
use Application\Health\Dto\ArcadiaConformityResult;
use Application\Health\Dto\DirectoryConformityCheck;
use Application\Health\Enums\ComponentStatus;
use Application\Health\Enums\HealthStatus;
covers(ArcadiaConformityResult::class, DirectoryConformityCheck::class);
describe('ArcadiaConformityResult Unit Tests', function (): void {
it('evaluates healthy state and returns healthy checksum', function (): void {
// GIVEN
$date = new \DateTimeImmutable('2026-08-27 15:00:00 UTC');
$checks = [
new DirectoryConformityCheck('brands', ComponentStatus::UP, 'MARQUE', 10),
new DirectoryConformityCheck('employees', ComponentStatus::UP, 'RU_PERSONNE_SIRH', 5),
new DirectoryConformityCheck('inco_sheets', ComponentStatus::UP, 'INCO + FAM_VENTE', 5),
new DirectoryConformityCheck('inco_compositions', ComponentStatus::UP, 'INCO_COMPO', 1),
];
$result = new ArcadiaConformityResult(
status: HealthStatus::HEALTHY,
timestamp: $date,
checks: $checks,
);
// WHEN & THEN
expect($result->isConform())->toBeTrue()
->and($result->hasDissonances())->toBeFalse()
->and($result->checksum())->toBe('healthy')
->and($checks[0]->isUp())->toBeTrue();
});
it('evaluates unhealthy state and generates deterministic SHA-256 checksum for diffing', function (): void {
// GIVEN
$date = new \DateTimeImmutable('2026-08-27 15:00:00 UTC');
$checks1 = [
new DirectoryConformityCheck('brands', ComponentStatus::DOWN, 'MARQUE', 0, 'Column LIB_MARQ not found'),
new DirectoryConformityCheck('employees', ComponentStatus::UP, 'RU_PERSONNE_SIRH', 5),
];
$checks2 = [
new DirectoryConformityCheck('employees', ComponentStatus::UP, 'RU_PERSONNE_SIRH', 5),
new DirectoryConformityCheck('brands', ComponentStatus::DOWN, 'MARQUE', 0, 'Column LIB_MARQ not found'),
];
$checks3 = [
new DirectoryConformityCheck('brands', ComponentStatus::DOWN, 'MARQUE', 0, 'Table MARQUE not found'),
new DirectoryConformityCheck('employees', ComponentStatus::UP, 'RU_PERSONNE_SIRH', 5),
];
$result1 = new ArcadiaConformityResult(HealthStatus::UNHEALTHY, $date, $checks1);
$result2 = new ArcadiaConformityResult(HealthStatus::UNHEALTHY, $date, $checks2);
$result3 = new ArcadiaConformityResult(HealthStatus::UNHEALTHY, $date, $checks3);
// WHEN
$checksum1 = $result1->checksum();
$checksum2 = $result2->checksum();
$checksum3 = $result3->checksum();
// THEN
expect($result1->isConform())->toBeFalse()
->and($result1->hasDissonances())->toBeTrue()
->and($checksum1)->toBe($checksum2) // Deterministic regardless of order
->and($checksum1)->not->toBe($checksum3) // Changes when error changes
->and(strlen($checksum1))->toBe(64); // Valid SHA-256 length
});
});