Files
L-Ami-Fiduciaire/tests/Feature/Notification/NotificationControllerTest.php

66 lines
1.9 KiB
PHP
Raw Normal View History

<?php
use App\Models\User;
use App\Notifications\FolderMentionNotification;
test('user can mark own notification as read', function () {
$user = User::factory()->create();
$user->notify(new FolderMentionNotification(
folderId: 1,
folderTitle: 'Test Folder',
mentionedById: 999,
mentionedByName: 'Admin',
message: 'Please review.',
url: '/folders/1',
));
$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();
$other->notify(new FolderMentionNotification(
folderId: 1,
folderTitle: 'Test',
mentionedById: 999,
mentionedByName: 'Admin',
message: 'Hey.',
url: '/folders/1',
));
$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();
for ($i = 0; $i < 3; $i++) {
$user->notify(new FolderMentionNotification(
folderId: $i,
folderTitle: "Folder $i",
mentionedById: 999,
mentionedByName: 'Admin',
message: "Message $i",
url: "/folders/$i",
));
}
expect($user->unreadNotifications()->count())->toBe(3);
$response = $this->actingAs($user)->post(route('notifications.readAll'));
$response->assertRedirect();
expect($user->unreadNotifications()->count())->toBe(0);
});