TenantAtlas/apps/platform/tests/Browser/Spec280WorkspaceTenancyEnvironmentRoutingSmokeTest.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

105 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\ManagedEnvironment;
use App\Models\OperationRun;
use App\Models\ProviderConnection;
use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunStatus;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
pest()->browser()->timeout(20_000);
it('smokes the workspace-first admin flow from workspace selection to environment dashboard to operations hub', function (): void {
$workspace = Workspace::factory()->create([
'name' => 'Spec 280 Workspace',
]);
$otherWorkspace = Workspace::factory()->create([
'name' => 'Spec 280 Other Workspace',
]);
$tenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec 280 Production',
'slug' => 'spec-280-production',
]);
$secondaryTenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec 280 Secondary',
'slug' => 'spec-280-secondary',
]);
$otherWorkspaceTenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $otherWorkspace->getKey(),
'name' => 'Spec 280 Other Workspace ManagedEnvironment',
'slug' => 'spec-280-other-workspace',
]);
$user = User::factory()->create();
foreach ([$workspace, $otherWorkspace] as $memberWorkspace) {
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $memberWorkspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
}
foreach ([$tenant, $secondaryTenant, $otherWorkspaceTenant] as $memberTenant) {
$user->tenants()->syncWithoutDetaching([
(int) $memberTenant->getKey() => ['role' => 'owner'],
]);
}
ProviderConnection::factory()->platform()->consentGranted()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $workspace->getKey(),
'is_default' => true,
]);
$run = OperationRun::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $workspace->getKey(),
'type' => 'inventory_sync',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
]);
$this->actingAs($user);
$workspaceChooser = visit('/admin')
->waitForText('Spec 280 Workspace')
->assertSee('Spec 280 Other Workspace')
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
$environmentChooser = visit(route('admin.workspace.managed-environments.index', ['workspace' => $workspace]))
->waitForText('Spec 280 Production')
->assertSee('Spec 280 Secondary')
->assertDontSee('Spec 280 Other Workspace ManagedEnvironment')
->assertScript("window.location.pathname.includes('/admin/workspaces/{$workspace->getRouteKey()}/environments')", true)
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
$dashboard = $environmentChooser
->click('[wire\\:key="tenant-'.$tenant->getKey().'"]')
->waitForText('Spec 280 Production')
->waitForText('Show all operations')
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
$dashboard
->click('Show all operations')
->waitForText('Monitoring landing')
->assertSee('Open run detail')
->assertSee('Spec 280 Production')
->assertScript("window.location.pathname.includes('/admin/workspaces/{$workspace->getRouteKey()}/operations')", true)
->assertScript("window.location.search.includes('managed_environment_id={$tenant->getKey()}')", true)
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
});