create(['slug' => 'spec195-managed-tenants']); $user = User::factory()->create(); WorkspaceMembership::factory()->create([ 'workspace_id' => (int) $workspace->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'owner', ]); $tenant = ManagedEnvironment::factory()->active()->create([ 'workspace_id' => (int) $workspace->getKey(), 'name' => 'Spec195 Landing ManagedEnvironment', ]); $user->tenants()->syncWithoutDetaching([ $tenant->getKey() => ['role' => 'owner'], ]); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->get(route('admin.workspace.managed-tenants.index', ['workspace' => $workspace])) ->assertSuccessful() ->assertSee('Spec195 Landing ManagedEnvironment') ->assertSee(__('localization.shell.managed_environments_title')) ->assertDontSee(__('localization.shell.no_environment_selected')); }); it('routes the managed-tenants landing back into the chooser flow and open-tenant flow', function (): void { $workspace = Workspace::factory()->create(['slug' => 'spec195-managed-routing']); $user = User::factory()->create(); WorkspaceMembership::factory()->create([ 'workspace_id' => (int) $workspace->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'owner', ]); $tenant = ManagedEnvironment::factory()->active()->create([ 'workspace_id' => (int) $workspace->getKey(), 'name' => 'Spec195 Routed ManagedEnvironment', ]); $user->tenants()->syncWithoutDetaching([ $tenant->getKey() => ['role' => 'owner'], ]); $this->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]); session([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]); $component = Livewire::actingAs($user) ->test(ManagedTenantsLanding::class, ['workspace' => $workspace]); $component ->call('goToChooseTenant') ->assertRedirect(route('admin.workspace.managed-tenants.index', ['workspace' => $workspace])); $this->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]); session([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]); Livewire::actingAs($user) ->test(ManagedTenantsLanding::class, ['workspace' => $workspace]) ->call('openTenant', $tenant->getKey()) ->assertRedirect(TenantDashboard::getUrl(tenant: $tenant)); }); it('allows workspace-scoped access to open an environment from the landing without explicit membership', function (): void { $workspace = Workspace::factory()->create(['slug' => 'spec195-managed-guard']); $user = User::factory()->create(); WorkspaceMembership::factory()->create([ 'workspace_id' => (int) $workspace->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'owner', ]); $tenant = ManagedEnvironment::factory()->active()->create([ 'workspace_id' => (int) $workspace->getKey(), 'name' => 'Spec195 Guarded ManagedEnvironment', ]); $this->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]); session([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]); Livewire::actingAs($user) ->test(ManagedTenantsLanding::class, ['workspace' => $workspace]) ->call('openTenant', $tenant->getKey()) ->assertRedirect(TenantDashboard::getUrl(tenant: $tenant)); });