feat: add notification infrastructure with database channel, enum, and notification classes (Story 3.1)

Set up Laravel notification system with NotificationType enum (5 types),
NudgeNotification, DocumentUploadedNotification, and DeclarationOverdueNotification
classes with database + mail channels. Add email templates, infrastructure tests,
and fix existing NotificationController tests for workspace compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 11:26:03 +01:00
parent 6956f7bf95
commit 1ab3cfc445
10 changed files with 731 additions and 9 deletions

View File

@@ -5,11 +5,13 @@ use App\Models\Declaration;
use App\Models\User;
use App\Models\Workspace;
use App\Notifications\DeclarationMentionNotification;
use App\Notifications\DocumentUploadedNotification;
test('user can mark own notification as read', function () {
$user = User::factory()->create();
$workspace = Workspace::factory()->create();
$workspace->users()->attach($user, ['role' => 'owner']);
$workspace->users()->attach($user, ['role' => 'owner', 'permissions' => json_encode([])]);
$user->update(['current_workspace_id' => $workspace->id]);
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
$declaration = Declaration::factory()->create([
'workspace_id' => $workspace->id,
@@ -37,7 +39,9 @@ test('cannot mark another user notification as read', function () {
$user = User::factory()->create();
$other = User::factory()->create();
$workspace = Workspace::factory()->create();
$workspace->users()->attach($other, ['role' => 'owner']);
$workspace->users()->attach($user, ['role' => 'owner', 'permissions' => json_encode([])]);
$workspace->users()->attach($other, ['role' => 'worker', 'permissions' => json_encode([])]);
$user->update(['current_workspace_id' => $workspace->id]);
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
$declaration = Declaration::factory()->create([
'workspace_id' => $workspace->id,
@@ -60,20 +64,16 @@ test('cannot mark another user notification as read', function () {
test('user can mark all notifications as read', function () {
$user = User::factory()->create();
$workspace = Workspace::factory()->create();
$workspace->users()->attach($user, ['role' => 'owner']);
$workspace->users()->attach($user, ['role' => 'owner', 'permissions' => json_encode([])]);
$user->update(['current_workspace_id' => $workspace->id]);
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
$mentionedBy = User::factory()->create();
for ($i = 0; $i < 3; $i++) {
$declaration = Declaration::factory()->create([
'workspace_id' => $workspace->id,
'client_id' => $client->id,
]);
$user->notify(new DeclarationMentionNotification(
$declaration,
$mentionedBy,
"Message $i",
));
$user->notify(new DocumentUploadedNotification($declaration, $client->id));
}
expect($user->unreadNotifications()->count())->toBe(3);
@@ -81,5 +81,6 @@ test('user can mark all notifications as read', function () {
$response = $this->actingAs($user)->post(route('notifications.readAll'));
$response->assertRedirect();
$user->refresh();
expect($user->unreadNotifications()->count())->toBe(0);
});