complete story 8.7 with qa tests

This commit is contained in:
Naser Mansour
2026-01-02 22:47:03 +02:00
parent 91be71fa44
commit b7b8a4fa86
9 changed files with 457 additions and 31 deletions
+197
View File
@@ -198,3 +198,200 @@ it('does not send 2h reminder for rejected consultation', function () {
Notification::assertNotSentTo($consultation->user, ConsultationReminder2h::class);
});
// 2-Hour Reminder Additional Tests (Story 8.7)
it('2h command uses 7-minute window for matching', function () {
Notification::fake();
// Create consultation at exactly 2h + 8 minutes (outside window)
$outsideWindow = Consultation::factory()->approved()->create([
'booking_date' => now()->addHours(2)->addMinutes(8)->toDateString(),
'booking_time' => now()->addHours(2)->addMinutes(8)->format('H:i:s'),
'reminder_2h_sent_at' => null,
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertNotSentTo($outsideWindow->user, ConsultationReminder2h::class);
});
it('2h command sends reminder within 7-minute window', function () {
Notification::fake();
// Create consultation at exactly 2h + 6 minutes (inside window)
$insideWindow = Consultation::factory()->approved()->create([
'booking_date' => now()->addHours(2)->addMinutes(6)->toDateString(),
'booking_time' => now()->addHours(2)->addMinutes(6)->format('H:i:s'),
'reminder_2h_sent_at' => null,
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertSentTo($insideWindow->user, ConsultationReminder2h::class);
});
it('2h command only checks consultations scheduled for today', function () {
Notification::fake();
// Create consultation 2 hours from now but for tomorrow's date
$tomorrowConsultation = Consultation::factory()->approved()->create([
'booking_date' => now()->addDay()->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
'reminder_2h_sent_at' => null,
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertNotSentTo($tomorrowConsultation->user, ConsultationReminder2h::class);
});
it('does not send 2h reminder for pending consultation', function () {
Notification::fake();
$consultation = Consultation::factory()->pending()->create([
'booking_date' => now()->addHours(2)->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertNotSentTo($consultation->user, ConsultationReminder2h::class);
});
it('does not send 2h reminder for completed consultation', function () {
Notification::fake();
$consultation = Consultation::factory()->completed()->create([
'booking_date' => now()->addHours(2)->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertNotSentTo($consultation->user, ConsultationReminder2h::class);
});
it('does not send 2h reminder for no-show consultation', function () {
Notification::fake();
$consultation = Consultation::factory()->noShow()->create([
'booking_date' => now()->addHours(2)->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertNotSentTo($consultation->user, ConsultationReminder2h::class);
});
it('respects user language preference for 2h reminders', function () {
Notification::fake();
$user = User::factory()->create(['preferred_language' => 'en']);
$consultation = Consultation::factory()->approved()->create([
'user_id' => $user->id,
'booking_date' => now()->addHours(2)->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertSentTo($user, ConsultationReminder2h::class);
});
it('shows payment reminder for unpaid paid consultation in 2h reminder', function () {
Notification::fake();
$consultation = Consultation::factory()->approved()->paid()->create([
'booking_date' => now()->addHours(2)->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
'payment_status' => 'pending',
'payment_amount' => 200.00,
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertSentTo(
$consultation->user,
ConsultationReminder2h::class,
function ($notification) {
return $notification->consultation->consultation_type->value === 'paid'
&& $notification->consultation->payment_status->value === 'pending';
}
);
});
it('hides payment reminder when payment received in 2h reminder', function () {
Notification::fake();
$consultation = Consultation::factory()->approved()->paid()->create([
'booking_date' => now()->addHours(2)->toDateString(),
'booking_time' => now()->addHours(2)->format('H:i:s'),
'payment_status' => 'received',
'payment_amount' => 200.00,
]);
$this->artisan('reminders:send-2h')
->assertSuccessful();
Notification::assertSentTo(
$consultation->user,
ConsultationReminder2h::class,
function ($notification) {
return $notification->consultation->payment_status->value === 'received';
}
);
});
// 2-Hour Reminder Email Content Tests (Story 8.7)
it('2h reminder notification has correct subject in Arabic', function () {
$user = User::factory()->create(['preferred_language' => 'ar']);
$consultation = Consultation::factory()->approved()->create([
'user_id' => $user->id,
]);
$notification = new ConsultationReminder2h($consultation);
$mail = $notification->toMail($user);
expect($mail->subject)->toBe('استشارتك بعد ساعتين');
});
it('2h reminder notification has correct subject in English', function () {
$user = User::factory()->create(['preferred_language' => 'en']);
$consultation = Consultation::factory()->approved()->create([
'user_id' => $user->id,
]);
$notification = new ConsultationReminder2h($consultation);
$mail = $notification->toMail($user);
expect($mail->subject)->toBe('Your consultation is in 2 hours');
});
it('2h reminder email does not include calendar download link', function () {
$user = User::factory()->create(['preferred_language' => 'en']);
$consultation = Consultation::factory()->approved()->create([
'user_id' => $user->id,
]);
$notification = new ConsultationReminder2h($consultation);
$mail = $notification->toMail($user);
// The view should be emails.reminder-2h which doesn't have calendar link
expect($mail->view)->toBe('emails.reminder-2h');
});
it('2h reminder notification is queued', function () {
expect(ConsultationReminder2h::class)
->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class);
});