TenantAtlas/apps/platform/tests/Feature/TenantRBAC/TenantDiagnosticsAccessTest.php
Ahmed Darrazi 1123b122d9
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 7m13s
feat: cut over tenant core to managed environments
2026-05-07 08:35:42 +02:00

49 lines
1.6 KiB
PHP

<?php
use App\Filament\Pages\TenantDiagnostics;
use App\Models\ManagedEnvironmentMembership;
use App\Support\Rbac\UiTooltips;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use App\Models\ManagedEnvironment;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('allows members to access the tenant diagnostics page', function () {
[$user, $tenant] = createUserWithTenant(role: 'readonly');
$this->actingAs($user)
->get("/admin/t/{$tenant->external_id}/diagnostics")
->assertSuccessful();
});
it('returns 404 for non-members on the tenant diagnostics page', function () {
$tenant = ManagedEnvironment::factory()->create(['external_id' => 'tenant-diag-a']);
$user = User::factory()->create();
$this->actingAs($user)
->get("/admin/t/{$tenant->external_id}/diagnostics")
->assertNotFound();
});
it('shows disabled repair affordances to readonly members when a defect exists', function () {
[$user, $tenant] = createUserWithTenant(role: 'readonly');
$this->actingAs($user);
Filament::setTenant($tenant, true);
ManagedEnvironmentMembership::query()
->where('managed_environment_id', (int) $tenant->getKey())
->update(['role' => 'readonly']);
Livewire::test(TenantDiagnostics::class)
->assertActionVisible('bootstrapOwner')
->assertActionDisabled('bootstrapOwner')
->assertActionExists('bootstrapOwner', function (Action $action): bool {
return $action->getTooltip() === UiTooltips::INSUFFICIENT_PERMISSION;
});
});