Files
L-Ami-Fiduciaire/tests/Feature/Notification/FolderMentionTest.php
Saad Zoubir 7a18c40361 chore: add BMAD framework modules, folder features, and tooling configs
Includes BMAD bmb/bmm/cis/tea workflow modules, folder (declaration)
feature implementation (controllers, models, enums, views, tests),
claude/cursor command configs, and email templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 21:24:17 +01:00

98 lines
3.3 KiB
PHP

<?php
use App\Models\Client;
use App\Models\Folder;
use App\Models\User;
use App\Models\Workspace;
use App\Notifications\FolderMentionNotification;
use Illuminate\Support\Facades\Notification;
function setupFolderMentionScenario(string $role = 'owner'): array
{
$sender = User::factory()->create();
$target = User::factory()->create();
$workspace = Workspace::factory()->create();
$workspace->users()->attach($sender, ['role' => $role]);
$workspace->users()->attach($target, ['role' => 'member']);
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
$folder = Folder::factory()->create([
'workspace_id' => $workspace->id,
'client_id' => $client->id,
]);
return [$sender, $target, $workspace, $folder];
}
test('owner can mention a workspace user', function () {
Notification::fake();
[$sender, $target, $workspace, $folder] = setupFolderMentionScenario('owner');
session(['current_workspace_id' => $workspace->id]);
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
'user_id' => $target->id,
'message' => 'Please check this folder.',
]);
$response->assertRedirect();
Notification::assertSentTo($target, FolderMentionNotification::class);
});
test('manager can mention a workspace user', function () {
Notification::fake();
[$sender, $target, $workspace, $folder] = setupFolderMentionScenario('manager');
session(['current_workspace_id' => $workspace->id]);
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
'user_id' => $target->id,
'message' => 'Please check this folder.',
]);
$response->assertRedirect();
Notification::assertSentTo($target, FolderMentionNotification::class);
});
test('member cannot mention a workspace user', function () {
Notification::fake();
[$sender, $target, $workspace, $folder] = setupFolderMentionScenario('member');
session(['current_workspace_id' => $workspace->id]);
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
'user_id' => $target->id,
'message' => 'Please check this folder.',
]);
$response->assertForbidden();
Notification::assertNothingSent();
});
test('cannot mention user from another workspace', function () {
Notification::fake();
[$sender, , $workspace, $folder] = setupFolderMentionScenario('owner');
$outsider = User::factory()->create();
session(['current_workspace_id' => $workspace->id]);
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
'user_id' => $outsider->id,
'message' => 'Hello',
]);
$response->assertSessionHasErrors('user_id');
Notification::assertNothingSent();
});
test('notification is persisted in database', function () {
[$sender, $target, $workspace, $folder] = setupFolderMentionScenario('owner');
session(['current_workspace_id' => $workspace->id]);
$this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
'user_id' => $target->id,
'message' => 'Check this.',
]);
expect($target->notifications()->count())->toBe(1);
$notif = $target->notifications()->first();
expect($notif->data['folder_id'])->toBe($folder->id);
expect($notif->data['message'])->toBe('Check this.');
});