Certificate manager built on Laravel 13, Livewire 4, and Flux. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
51 lines
1.9 KiB
PHP
51 lines
1.9 KiB
PHP
<?php
|
|
|
|
use App\Models\Certificate;
|
|
use App\Models\User;
|
|
use App\Notifications\CertificateExpiredNotification;
|
|
use App\Notifications\CertificateExpiringNotification;
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
beforeEach(function () {
|
|
Notification::fake();
|
|
});
|
|
|
|
test('an advance reminder is sent on the user threshold date', function () {
|
|
$user = User::factory()->create(['reminder_months_before' => 1]);
|
|
$certificate = Certificate::factory()->for($user)->create([
|
|
'expires_at' => today()->addMonth(),
|
|
]);
|
|
|
|
$this->artisan('app:send-certificate-reminders')->assertSuccessful();
|
|
|
|
Notification::assertSentTo($user, CertificateExpiringNotification::class);
|
|
expect($certificate->refresh()->last_reminded_at)->not->toBeNull();
|
|
});
|
|
|
|
test('an urgent reminder is sent for certificates expiring today', function () {
|
|
$user = User::factory()->create();
|
|
Certificate::factory()->for($user)->create(['expires_at' => today()]);
|
|
|
|
$this->artisan('app:send-certificate-reminders')->assertSuccessful();
|
|
|
|
Notification::assertSentTo($user, CertificateExpiredNotification::class);
|
|
});
|
|
|
|
test('certificates outside the threshold are not notified', function () {
|
|
$user = User::factory()->create(['reminder_months_before' => 1]);
|
|
Certificate::factory()->for($user)->create(['expires_at' => today()->addMonths(6)]);
|
|
|
|
$this->artisan('app:send-certificate-reminders')->assertSuccessful();
|
|
|
|
Notification::assertNothingSent();
|
|
});
|
|
|
|
test('reminders are not sent twice on the same day', function () {
|
|
$user = User::factory()->create(['reminder_months_before' => 1]);
|
|
Certificate::factory()->for($user)->create(['expires_at' => today()->addMonth()]);
|
|
|
|
$this->artisan('app:send-certificate-reminders')->assertSuccessful();
|
|
$this->artisan('app:send-certificate-reminders')->assertSuccessful();
|
|
|
|
Notification::assertSentToTimes($user, CertificateExpiringNotification::class, 1);
|
|
});
|