73 lines
2.6 KiB
PHP
73 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\BaselineCompareLanding;
|
|
use App\Filament\Resources\BaselineProfileResource\Pages\ViewBaselineProfile;
|
|
use App\Models\BaselineProfile;
|
|
use App\Models\BaselineSnapshot;
|
|
use App\Models\BaselineTenantAssignment;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
it('keeps baseline capture and compare actions capability-gated on the profile detail page', function (): void {
|
|
[$readonlyUser, $tenant] = createUserWithTenant(role: 'readonly');
|
|
[$ownerUser] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
$profile = BaselineProfile::factory()->active()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
]);
|
|
|
|
$snapshot = BaselineSnapshot::factory()->complete()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
]);
|
|
|
|
$profile->update(['active_snapshot_id' => (int) $snapshot->getKey()]);
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
|
|
|
|
Livewire::actingAs($readonlyUser)
|
|
->test(ViewBaselineProfile::class, ['record' => $profile->getKey()])
|
|
->assertActionDisabled('capture')
|
|
->assertActionDisabled('compareNow');
|
|
|
|
Livewire::actingAs($ownerUser)
|
|
->test(ViewBaselineProfile::class, ['record' => $profile->getKey()])
|
|
->assertActionEnabled('capture')
|
|
->assertActionDisabled('compareNow');
|
|
});
|
|
|
|
it('keeps tenant compare actions disabled for users without tenant.sync and enabled for owners', function (): void {
|
|
[$readonlyUser, $tenant] = createUserWithTenant(role: 'readonly');
|
|
[$ownerUser] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
$profile = BaselineProfile::factory()->active()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
]);
|
|
|
|
$snapshot = BaselineSnapshot::factory()->complete()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
]);
|
|
|
|
$profile->update(['active_snapshot_id' => (int) $snapshot->getKey()]);
|
|
|
|
BaselineTenantAssignment::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($readonlyUser)
|
|
->test(BaselineCompareLanding::class)
|
|
->assertActionDisabled('compareNow');
|
|
|
|
Livewire::actingAs($ownerUser)
|
|
->test(BaselineCompareLanding::class)
|
|
->assertActionEnabled('compareNow');
|
|
});
|