TenantAtlas/apps/platform/tests/Feature/Filament/Pages/WorkspaceContextClosureRecoveryTest.php
ahmido 210508db9d feat: implement workspace and tenant closure lifecycle (#337)
## Summary
- add explicit workspace closure and tenant removal lifecycle truth with a bounded `WorkspaceLifecycleService`
- surface closure and removal posture across admin/system pages, chooser recovery, and canonical historical viewers
- block new review-pack and operation starts for closed workspaces or removed tenants while preserving memberships, audit, and history
- add focused Pest coverage plus the Spec 292 artifacts for the implemented slice

## Testing
- `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/System/Directory/ViewWorkspaceClosureTest.php tests/Feature/System/Ops/ClosedWorkspaceHistoricalAccessTest.php tests/Feature/Filament/Resources/Workspaces/WorkspaceClosureStatusTest.php tests/Feature/Filament/Resources/TenantResource/TenantWorkspaceRemovalTest.php tests/Feature/Filament/Pages/WorkspaceContextClosureRecoveryTest.php`
- `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- manual integrated-browser smoke for admin tenant remove/restore plus chooser recovery and system workspace close/reopen

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #337
2026-05-07 13:12:17 +00:00

71 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use App\Support\Workspaces\WorkspaceContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('excludes closed workspaces from the workspace chooser', function (): void {
$user = User::factory()->create();
$openWorkspace = Workspace::factory()->create(['name' => 'Open Workspace']);
$closedWorkspace = Workspace::factory()->create([
'name' => 'Closed Workspace',
'closed_at' => now(),
'closed_reason' => 'No longer active.',
]);
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $openWorkspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $closedWorkspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$this->actingAs($user)
->get(route('filament.admin.pages.choose-workspace'))
->assertSuccessful()
->assertSee('Open Workspace')
->assertDontSee('Closed Workspace');
});
it('clears closed remembered workspace context and routes to explicit recovery', function (): void {
$user = User::factory()->create();
$openWorkspace = Workspace::factory()->create();
$closedWorkspace = Workspace::factory()->create([
'closed_at' => now(),
'closed_reason' => 'The workspace was closed by support.',
]);
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $openWorkspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $closedWorkspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$user->forceFill(['last_workspace_id' => (int) $closedWorkspace->getKey()])->save();
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $closedWorkspace->getKey()])
->get('/admin/_test/workspace-context')
->assertRedirect('/admin/choose-workspace')
->assertSessionMissing(WorkspaceContext::SESSION_KEY);
expect($user->fresh()->last_workspace_id)->toBeNull();
});