feat: add SendPaymentFailedReminderJob with grace guard

This commit is contained in:
Ovidiu U
2026-04-23 10:51:13 +01:00
parent c127cc379e
commit 5b17f4cae4
2 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<?php
use App\Jobs\SendPaymentFailedReminderJob;
use App\Mail\PaymentFailedDay3Reminder;
use App\Mail\PaymentFailedDay5Reminder;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
uses(RefreshDatabase::class);
it('sends the day-3 mailable when grace_period_until is still set', function (): void {
Mail::fake();
$user = User::factory()->create(['grace_period_until' => now()->addDays(2)]);
(new SendPaymentFailedReminderJob($user->id, 3))->handle();
Mail::assertSent(PaymentFailedDay3Reminder::class, fn ($mail) => $mail->hasTo($user->email));
});
it('sends the day-5 mailable when grace_period_until is still set', function (): void {
Mail::fake();
$user = User::factory()->create(['grace_period_until' => now()->addDay()]);
(new SendPaymentFailedReminderJob($user->id, 5))->handle();
Mail::assertSent(PaymentFailedDay5Reminder::class, fn ($mail) => $mail->hasTo($user->email));
});
it('silently skips the day-3 mailable when grace has been cleared', function (): void {
Mail::fake();
$user = User::factory()->create(['grace_period_until' => null]);
(new SendPaymentFailedReminderJob($user->id, 3))->handle();
Mail::assertNothingSent();
});
it('silently skips the day-5 mailable when grace has been cleared', function (): void {
Mail::fake();
$user = User::factory()->create(['grace_period_until' => null]);
(new SendPaymentFailedReminderJob($user->id, 5))->handle();
Mail::assertNothingSent();
});
it('silently skips when the user no longer exists', function (): void {
Mail::fake();
(new SendPaymentFailedReminderJob(999999, 3))->handle();
Mail::assertNothingSent();
});