84 lines
3 KiB
PHP
84 lines
3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Infra\Mail;
|
||
|
|
|
||
|
|
use Application\Health\Enums\HealthStatus;
|
||
|
|
use Infra\Mail\ArcadiaConformityAlertMail;
|
||
|
|
|
||
|
|
covers(ArcadiaConformityAlertMail::class);
|
||
|
|
|
||
|
|
describe('ArcadiaConformityAlertMail Unit Test', function (): void {
|
||
|
|
it('constructs degraded mail with dissonance subject and checks json content', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$occurredAt = new \DateTimeImmutable('2026-08-27 15:00:00 UTC');
|
||
|
|
$checks = [
|
||
|
|
[
|
||
|
|
'name' => 'brands',
|
||
|
|
'status' => 'down',
|
||
|
|
'target' => 'MARQUE',
|
||
|
|
'sample_count' => 0,
|
||
|
|
'error_message' => 'Column LIB_MARQ not found',
|
||
|
|
],
|
||
|
|
];
|
||
|
|
$checksum = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$mail = new ArcadiaConformityAlertMail(
|
||
|
|
status: HealthStatus::UNHEALTHY,
|
||
|
|
occurredAt: $occurredAt,
|
||
|
|
checks: $checks,
|
||
|
|
checksum: $checksum,
|
||
|
|
previousStatus: HealthStatus::HEALTHY,
|
||
|
|
);
|
||
|
|
|
||
|
|
$envelope = $mail->envelope();
|
||
|
|
$content = $mail->content();
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($envelope->subject)->toBe('[Arcadia Health] 🔴 Arcadia Database Dissonance Alert - Schema Non-Conform')
|
||
|
|
->and($content->markdown)->toBe('mails.arcadia-conformity-alert')
|
||
|
|
->and($content->with['status'])->toBe('unhealthy')
|
||
|
|
->and($content->with['isRecovery'])->toBeFalse()
|
||
|
|
->and($content->with['checksum'])->toBe($checksum)
|
||
|
|
->and($content->with['previousStatus'])->toBe('healthy')
|
||
|
|
->and($content->with['checksJson'])->toContain('Column LIB_MARQ not found');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('constructs recovery mail with recovery subject and checks json content', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$occurredAt = new \DateTimeImmutable('2026-08-27 15:30:00 UTC');
|
||
|
|
$checks = [
|
||
|
|
[
|
||
|
|
'name' => 'brands',
|
||
|
|
'status' => 'up',
|
||
|
|
'target' => 'MARQUE',
|
||
|
|
'sample_count' => 10,
|
||
|
|
'error_message' => null,
|
||
|
|
],
|
||
|
|
];
|
||
|
|
$checksum = 'healthy';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$mail = new ArcadiaConformityAlertMail(
|
||
|
|
status: HealthStatus::HEALTHY,
|
||
|
|
occurredAt: $occurredAt,
|
||
|
|
checks: $checks,
|
||
|
|
checksum: $checksum,
|
||
|
|
previousStatus: HealthStatus::UNHEALTHY,
|
||
|
|
);
|
||
|
|
|
||
|
|
$envelope = $mail->envelope();
|
||
|
|
$content = $mail->content();
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($envelope->subject)->toBe('[Arcadia Health] 🟢 Arcadia Database Conformity Recovered')
|
||
|
|
->and($content->markdown)->toBe('mails.arcadia-conformity-alert')
|
||
|
|
->and($content->with['status'])->toBe('healthy')
|
||
|
|
->and($content->with['isRecovery'])->toBeTrue()
|
||
|
|
->and($content->with['checksum'])->toBe('healthy')
|
||
|
|
->and($content->with['previousStatus'])->toBe('unhealthy');
|
||
|
|
});
|
||
|
|
});
|