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>
146 lines
5.4 KiB
PHP
146 lines
5.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\V1\Health;
|
|
|
|
use Illuminate\Support\Facades\Config;
|
|
use Tests\TestCase;
|
|
|
|
describe('Health Check API (GET /api/v1/health)', function (): void {
|
|
$originalDbDefault = null;
|
|
$originalArcadiaDb = null;
|
|
$originalCache = null;
|
|
$originalMail = null;
|
|
$originalMailer = null;
|
|
|
|
beforeEach(function () use (&$originalDbDefault, &$originalArcadiaDb, &$originalCache, &$originalMail, &$originalMailer): void {
|
|
$originalDbDefault = Config::get('database.default');
|
|
$originalArcadiaDb = Config::get('database.arcadia_meta_model');
|
|
$originalCache = Config::get('cache.default');
|
|
$originalMail = Config::get('mail.default');
|
|
$originalMailer = Config::get('mail.mailers.smtp');
|
|
});
|
|
|
|
afterEach(function () use (&$originalDbDefault, &$originalArcadiaDb, &$originalCache, &$originalMail, &$originalMailer): void {
|
|
Config::set('database.default', $originalDbDefault);
|
|
Config::set('database.arcadia_meta_model', $originalArcadiaDb);
|
|
Config::set('cache.default', $originalCache);
|
|
Config::set('mail.default', $originalMail);
|
|
Config::set('mail.mailers.smtp', $originalMailer);
|
|
});
|
|
|
|
it('returns 200 healthy when all infrastructure components are operational', function (): void {
|
|
// GIVEN
|
|
/** @var TestCase $this */
|
|
$databaseDefault = Config::string('database.default');
|
|
$databaseArcadia = Config::string('database.arcadia_meta_model');
|
|
$cacheStore = Config::string('cache.default');
|
|
$mailTransport = Config::string('mail.default');
|
|
|
|
// WHEN
|
|
$response = $this->getJson('/api/v1/health');
|
|
|
|
// THEN
|
|
$response->assertStatus(200)
|
|
->assertJsonStructure([
|
|
'status',
|
|
'timestamp',
|
|
'checks',
|
|
])
|
|
->assertJsonPath('status', 'healthy')
|
|
->assertJsonPath('checks.' . $databaseDefault . '.status', 'up')
|
|
->assertJsonPath('checks.' . $databaseArcadia . '.status', 'up')
|
|
->assertJsonPath('checks.' . $cacheStore . '.status', 'up')
|
|
->assertJsonPath('checks.' . $mailTransport . '.status', 'up');
|
|
});
|
|
|
|
it('returns 503 unhealthy when default database connection fails', function () use (&$originalDbDefault): void {
|
|
// GIVEN
|
|
/** @var TestCase $this */
|
|
Config::set('database.default', 'invalid_connection');
|
|
$databaseDefault = Config::string('database.default');
|
|
|
|
try {
|
|
// WHEN
|
|
$response = $this->getJson('/api/v1/health');
|
|
|
|
// THEN
|
|
$response->assertStatus(503)
|
|
->assertJsonPath('status', 'unhealthy')
|
|
->assertJsonPath('checks.' . $databaseDefault . '.status', 'down');
|
|
} finally {
|
|
Config::set('database.default', $originalDbDefault);
|
|
}
|
|
});
|
|
|
|
it('returns 503 unhealthy when arcadia database connection fails', function () use (&$originalArcadiaDb): void {
|
|
// GIVEN
|
|
/** @var TestCase $this */
|
|
Config::set('database.connections.invalid_arcadia_connection', [
|
|
'driver' => 'mysql',
|
|
'host' => '127.0.0.1',
|
|
'port' => 65433,
|
|
'database' => 'invalid_arcadia_db',
|
|
]);
|
|
Config::set('database.arcadia_meta_model', 'invalid_arcadia_connection');
|
|
$databaseArcadia = Config::string('database.arcadia_meta_model');
|
|
|
|
try {
|
|
// WHEN
|
|
$response = $this->getJson('/api/v1/health');
|
|
|
|
// THEN
|
|
$response->assertStatus(503)
|
|
->assertJsonPath('status', 'unhealthy')
|
|
->assertJsonPath('checks.' . $databaseArcadia . '.status', 'down');
|
|
} finally {
|
|
Config::set('database.arcadia_meta_model', $originalArcadiaDb);
|
|
}
|
|
});
|
|
|
|
it('returns 503 unhealthy when cache store fails', function () use (&$originalCache): void {
|
|
// GIVEN
|
|
/** @var TestCase $this */
|
|
Config::set('cache.default', 'invalid_cache_store');
|
|
$cacheStore = Config::string('cache.default');
|
|
|
|
try {
|
|
// WHEN
|
|
$response = $this->getJson('/api/v1/health');
|
|
|
|
// THEN
|
|
$response->assertStatus(503)
|
|
->assertJsonPath('status', 'unhealthy')
|
|
->assertJsonPath('checks.' . $cacheStore . '.status', 'down');
|
|
} finally {
|
|
Config::set('cache.default', $originalCache);
|
|
}
|
|
});
|
|
|
|
it('returns 503 unhealthy when smtp server connection fails', function () use (&$originalMail, &$originalMailer): void {
|
|
// GIVEN
|
|
/** @var TestCase $this */
|
|
Config::set('mail.default', 'smtp');
|
|
Config::set('mail.mailers.smtp', [
|
|
'transport' => 'smtp',
|
|
'host' => '127.0.0.1',
|
|
'port' => 65432, // Non-existent port
|
|
'timeout' => 0.1,
|
|
]);
|
|
$mailTransport = Config::string('mail.default');
|
|
|
|
try {
|
|
// WHEN
|
|
$response = $this->getJson('/api/v1/health');
|
|
|
|
// THEN
|
|
$response->assertStatus(503)
|
|
->assertJsonPath('status', 'unhealthy')
|
|
->assertJsonPath('checks.' . $mailTransport . '.status', 'down');
|
|
} finally {
|
|
Config::set('mail.default', $originalMail);
|
|
Config::set('mail.mailers.smtp', $originalMailer);
|
|
}
|
|
});
|
|
});
|