TenantAtlas/apps/platform/tests/Feature/EnvironmentReview/EnvironmentReviewRbacTest.php
Ahmed Darrazi 5443dba269
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 7m2s
refactor: consolidate internal tenant model naming
2026-05-14 13:09:36 +02:00

54 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\EnvironmentReviewResource;
use App\Filament\Resources\EnvironmentReviewResource\Pages\ListEnvironmentReviews;
use App\Filament\Resources\EnvironmentReviewResource\Pages\ViewEnvironmentReview;
use App\Models\ManagedEnvironment;
use App\Models\User;
use App\Support\Auth\UiTooltips;
use Livewire\Livewire;
it('returns not found for non-members on the environment review library and detail routes', function (): void {
$targetTenant = ManagedEnvironment::factory()->create();
[$member] = createUserWithTenant(role: 'owner');
$reviewOwner = User::factory()->create();
createUserWithTenant(tenant: $targetTenant, user: $reviewOwner, role: 'owner');
$review = composeEnvironmentReviewForTest($targetTenant, $reviewOwner);
$this->actingAs($member)
->get(EnvironmentReviewResource::tenantScopedUrl('index', tenant: $targetTenant))
->assertNotFound();
$this->actingAs($member)
->get(EnvironmentReviewResource::tenantScopedUrl('view', ['record' => $review], $targetTenant))
->assertNotFound();
});
it('allows readonly members to inspect reviews but keeps create actions disabled', function (): void {
$tenant = ManagedEnvironment::factory()->create();
[$owner, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
[$readonly] = createUserWithTenant(tenant: $tenant, user: User::factory()->create(), role: 'readonly');
$review = composeEnvironmentReviewForTest($tenant, $owner);
$this->actingAs($readonly)
->get(EnvironmentReviewResource::tenantScopedUrl('view', ['record' => $review], $tenant))
->assertOk();
setAdminEnvironmentContext($tenant);
Livewire::actingAs($readonly)
->test(ListEnvironmentReviews::class)
->assertActionVisible('create_review')
->assertActionDisabled('create_review')
->assertActionExists('create_review', fn ($action): bool => $action->getTooltip() === UiTooltips::insufficientPermission());
Livewire::actingAs($readonly)
->test(ViewEnvironmentReview::class, ['record' => $review->getKey()])
->assertActionVisible('publish_review')
->assertActionDisabled('publish_review')
->assertActionVisible('archive_review')
->assertActionDisabled('archive_review');
});