reviewed epic 4
This commit is contained in:
@@ -16,6 +16,31 @@ So that **I stay informed about my case progress without checking the portal**.
|
||||
- **Follows pattern:** Event-driven notification pattern
|
||||
- **Touch points:** Timeline update creation
|
||||
|
||||
### Previous Story Context (Story 4.2)
|
||||
Story 4.2 established:
|
||||
- `TimelineUpdate` model with fields: `timeline_id`, `admin_id`, `update_text`
|
||||
- `TimelineUpdate` belongs to `Timeline` and `User` (admin)
|
||||
- `Timeline` has many `TimelineUpdate` records
|
||||
- Updates created via `addUpdate()` method in timeline management Volt component
|
||||
- Notification trigger point: after `$this->timeline->updates()->create([...])`
|
||||
|
||||
### Prerequisites
|
||||
The following must exist before implementing this story:
|
||||
- **User model requirements:**
|
||||
- `preferred_language` field (string, defaults to 'ar') - from Epic 2 user registration
|
||||
- `isActive()` method returning boolean (checks `status !== 'deactivated'`) - from Epic 2
|
||||
- **Route requirement:**
|
||||
- `client.timelines.show` route must exist (from Story 4.5)
|
||||
- **Models available:**
|
||||
- `Timeline` model with `user()` relationship
|
||||
- `TimelineUpdate` model with `timeline()` relationship
|
||||
|
||||
### Implementation Files
|
||||
- **Notification:** `app/Notifications/TimelineUpdateNotification.php`
|
||||
- **Arabic Template:** `resources/views/emails/timeline/update/ar.blade.php`
|
||||
- **English Template:** `resources/views/emails/timeline/update/en.blade.php`
|
||||
- **Modify:** Story 4.2 Volt component to trigger notification
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
### Notification Trigger
|
||||
@@ -168,18 +193,33 @@ if ($this->timeline->user->isActive()) {
|
||||
}
|
||||
```
|
||||
|
||||
### Testing
|
||||
### Test Scenarios
|
||||
- [ ] Notification sent when timeline update created
|
||||
- [ ] No notification to deactivated user (`status === 'deactivated'`)
|
||||
- [ ] Arabic template renders with correct content (case name, update text, date)
|
||||
- [ ] English template renders with correct content
|
||||
- [ ] Uses client's `preferred_language` for template selection (defaults to 'ar')
|
||||
- [ ] Email is queued (uses `ShouldQueue` interface)
|
||||
- [ ] Email contains valid link to timeline view
|
||||
- [ ] Subject line includes case name in correct language
|
||||
|
||||
### Testing Examples
|
||||
```php
|
||||
use App\Models\{User, Timeline, TimelineUpdate};
|
||||
use App\Notifications\TimelineUpdateNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
it('sends notification when timeline update created', function () {
|
||||
Notification::fake();
|
||||
|
||||
$timeline = Timeline::factory()->create();
|
||||
$user = User::factory()->create(['status' => 'active']);
|
||||
$timeline = Timeline::factory()->for($user)->create();
|
||||
$update = TimelineUpdate::factory()->create(['timeline_id' => $timeline->id]);
|
||||
|
||||
$timeline->user->notify(new TimelineUpdateNotification($update));
|
||||
// Simulate the trigger from Story 4.2
|
||||
if ($timeline->user->isActive()) {
|
||||
$timeline->user->notify(new TimelineUpdateNotification($update));
|
||||
}
|
||||
|
||||
Notification::assertSentTo($timeline->user, TimelineUpdateNotification::class);
|
||||
});
|
||||
@@ -189,12 +229,45 @@ it('does not send notification to deactivated user', function () {
|
||||
|
||||
$user = User::factory()->create(['status' => 'deactivated']);
|
||||
$timeline = Timeline::factory()->for($user)->create();
|
||||
$update = TimelineUpdate::factory()->create(['timeline_id' => $timeline->id]);
|
||||
|
||||
// Add update (should check user status)
|
||||
// ...
|
||||
// Simulate the trigger from Story 4.2 - should NOT notify
|
||||
if ($timeline->user->isActive()) {
|
||||
$timeline->user->notify(new TimelineUpdateNotification($update));
|
||||
}
|
||||
|
||||
Notification::assertNotSentTo($user, TimelineUpdateNotification::class);
|
||||
});
|
||||
|
||||
it('uses arabic template for arabic-preferred user', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create(['preferred_language' => 'ar']);
|
||||
$timeline = Timeline::factory()->for($user)->create(['case_name' => 'Test Case']);
|
||||
$update = TimelineUpdate::factory()->create(['timeline_id' => $timeline->id]);
|
||||
|
||||
$user->notify(new TimelineUpdateNotification($update));
|
||||
|
||||
Notification::assertSentTo($user, TimelineUpdateNotification::class, function ($notification, $channels, $notifiable) {
|
||||
$mail = $notification->toMail($notifiable);
|
||||
return str_contains($mail->subject, 'تحديث جديد على قضيتك');
|
||||
});
|
||||
});
|
||||
|
||||
it('uses english template for english-preferred user', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create(['preferred_language' => 'en']);
|
||||
$timeline = Timeline::factory()->for($user)->create(['case_name' => 'Test Case']);
|
||||
$update = TimelineUpdate::factory()->create(['timeline_id' => $timeline->id]);
|
||||
|
||||
$user->notify(new TimelineUpdateNotification($update));
|
||||
|
||||
Notification::assertSentTo($user, TimelineUpdateNotification::class, function ($notification, $channels, $notifiable) {
|
||||
$mail = $notification->toMail($notifiable);
|
||||
return str_contains($mail->subject, 'New update on your case');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Definition of Done
|
||||
@@ -211,8 +284,10 @@ it('does not send notification to deactivated user', function () {
|
||||
|
||||
## Dependencies
|
||||
|
||||
- **Story 4.2:** Timeline updates management
|
||||
- **Epic 8:** Email infrastructure
|
||||
- **Story 4.2:** Timeline updates management (REQUIRED - notification triggered from addUpdate method)
|
||||
- **Story 4.5:** Client timeline view (REQUIRED - provides `client.timelines.show` route used in email link)
|
||||
- **Epic 2:** User model with `preferred_language` field and `isActive()` method
|
||||
- **Epic 8:** Email infrastructure (SOFT DEPENDENCY - notification will queue but email delivery requires Epic 8)
|
||||
|
||||
## Estimation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user