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:
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Folder;
|
||||
use App\Models\Declaration;
|
||||
use App\Models\User;
|
||||
use App\Models\Workspace;
|
||||
use App\Notifications\FolderMentionNotification;
|
||||
use App\Notifications\DeclarationMentionNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
function setupMentionScenario(string $role = 'owner'): array
|
||||
@@ -16,50 +16,50 @@ function setupMentionScenario(string $role = 'owner'): array
|
||||
$workspace->users()->attach($target, ['role' => 'member']);
|
||||
|
||||
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
|
||||
$folder = Folder::factory()->create([
|
||||
$declaration = Declaration::factory()->create([
|
||||
'workspace_id' => $workspace->id,
|
||||
'client_id' => $client->id,
|
||||
]);
|
||||
|
||||
return [$sender, $target, $workspace, $folder];
|
||||
return [$sender, $target, $workspace, $declaration];
|
||||
}
|
||||
|
||||
test('owner can mention a workspace user', function () {
|
||||
Notification::fake();
|
||||
[$sender, $target, $workspace, $folder] = setupMentionScenario('owner');
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('owner');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Please check this folder.',
|
||||
'message' => 'Please check this declaration.',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
Notification::assertSentTo($target, FolderMentionNotification::class);
|
||||
Notification::assertSentTo($target, DeclarationMentionNotification::class);
|
||||
});
|
||||
|
||||
test('manager can mention a workspace user', function () {
|
||||
Notification::fake();
|
||||
[$sender, $target, $workspace, $folder] = setupMentionScenario('manager');
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('manager');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Please check this folder.',
|
||||
'message' => 'Please check this declaration.',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
Notification::assertSentTo($target, FolderMentionNotification::class);
|
||||
Notification::assertSentTo($target, DeclarationMentionNotification::class);
|
||||
});
|
||||
|
||||
test('member cannot mention a workspace user', function () {
|
||||
Notification::fake();
|
||||
[$sender, $target, $workspace, $folder] = setupMentionScenario('member');
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('member');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $target->id,
|
||||
'message' => 'Please check this folder.',
|
||||
'message' => 'Please check this declaration.',
|
||||
]);
|
||||
|
||||
$response->assertForbidden();
|
||||
@@ -68,11 +68,11 @@ test('member cannot mention a workspace user', function () {
|
||||
|
||||
test('cannot mention user from another workspace', function () {
|
||||
Notification::fake();
|
||||
[$sender, , $workspace, $folder] = setupMentionScenario('owner');
|
||||
[$sender, , $workspace, $declaration] = setupMentionScenario('owner');
|
||||
$outsider = User::factory()->create();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
|
||||
$response = $this->actingAs($sender)->post(route('declarations.mentions.store', $declaration), [
|
||||
'user_id' => $outsider->id,
|
||||
'message' => 'Hello',
|
||||
]);
|
||||
@@ -82,16 +82,16 @@ test('cannot mention user from another workspace', function () {
|
||||
});
|
||||
|
||||
test('notification is persisted in database', function () {
|
||||
[$sender, $target, $workspace, $folder] = setupMentionScenario('owner');
|
||||
[$sender, $target, $workspace, $declaration] = setupMentionScenario('owner');
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$this->actingAs($sender)->post(route('folders.mentions.store', $folder), [
|
||||
$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['folder_id'])->toBe($folder->id);
|
||||
expect($notif->data['declaration_id'])->toBe($declaration->id);
|
||||
expect($notif->data['message'])->toBe('Check this.');
|
||||
});
|
||||
@@ -1,17 +1,26 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Declaration;
|
||||
use App\Models\User;
|
||||
use App\Notifications\FolderMentionNotification;
|
||||
use App\Models\Workspace;
|
||||
use App\Notifications\DeclarationMentionNotification;
|
||||
|
||||
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',
|
||||
$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();
|
||||
@@ -27,13 +36,19 @@ test('user can mark own notification as read', function () {
|
||||
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',
|
||||
$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();
|
||||
@@ -44,15 +59,20 @@ 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']);
|
||||
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
|
||||
$mentionedBy = 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",
|
||||
$declaration = Declaration::factory()->create([
|
||||
'workspace_id' => $workspace->id,
|
||||
'client_id' => $client->id,
|
||||
]);
|
||||
$user->notify(new DeclarationMentionNotification(
|
||||
$declaration,
|
||||
$mentionedBy,
|
||||
"Message $i",
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user