Certified/tests/Feature/Certificates/CertificateReminderTest.php
Joël van de Wouw ac340d125c
Some checks failed
linter / quality (push) Failing after 13s
tests / ci (8.3) (push) Failing after 2s
tests / ci (8.4) (push) Failing after 2s
tests / ci (8.5) (push) Failing after 3s
Initial commit
Certificate manager built on Laravel 13, Livewire 4, and Flux.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 14:44:58 +02:00

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);
});