67 lines
2.5 KiB
PHP
67 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Infra\Mail;
|
|
|
|
use Application\Health\Enums\HealthStatus;
|
|
use Infra\Mail\SystemHealthAlertMail;
|
|
|
|
covers(SystemHealthAlertMail::class);
|
|
|
|
describe('SystemHealthAlertMail Unit Test', function (): void {
|
|
it('constructs degraded mail with alert subject and json markdown content', function (): void {
|
|
// GIVEN
|
|
$occurredAt = new \DateTimeImmutable('2026-08-26 12:00:00 UTC');
|
|
$checks = [
|
|
'database_default' => ['status' => 'down', 'connection' => 'mysql', 'message' => 'Connection refused'],
|
|
'database_arcadia' => ['status' => 'up', 'connection' => 'arcadia'],
|
|
];
|
|
|
|
// WHEN
|
|
$mail = new SystemHealthAlertMail(
|
|
status: HealthStatus::UNHEALTHY,
|
|
occurredAt: $occurredAt,
|
|
checks: $checks,
|
|
previousStatus: HealthStatus::HEALTHY,
|
|
);
|
|
|
|
$envelope = $mail->envelope();
|
|
$content = $mail->content();
|
|
|
|
// THEN
|
|
expect($envelope->subject)->toBe('[Arcadia Health] 🛑 System Health Alert - Component DOWN')
|
|
->and($content->markdown)->toBe('mails.health-alert')
|
|
->and($content->with['status'])->toBe('unhealthy')
|
|
->and($content->with['isRecovery'])->toBeFalse()
|
|
->and($content->with['previousStatus'])->toBe('healthy')
|
|
->and($content->with['checksJson'])->toContain('Connection refused');
|
|
});
|
|
|
|
it('constructs recovery mail with recovery subject and json markdown content', function (): void {
|
|
// GIVEN
|
|
$occurredAt = new \DateTimeImmutable('2026-08-26 12:05:00 UTC');
|
|
$checks = [
|
|
'database_default' => ['status' => 'up', 'connection' => 'mysql'],
|
|
'database_arcadia' => ['status' => 'up', 'connection' => 'arcadia'],
|
|
];
|
|
|
|
// WHEN
|
|
$mail = new SystemHealthAlertMail(
|
|
status: HealthStatus::HEALTHY,
|
|
occurredAt: $occurredAt,
|
|
checks: $checks,
|
|
previousStatus: HealthStatus::UNHEALTHY,
|
|
);
|
|
|
|
$envelope = $mail->envelope();
|
|
$content = $mail->content();
|
|
|
|
// THEN
|
|
expect($envelope->subject)->toBe('[Arcadia Health] 🟢 System Health Recovered- Component UP')
|
|
->and($content->markdown)->toBe('mails.health-alert')
|
|
->and($content->with['status'])->toBe('healthy')
|
|
->and($content->with['isRecovery'])->toBeTrue()
|
|
->and($content->with['previousStatus'])->toBe('unhealthy');
|
|
});
|
|
});
|