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