TenantAtlas/apps/platform/tests/Feature/Reviews/CustomerReviewWorkspaceHubContractTest.php
ahmido b159dacd36 feat: clean up legacy tenant environment context (#372)
## Summary
- remove legacy tenant-scoped routing and middleware paths in favor of the current environment/workspace context flow
- update Filament pages and resources to use the cleaned-up admin surface and environment filter context
- add the related spec 317 artifacts and targeted tests for environment filter state and legacy context cleanup

## Testing
- not run as part of this commit/push/PR workflow

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #372
2026-05-16 18:25:36 +00:00

95 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\Reviews\CustomerReviewWorkspace;
use App\Models\ManagedEnvironment;
use App\Support\EnvironmentReviewStatus;
use App\Support\Workspaces\WorkspaceContext;
use Filament\Facades\Filament;
use Livewire\Livewire;
it('Spec314 customer review workspace sidebar entry is workspace wide', function (): void {
$environmentA = ManagedEnvironment::factory()->active()->create(['name' => 'Customer Review A']);
[$user, $environmentA] = createUserWithTenant(tenant: $environmentA, role: 'readonly');
$environmentB = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $environmentA->workspace_id,
'name' => 'Customer Review B',
]);
createUserWithTenant(tenant: $environmentB, user: $user, role: 'readonly');
$reviewA = composeEnvironmentReviewForTest($environmentA, $user, seedEnvironmentReviewEvidence($environmentA));
$reviewA->forceFill([
'status' => EnvironmentReviewStatus::Published->value,
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
])->save();
$reviewB = composeEnvironmentReviewForTest($environmentB, $user, seedEnvironmentReviewEvidence($environmentB));
$reviewB->forceFill([
'status' => EnvironmentReviewStatus::Published->value,
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
])->save();
Filament::setTenant($environmentA, true);
$url = CustomerReviewWorkspace::getUrl(panel: 'admin');
expect($url)->not->toContain('tenant=')
->and($url)->not->toContain('managed_environment_id');
$this->actingAs($user);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $environmentA->workspace_id);
session()->put(WorkspaceContext::LAST_ENVIRONMENT_IDS_SESSION_KEY, [
(string) $environmentA->workspace_id => (int) $environmentA->getKey(),
]);
Livewire::actingAs($user)
->test(CustomerReviewWorkspace::class)
->assertSet('tableFilters.managed_environment_id.value', null)
->assertCanSeeTableRecords([$environmentA->fresh(), $environmentB->fresh()]);
});
it('Spec314 customer review workspace ignores stale persisted environment filters on clean entry', function (): void {
$environmentA = ManagedEnvironment::factory()->active()->create();
[$user, $environmentA] = createUserWithTenant(tenant: $environmentA, role: 'readonly');
$environmentB = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $environmentA->workspace_id,
]);
createUserWithTenant(tenant: $environmentB, user: $user, role: 'readonly');
composeEnvironmentReviewForTest($environmentA, $user, seedEnvironmentReviewEvidence($environmentA))
->forceFill([
'status' => EnvironmentReviewStatus::Published->value,
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
])->save();
composeEnvironmentReviewForTest($environmentB, $user, seedEnvironmentReviewEvidence($environmentB))
->forceFill([
'status' => EnvironmentReviewStatus::Published->value,
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
])->save();
$this->actingAs($user);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $environmentA->workspace_id);
$component = Livewire::actingAs($user)->test(CustomerReviewWorkspace::class);
$filtersSessionKey = $component->instance()->getTableFiltersSessionKey();
session()->put($filtersSessionKey, [
'managed_environment_id' => ['value' => (string) $environmentA->getKey()],
]);
$this->get(CustomerReviewWorkspace::getUrl(panel: 'admin'))
->assertOk()
->assertSee($environmentA->name)
->assertSee($environmentB->name);
expect(data_get(session()->get($filtersSessionKey, []), 'managed_environment_id.value'))->toBeNull();
});