57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\ManagedTenants\ArchivedStatus;
|
|
use App\Models\Tenant;
|
|
use App\Support\ManagedTenants\ManagedTenantContext;
|
|
use Filament\Actions\Action;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
it('disables restore and force-delete actions for members without permission and does not execute them', function (): void {
|
|
$activeTenant = Tenant::factory()->create(['status' => 'active']);
|
|
$archivedTenant = Tenant::factory()->create(['status' => 'active']);
|
|
|
|
[$user] = createUserWithTenant($activeTenant, role: 'owner');
|
|
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$archivedTenant->getKey() => [
|
|
'role' => 'readonly',
|
|
'source' => 'manual',
|
|
'created_by_user_id' => $user->getKey(),
|
|
],
|
|
]);
|
|
|
|
$archivedTenant->delete();
|
|
|
|
$this->actingAs($user);
|
|
|
|
$activeTenant->makeCurrent();
|
|
Filament::setTenant($activeTenant, true);
|
|
|
|
$this->withSession([
|
|
ManagedTenantContext::ARCHIVED_TENANT_ID_SESSION_KEY => $archivedTenant->getKey(),
|
|
]);
|
|
|
|
Livewire::test(ArchivedStatus::class)
|
|
->assertActionVisible('restore')
|
|
->assertActionDisabled('restore')
|
|
->assertActionExists('restore', fn (Action $action): bool => $action->isConfirmationRequired())
|
|
->assertActionVisible('force_delete')
|
|
->assertActionDisabled('force_delete')
|
|
->assertActionExists('force_delete', fn (Action $action): bool => $action->isConfirmationRequired())
|
|
->mountAction('restore')
|
|
->callMountedAction()
|
|
->assertSuccessful();
|
|
|
|
expect(Tenant::withTrashed()->find($archivedTenant->getKey())?->trashed())->toBeTrue();
|
|
|
|
Livewire::test(ArchivedStatus::class)
|
|
->mountAction('force_delete')
|
|
->callMountedAction()
|
|
->assertSuccessful();
|
|
|
|
expect(Tenant::withTrashed()->find($archivedTenant->getKey()))->not->toBeNull();
|
|
});
|