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>
This commit is contained in:
97
tests/Feature/Notification/DeclarationMentionTest.php
Normal file
97
tests/Feature/Notification/DeclarationMentionTest.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Declaration;
|
||||
use App\Models\User;
|
||||
use App\Models\Workspace;
|
||||
use App\Notifications\DeclarationMentionNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
function setupMentionScenario(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]);
|
||||
$declaration = Declaration::factory()->create([
|
||||
'workspace_id' => $workspace->id,
|
||||
'client_id' => $client->id,
|
||||
]);
|
||||
|
||||
return [$sender, $target, $workspace, $declaration];
|
||||
}
|
||||
|
||||
test('owner can mention a workspace user', function () {
|
||||
Notification::fake();
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('owner');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Please check this declaration.',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
Notification::assertSentTo($target, DeclarationMentionNotification::class);
|
||||
});
|
||||
|
||||
test('manager can mention a workspace user', function () {
|
||||
Notification::fake();
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('manager');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Please check this declaration.',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
Notification::assertSentTo($target, DeclarationMentionNotification::class);
|
||||
});
|
||||
|
||||
test('member cannot mention a workspace user', function () {
|
||||
Notification::fake();
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('member');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Please check this declaration.',
|
||||
]);
|
||||
|
||||
$response->assertForbidden();
|
||||
Notification::assertNothingSent();
|
||||
});
|
||||
|
||||
test('cannot mention user from another workspace', function () {
|
||||
Notification::fake();
|
||||
[$sender, , $workspace, $declaration] = setupMentionScenario('owner');
|
||||
$outsider = User::factory()->create();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $outsider->id,
|
||||
'message' => 'Hello',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('user_id');
|
||||
Notification::assertNothingSent();
|
||||
});
|
||||
|
||||
test('notification is persisted in database', function () {
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('owner');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Check this.',
|
||||
]);
|
||||
|
||||
expect($target->notifications()->count())->toBe(1);
|
||||
$notif = $target->notifications()->first();
|
||||
expect($notif->data['declaration_id'])->toBe($declaration->id);
|
||||
expect($notif->data['message'])->toBe('Check this.');
|
||||
});
|
||||
Reference in New Issue
Block a user