Files
L-Ami-Fiduciaire/tests/Feature/Notification/NotificationControllerTest.php
Saad Ibn-Ezzoubayr fd43a6f429 feat: complete Epic 0 — foundation migration & infrastructure setup
Stories 0.2-0.5: rename folders→declarations (backend+frontend), configure
Redis for cache/queue/sessions, add foundation database migrations
(permissions, archived_at), replace DeclarationStatus enum with architecture
lifecycle values, create DeclarationObserver for status transition validation
and auto-archive, fix controller status transitions to respect observer rules.

93 tests pass (240 assertions).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 18:25:32 +00:00

86 lines
2.8 KiB
PHP

<?php
use App\Models\Client;
use App\Models\Declaration;
use App\Models\User;
use App\Models\Workspace;
use App\Notifications\DeclarationMentionNotification;
test('user can mark own notification as read', function () {
$user = User::factory()->create();
$workspace = Workspace::factory()->create();
$workspace->users()->attach($user, ['role' => 'owner']);
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
$declaration = Declaration::factory()->create([
'workspace_id' => $workspace->id,
'client_id' => $client->id,
]);
$mentionedBy = User::factory()->create();
$user->notify(new DeclarationMentionNotification(
$declaration,
$mentionedBy,
'Please review.',
));
$notification = $user->notifications()->first();
expect($notification->read_at)->toBeNull();
$response = $this->actingAs($user)->post(route('notifications.read', $notification->id));
$response->assertRedirect();
$notification->refresh();
expect($notification->read_at)->not->toBeNull();
});
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']);
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
$declaration = Declaration::factory()->create([
'workspace_id' => $workspace->id,
'client_id' => $client->id,
]);
$mentionedBy = User::factory()->create();
$other->notify(new DeclarationMentionNotification(
$declaration,
$mentionedBy,
'Hey.',
));
$notification = $other->notifications()->first();
$response = $this->actingAs($user)->post(route('notifications.read', $notification->id));
$response->assertNotFound();
});
test('user can mark all notifications as read', function () {
$user = User::factory()->create();
$workspace = Workspace::factory()->create();
$workspace->users()->attach($user, ['role' => 'owner']);
$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",
));
}
expect($user->unreadNotifications()->count())->toBe(3);
$response = $this->actingAs($user)->post(route('notifications.readAll'));
$response->assertRedirect();
expect($user->unreadNotifications()->count())->toBe(0);
});