70 lines
2.8 KiB
PHP
70 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\Infra\Services\Health;
|
|
|
|
use Application\Health\Enums\ComponentStatus;
|
|
use Application\Health\Enums\HealthStatus;
|
|
use Database\ArcadiaReplicate\Migrator;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Infra\Config\ArcadiaStorageConfig;
|
|
use Infra\Services\Health\LaravelSystemHealthChecker;
|
|
use Tests\TestCase;
|
|
|
|
covers(LaravelSystemHealthChecker::class);
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
describe('LaravelSystemHealthChecker checkArcadiaConformity Integration Test', function (): void {
|
|
it('returns healthy status when all 56 replicated tables and views exist', function (): void {
|
|
// GIVEN
|
|
$storageConfig = resolve(ArcadiaStorageConfig::class);
|
|
$checker = new LaravelSystemHealthChecker($storageConfig);
|
|
|
|
// WHEN
|
|
$result = $checker->checkArcadiaConformity();
|
|
|
|
// THEN
|
|
expect($result->isConform())->toBeTrue()
|
|
->and($result->status)->toBe(HealthStatus::HEALTHY)
|
|
->and(count($result->checks))->toBe(count(Migrator::DEFINITIONS));
|
|
|
|
foreach ($result->checks as $check) {
|
|
expect($check->status)->toBe(ComponentStatus::UP)
|
|
->and($check->errorMessage)->toBeNull();
|
|
}
|
|
});
|
|
|
|
it('returns unhealthy status with captured dissonance when tables like ADDITIF or FAM_VENTE are missing or renamed', function (): void {
|
|
// GIVEN
|
|
$storageConfig = resolve(ArcadiaStorageConfig::class);
|
|
$checker = new LaravelSystemHealthChecker($storageConfig);
|
|
|
|
// Drop ADDITIF and FAM_VENTE to simulate table rename/removal in Oracle schema
|
|
Schema::connection($storageConfig->databaseConnection)->dropIfExists('ADDITIF');
|
|
Schema::connection($storageConfig->databaseConnection)->dropIfExists('FAM_VENTE');
|
|
|
|
// WHEN
|
|
$result = $checker->checkArcadiaConformity();
|
|
|
|
// THEN
|
|
expect($result->isConform())->toBeFalse()
|
|
->and($result->hasDissonances())->toBeTrue()
|
|
->and($result->status)->toBe(HealthStatus::UNHEALTHY);
|
|
|
|
$additifCheck = collect($result->checks)->firstWhere('name', 'additif');
|
|
$famVenteCheck = collect($result->checks)->firstWhere('name', 'fam_vente');
|
|
$marqueCheck = collect($result->checks)->firstWhere('name', 'marque');
|
|
|
|
expect($additifCheck)->not->toBeNull()
|
|
->and($additifCheck->status)->toBe(ComponentStatus::DOWN)
|
|
->and($additifCheck->errorMessage)->not->toBeNull()
|
|
->and($famVenteCheck)->not->toBeNull()
|
|
->and($famVenteCheck->status)->toBe(ComponentStatus::DOWN)
|
|
->and($famVenteCheck->errorMessage)->not->toBeNull()
|
|
->and($marqueCheck)->not->toBeNull()
|
|
->and($marqueCheck->status)->toBe(ComponentStatus::UP);
|
|
});
|
|
});
|