TenantAtlas/apps/platform/tests/Feature/Guards/ManagedEnvironmentCanonicalRouteContractTest.php
ahmido 3ec582a182 feat: retire legacy tenant route surfaces (#352)
## Summary
- retire legacy `/admin/t` and active `/admin/tenants` product surfaces in favor of canonical workspace-scoped managed-environment routes
- centralize runtime URL generation through `ManagedEnvironmentLinks` and update intended URL handling to reject legacy tenant paths
- remove dormant tenant panel runtime, rename test helpers to the admin environment context, and add guard coverage for route/helper regressions

## Validation
- targeted Feature guard, workspace, provider connection, required permissions, and Filament test lanes run under Sail
- browser smoke coverage run for provider connection and workspace RBAC environment access flows
- formatting and diff checks completed with Pint and `git diff --check`

## Notes
- Filament remains on v5 with Livewire v4
- provider registration stays in `apps/platform/bootstrap/providers.php`
- retired tenant resource global search is disabled and destructive action confirmation rules remain unchanged

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #352
2026-05-12 23:35:03 +00:00

64 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\TenantResource;
use App\Models\OperationRun;
use App\Support\ManagedEnvironmentLinks;
use App\Support\OperationRunLinks;
use App\Support\Workspaces\WorkspaceContext;
it('generates canonical managed-environment route families only', function (): void {
[$user, $tenant] = createMinimalUserWithTenant(role: 'owner');
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]);
$urls = [
ManagedEnvironmentLinks::indexUrl($tenant),
ManagedEnvironmentLinks::viewUrl($tenant),
ManagedEnvironmentLinks::requiredPermissionsUrl($tenant),
ManagedEnvironmentLinks::diagnosticsUrl($tenant),
ManagedEnvironmentLinks::accessScopesUrl($tenant),
ManagedEnvironmentLinks::operationsUrl($tenant),
ManagedEnvironmentLinks::providerConnectionsUrl($tenant),
TenantResource::getUrl('index'),
TenantResource::getUrl('view', ['record' => $tenant]),
TenantResource::getUrl('edit', ['record' => $tenant]),
TenantResource::getUrl('memberships', ['record' => $tenant]),
OperationRunLinks::index($tenant),
];
$run = OperationRun::factory()->create([
'workspace_id' => (int) $tenant->workspace_id,
'managed_environment_id' => (int) $tenant->getKey(),
]);
$urls[] = OperationRunLinks::tenantlessView($run);
foreach ($urls as $url) {
expect($url)
->not->toContain('/admin/tenants')
->not->toContain('/admin/t/');
}
expect(ManagedEnvironmentLinks::viewUrl($tenant))->toContain('/admin/workspaces/')
->and(ManagedEnvironmentLinks::viewUrl($tenant))->toContain('/environments/'.$tenant->getRouteKey())
->and(ManagedEnvironmentLinks::requiredPermissionsUrl($tenant))->toEndWith('/required-permissions')
->and(ManagedEnvironmentLinks::diagnosticsUrl($tenant))->toEndWith('/diagnostics')
->and(ManagedEnvironmentLinks::accessScopesUrl($tenant))->toEndWith('/access-scopes')
->and(ManagedEnvironmentLinks::providerConnectionsUrl($tenant))->toContain('/admin/provider-connections?managed_environment_id='.(string) $tenant->external_id)
->and(OperationRunLinks::index($tenant))->toContain('/admin/workspaces/')
->and(OperationRunLinks::tenantlessView($run))->toContain('/admin/workspaces/');
});
it('keeps the retired TenantResource out of global search', function (): void {
[$user, $tenant] = createMinimalUserWithTenant(role: 'owner');
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]);
expect(TenantResource::getGlobalSearchResults((string) $tenant->name))->toHaveCount(0);
});