TenantAtlas/apps/platform/tests/Feature/Filament/ManagedEnvironmentsLandingLifecycleTest.php
ahmido 292d555eac refactor: consolidate internal tenant model naming (#355)
## Summary
- consolidate internal platform naming from `Tenant` to `Environment` / `ManagedEnvironment` across models, controllers, services, and Filament resources
- rename environment-scoped UI surfaces such as dashboards, chooser flows, navigation, and related widgets to match the updated environment-first domain language
- align middleware, onboarding/review lifecycle services, jobs, and route/context controllers with the new environment-scoped architecture

## Validation
- not rerun as part of this commit/push/PR request

## Notes
- branch is 1 commit ahead of `platform-dev`
- main commit: `refactor: consolidate internal tenant model naming`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #355
2026-05-14 11:13:28 +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-environments.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-environments.index', ['workspace' => $workspace]))
->assertSuccessful()
->assertSee('Discoverable Draft ManagedEnvironment')
->assertSee('Discoverable Onboarding ManagedEnvironment')
->assertSee('Discoverable Archived ManagedEnvironment');
});
it('keeps administrative landing discoverability broader than choose-environment 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-environments.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-environment')
->assertSuccessful()
->assertSee('Landing Active ManagedEnvironment')
->assertDontSee('Landing Draft ManagedEnvironment')
->assertDontSee('Landing Onboarding ManagedEnvironment')
->assertDontSee('Landing Archived ManagedEnvironment');
});