complete story 4.7 with qa tests

This commit is contained in:
Naser Mansour
2025-12-27 01:15:49 +02:00
parent 68a5551006
commit 4a0c98b134
7 changed files with 418 additions and 22 deletions
@@ -376,7 +376,159 @@ test('notification contains correct update data', function () {
$this->client,
TimelineUpdateNotification::class,
function ($notification) {
return str_contains($notification->timelineUpdate->update_text, 'This is the notification test update.');
return str_contains($notification->update->update_text, 'This is the notification test update.');
}
);
});
test('deactivated user does not receive notification when update is added', function () {
Notification::fake();
$deactivatedClient = User::factory()->individual()->deactivated()->create();
$timeline = Timeline::factory()->create(['user_id' => $deactivatedClient->id]);
$this->actingAs($this->admin);
Volt::test('admin.timelines.show', ['timeline' => $timeline])
->set('updateText', 'This is a valid update text.')
->call('addUpdate')
->assertHasNoErrors();
Notification::assertNotSentTo($deactivatedClient, TimelineUpdateNotification::class);
});
test('notification uses arabic subject for arabic-preferred user', function () {
Notification::fake();
$arabicClient = User::factory()->individual()->create(['preferred_language' => 'ar']);
$timeline = Timeline::factory()->create([
'user_id' => $arabicClient->id,
'case_name' => 'Test Case Name',
]);
$this->actingAs($this->admin);
Volt::test('admin.timelines.show', ['timeline' => $timeline])
->set('updateText', 'This is a valid update text.')
->call('addUpdate')
->assertHasNoErrors();
Notification::assertSentTo(
$arabicClient,
TimelineUpdateNotification::class,
function ($notification, $channels, $notifiable) {
$mail = $notification->toMail($notifiable);
return str_contains($mail->subject, 'تحديث جديد على قضيتك')
&& str_contains($mail->subject, 'Test Case Name');
}
);
});
test('notification uses english subject for english-preferred user', function () {
Notification::fake();
$englishClient = User::factory()->individual()->create(['preferred_language' => 'en']);
$timeline = Timeline::factory()->create([
'user_id' => $englishClient->id,
'case_name' => 'Test Case Name',
]);
$this->actingAs($this->admin);
Volt::test('admin.timelines.show', ['timeline' => $timeline])
->set('updateText', 'This is a valid update text.')
->call('addUpdate')
->assertHasNoErrors();
Notification::assertSentTo(
$englishClient,
TimelineUpdateNotification::class,
function ($notification, $channels, $notifiable) {
$mail = $notification->toMail($notifiable);
return str_contains($mail->subject, 'New update on your case')
&& str_contains($mail->subject, 'Test Case Name');
}
);
});
test('notification defaults to arabic when preferred language is ar', function () {
Notification::fake();
$arabicClient = User::factory()->individual()->create(['preferred_language' => 'ar']);
$timeline = Timeline::factory()->create([
'user_id' => $arabicClient->id,
'case_name' => 'Default Arabic Case',
]);
$this->actingAs($this->admin);
Volt::test('admin.timelines.show', ['timeline' => $timeline])
->set('updateText', 'This is a valid update text.')
->call('addUpdate')
->assertHasNoErrors();
Notification::assertSentTo(
$arabicClient,
TimelineUpdateNotification::class,
function ($notification, $channels, $notifiable) {
$mail = $notification->toMail($notifiable);
return str_contains($mail->subject, 'تحديث جديد على قضيتك');
}
);
});
test('notification is queued for performance', function () {
expect(TimelineUpdateNotification::class)
->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class);
});
test('notification uses correct markdown template for arabic user', function () {
Notification::fake();
$arabicClient = User::factory()->individual()->create(['preferred_language' => 'ar']);
$timeline = Timeline::factory()->create(['user_id' => $arabicClient->id]);
$this->actingAs($this->admin);
Volt::test('admin.timelines.show', ['timeline' => $timeline])
->set('updateText', 'This is a valid update text.')
->call('addUpdate')
->assertHasNoErrors();
Notification::assertSentTo(
$arabicClient,
TimelineUpdateNotification::class,
function ($notification, $channels, $notifiable) {
$mail = $notification->toMail($notifiable);
return $mail->markdown === 'emails.timeline.update.ar';
}
);
});
test('notification uses correct markdown template for english user', function () {
Notification::fake();
$englishClient = User::factory()->individual()->create(['preferred_language' => 'en']);
$timeline = Timeline::factory()->create(['user_id' => $englishClient->id]);
$this->actingAs($this->admin);
Volt::test('admin.timelines.show', ['timeline' => $timeline])
->set('updateText', 'This is a valid update text.')
->call('addUpdate')
->assertHasNoErrors();
Notification::assertSentTo(
$englishClient,
TimelineUpdateNotification::class,
function ($notification, $channels, $notifiable) {
$mail = $notification->toMail($notifiable);
return $mail->markdown === 'emails.timeline.update.en';
}
);
});