TenantAtlas/apps/platform/tests/Feature/Filament/ManagedTenantsLandingLifecycleTest.php
ahmido e64bae9cfc feat: cut over tenant core to managed environments (#335)
## Summary
- replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership
- propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths
- add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`

## Notes
- branch pushed from commit `1123b122`
- browser smoke test file was added but not run in this pass

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #335
2026-05-07 06:38:14 +00:00

148 lines
6.0 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\ManagedEnvironment;
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('shows onboarding and archived tenants on the managed-tenants landing with lifecycle labels', function (): void {
$workspace = Workspace::factory()->create(['slug' => 'lifecycle-ws']);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$active = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Active ManagedEnvironment',
]);
$onboarding = ManagedEnvironment::factory()->onboarding()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Onboarding ManagedEnvironment',
]);
$archived = ManagedEnvironment::factory()->archived()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Archived ManagedEnvironment',
]);
$outsider = ManagedEnvironment::factory()->active()->create(['name' => 'Other Workspace ManagedEnvironment']);
$user->tenants()->syncWithoutDetaching([
$active->getKey() => ['role' => 'owner'],
$onboarding->getKey() => ['role' => 'owner'],
$archived->getKey() => ['role' => 'owner'],
$outsider->getKey() => ['role' => 'owner'],
]);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get(route('admin.workspace.managed-tenants.index', ['workspace' => $workspace]))
->assertSuccessful()
->assertSee('Active ManagedEnvironment')
->assertSee('Onboarding ManagedEnvironment')
->assertSee('Archived ManagedEnvironment')
->assertSee('Active')
->assertSee('Onboarding')
->assertSee('Archived')
->assertDontSee('Other Workspace ManagedEnvironment');
});
it('keeps managed tenants discoverable with no selected tenant context', function (): void {
$workspace = Workspace::factory()->create(['slug' => 'discoverable-managed-tenants']);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$onboardingTenant = ManagedEnvironment::factory()->onboarding()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Discoverable Onboarding ManagedEnvironment',
]);
$draftTenant = ManagedEnvironment::factory()->draft()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Discoverable Draft ManagedEnvironment',
]);
$archivedTenant = ManagedEnvironment::factory()->archived()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Discoverable Archived ManagedEnvironment',
]);
$user->tenants()->syncWithoutDetaching([
$draftTenant->getKey() => ['role' => 'owner'],
$onboardingTenant->getKey() => ['role' => 'owner'],
$archivedTenant->getKey() => ['role' => 'owner'],
]);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get(route('admin.workspace.managed-tenants.index', ['workspace' => $workspace]))
->assertSuccessful()
->assertSee('Discoverable Draft ManagedEnvironment')
->assertSee('Discoverable Onboarding ManagedEnvironment')
->assertSee('Discoverable Archived ManagedEnvironment');
});
it('keeps administrative landing discoverability broader than choose-tenant selection', function (): void {
$workspace = Workspace::factory()->create(['slug' => 'landing-vs-selector']);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$activeTenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Landing Active ManagedEnvironment',
]);
$draftTenant = ManagedEnvironment::factory()->draft()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Landing Draft ManagedEnvironment',
]);
$onboardingTenant = ManagedEnvironment::factory()->onboarding()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Landing Onboarding ManagedEnvironment',
]);
$archivedTenant = ManagedEnvironment::factory()->archived()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Landing Archived ManagedEnvironment',
]);
$user->tenants()->syncWithoutDetaching([
$activeTenant->getKey() => ['role' => 'owner'],
$draftTenant->getKey() => ['role' => 'owner'],
$onboardingTenant->getKey() => ['role' => 'owner'],
$archivedTenant->getKey() => ['role' => 'owner'],
]);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get(route('admin.workspace.managed-tenants.index', ['workspace' => $workspace]))
->assertSuccessful()
->assertSee('Landing Active ManagedEnvironment')
->assertSee('Landing Draft ManagedEnvironment')
->assertSee('Landing Onboarding ManagedEnvironment')
->assertSee('Landing Archived ManagedEnvironment');
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get('/admin/choose-tenant')
->assertSuccessful()
->assertSee('Landing Active ManagedEnvironment')
->assertDontSee('Landing Draft ManagedEnvironment')
->assertDontSee('Landing Onboarding ManagedEnvironment')
->assertDontSee('Landing Archived ManagedEnvironment');
});