create(); $workspaceA = Workspace::factory()->create(); $workspaceB = Workspace::factory()->create(); WorkspaceMembership::factory()->for($workspaceA)->for($user)->create(['role' => 'owner']); WorkspaceMembership::factory()->for($workspaceB)->for($user)->create(['role' => 'owner']); $tenantA = Tenant::factory()->create([ 'workspace_id' => $workspaceA->getKey(), 'name' => 'Tenant Alpha', 'is_current' => true, ]); $tenantB = Tenant::factory()->create([ 'workspace_id' => $workspaceB->getKey(), 'name' => 'Tenant Beta', 'is_current' => false, ]); $this->actingAs($user); session([WorkspaceContext::SESSION_KEY => $workspaceA->getKey()]); $tenantIds = TenantResource::getEloquentQuery()->pluck('id')->all(); expect($tenantIds) ->toContain($tenantA->getKey()) ->not()->toContain($tenantB->getKey()); }); it('returns no managed tenants when no workspace is selected', function (): void { $user = User::factory()->create(); $workspace = Workspace::factory()->create(); $otherWorkspace = Workspace::factory()->create(); WorkspaceMembership::factory()->for($workspace)->for($user)->create(['role' => 'owner']); WorkspaceMembership::factory()->for($otherWorkspace)->for($user)->create(['role' => 'owner']); Tenant::factory()->create(['workspace_id' => $workspace->getKey()]); $this->actingAs($user); $tenantIds = TenantResource::getEloquentQuery()->pluck('id')->all(); expect($tenantIds)->toBeEmpty(); });