Add notifications: header bell, task start run and assignment notices
A new Notifications module shows a bell beside the profile menu with the number of unseen notifications and a panel of the last 7 days; opening it marks them seen, and each notification links to its job or task. - A daily run at 14.00 (notifications:task-starts) tells the assignee and members of tasks that start by the next working day, skipping holidays and days off, done tasks and archived jobs. - Jobs publishes PeopleAddedToTask and PeopleAddedToJob when someone else makes a user a task's assignee or member or gives them a role on a job; those users are notified at once. UpdateTask and ScheduleTask now take the acting user. - A notification link to #task-<id> opens that task card on the job page. Also: simplifying job fields per service unit (K31) moves to the end of phase 4, and the workflow template browser test waits for Livewire's progress bar before its last accessibility check. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Jobs\Domain\Events\PeopleAddedToJob;
|
||||
use App\Modules\Jobs\Domain\Events\PeopleAddedToTask;
|
||||
use App\Modules\Notifications\Application\UseCases\NotifyAddedPeople;
|
||||
use App\Modules\Notifications\Domain\Enums\NotificationType;
|
||||
use Tests\Fakes\FakeClock;
|
||||
use Tests\Fakes\InMemoryNotificationRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->notifications = new InMemoryNotificationRepository;
|
||||
$this->notify = new NotifyAddedPeople($this->notifications, new FakeClock(new DateTimeImmutable('2026-11-25')));
|
||||
});
|
||||
|
||||
it('tells the new assignee and members of a task, but not the one who added them', function () {
|
||||
$this->notify->forTask(new PeopleAddedToTask(7, 'Kuvauspäivä', 3, '2026-0042', 'Messuvideo', 10, [11, 12], 12));
|
||||
|
||||
$notifications = array_values($this->notifications->notifications);
|
||||
|
||||
expect($notifications)->toHaveCount(2)
|
||||
->and($notifications[0]->userId)->toBe(10)
|
||||
->and($notifications[0]->type)->toBe(NotificationType::TaskAssigned)
|
||||
->and($notifications[0]->params)->toBe(['task_id' => 7, 'task_title' => 'Kuvauspäivä', 'job_id' => 3, 'job_number' => '2026-0042', 'job_name' => 'Messuvideo', 'role' => 'assignee'])
|
||||
->and($notifications[1]->userId)->toBe(11)
|
||||
->and($notifications[1]->params['role'])->toBe('member');
|
||||
});
|
||||
|
||||
it('tells each person about their new roles on a job, but not the one who gave them', function () {
|
||||
$this->notify->forJob(new PeopleAddedToJob(3, '2026-0042', 'Messuvideo', [10 => ['responsible'], 11 => ['contact', 'member']], 10));
|
||||
|
||||
$notifications = array_values($this->notifications->notifications);
|
||||
|
||||
expect($notifications)->toHaveCount(1)
|
||||
->and($notifications[0]->userId)->toBe(11)
|
||||
->and($notifications[0]->type)->toBe(NotificationType::JobAssigned)
|
||||
->and($notifications[0]->params['roles'])->toBe('contact,member');
|
||||
});
|
||||
|
||||
it('tells again when the same person is added again later', function () {
|
||||
$event = new PeopleAddedToTask(7, 'Kuvauspäivä', 3, '2026-0042', 'Messuvideo', 10, [], 12);
|
||||
|
||||
$this->notify->forTask($event);
|
||||
$this->notify->forTask($event);
|
||||
|
||||
expect($this->notifications->notifications)->toHaveCount(2);
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\UpcomingTask;
|
||||
use App\Modules\Notifications\Application\Services\WorkingDays;
|
||||
use App\Modules\Notifications\Application\UseCases\NotifyTasksStartingSoon;
|
||||
use App\Modules\Notifications\Domain\ValueObjects\NewNotification;
|
||||
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
|
||||
use Tests\Fakes\FakeClock;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\FakeUpcomingTasks;
|
||||
use Tests\Fakes\InMemoryHolidayOverrides;
|
||||
use Tests\Fakes\InMemoryNotificationRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->tasks = new FakeUpcomingTasks;
|
||||
$this->notifications = new InMemoryNotificationRepository;
|
||||
$this->clock = new FakeClock(new DateTimeImmutable('2026-11-26'));
|
||||
$this->notify = new NotifyTasksStartingSoon(
|
||||
$this->tasks,
|
||||
$this->notifications,
|
||||
new WorkingDays(new HolidayCalendar(new InMemoryHolidayOverrides)),
|
||||
new FakeTransactionManager,
|
||||
$this->clock,
|
||||
);
|
||||
});
|
||||
|
||||
function upcomingTask(int $id, string $startsOn, array $recipients = [10]): UpcomingTask
|
||||
{
|
||||
return new UpcomingTask($id, 'Tehtävä '.$id, 5, '2026-0042', 'Messuvideo', $startsOn, $recipients);
|
||||
}
|
||||
|
||||
it('notifies on Thursday about tasks starting on Friday, not later ones or today\'s', function () {
|
||||
$this->tasks->tasks = [upcomingTask(1, '2026-11-26'), upcomingTask(2, '2026-11-27'), upcomingTask(3, '2026-11-30')];
|
||||
|
||||
expect($this->notify->execute())->toBe(1)
|
||||
->and($this->notifications->recipients())->toBe(['10:2']);
|
||||
});
|
||||
|
||||
it('notifies on Friday about tasks starting on Saturday to Monday', function () {
|
||||
$this->clock->today = new DateTimeImmutable('2026-11-27');
|
||||
$this->tasks->tasks = [upcomingTask(1, '2026-11-28'), upcomingTask(2, '2026-11-30'), upcomingTask(3, '2026-12-01')];
|
||||
|
||||
$this->notify->execute();
|
||||
|
||||
expect($this->notifications->recipients())->toBe(['10:1', '10:2']);
|
||||
});
|
||||
|
||||
it('skips holidays: before Christmas it notifies up to the next working day after them', function () {
|
||||
$this->clock->today = new DateTimeImmutable('2026-12-23');
|
||||
$this->tasks->tasks = [upcomingTask(1, '2026-12-28'), upcomingTask(2, '2026-12-29')];
|
||||
|
||||
$this->notify->execute();
|
||||
|
||||
expect($this->notifications->recipients())->toBe(['10:1']);
|
||||
});
|
||||
|
||||
it('notifies nobody on a day off', function () {
|
||||
$this->clock->today = new DateTimeImmutable('2026-11-29');
|
||||
$this->tasks->tasks = [upcomingTask(1, '2026-11-30')];
|
||||
|
||||
expect($this->notify->execute())->toBe(0)
|
||||
->and($this->notifications->notifications)->toBe([]);
|
||||
});
|
||||
|
||||
it('notifies each recipient once, also when run again', function () {
|
||||
$this->tasks->tasks = [upcomingTask(1, '2026-11-27', [10, 12])];
|
||||
|
||||
expect($this->notify->execute())->toBe(2)
|
||||
->and($this->notify->execute())->toBe(0)
|
||||
->and($this->notifications->recipients())->toBe(['10:1', '12:1']);
|
||||
|
||||
$notification = array_values($this->notifications->notifications)[0];
|
||||
expect($notification->params)->toBe([
|
||||
'task_id' => 1,
|
||||
'task_title' => 'Tehtävä 1',
|
||||
'job_id' => 5,
|
||||
'job_number' => '2026-0042',
|
||||
'job_name' => 'Messuvideo',
|
||||
'starts_on' => '2026-11-27',
|
||||
]);
|
||||
});
|
||||
|
||||
it('removes notifications older than a week', function () {
|
||||
$this->notifications->addIfNew(NewNotification::taskStartsSoon(10, 1, '2026-11-18', ['task_id' => 1], new DateTimeImmutable('2026-11-17 14:00')));
|
||||
$this->notifications->addIfNew(NewNotification::taskStartsSoon(10, 2, '2026-11-20', ['task_id' => 2], new DateTimeImmutable('2026-11-19 14:00')));
|
||||
|
||||
$this->notify->execute();
|
||||
|
||||
expect($this->notifications->recipients())->toBe(['10:2']);
|
||||
});
|
||||
Reference in New Issue
Block a user