Update tenant lifecycle tooling and retire docs/process

This commit is contained in:
Codex Agent
2026-01-01 17:02:08 +01:00
parent 1e57fc1046
commit 405a4b7340
44 changed files with 631 additions and 860 deletions

View File

@@ -0,0 +1,120 @@
<?php
namespace Tests\Feature;
use App\Filament\Resources\TenantResource\Pages\ListTenants;
use App\Jobs\AnonymizeAccount;
use App\Models\Tenant;
use App\Models\User;
use Filament\Actions\Testing\TestAction;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Queue;
use Livewire\Livewire;
use Tests\TestCase;
class TenantLifecycleActionsTest extends TestCase
{
use RefreshDatabase;
public function test_superadmin_can_schedule_and_cancel_tenant_deletion(): void
{
Notification::fake();
$user = User::factory()->create(['role' => 'super_admin']);
$tenant = Tenant::factory()->create();
$this->bootSuperAdminPanel($user);
$plannedDeletion = now()->addWeeks(2);
Livewire::test(ListTenants::class)
->callAction(
TestAction::make('schedule_deletion')->table($tenant),
[
'pending_deletion_at' => $plannedDeletion->toDateTimeString(),
'send_warning' => false,
]
);
$tenant->refresh();
$this->assertNotNull($tenant->pending_deletion_at);
$this->assertSame(
$plannedDeletion->toDateTimeString(),
$tenant->pending_deletion_at?->toDateTimeString()
);
Livewire::test(ListTenants::class)
->callAction(TestAction::make('cancel_deletion')->table($tenant));
$tenant->refresh();
$this->assertNull($tenant->pending_deletion_at);
$this->assertNull($tenant->deletion_warning_sent_at);
}
public function test_superadmin_can_toggle_tenant_status_flags(): void
{
$user = User::factory()->create(['role' => 'super_admin']);
$tenant = Tenant::factory()->create([
'is_active' => true,
'is_suspended' => false,
]);
$this->bootSuperAdminPanel($user);
Livewire::test(ListTenants::class)
->callAction(TestAction::make('deactivate')->table($tenant));
$tenant->refresh();
$this->assertFalse((bool) $tenant->is_active);
Livewire::test(ListTenants::class)
->callAction(TestAction::make('activate')->table($tenant));
$tenant->refresh();
$this->assertTrue((bool) $tenant->is_active);
Livewire::test(ListTenants::class)
->callAction(TestAction::make('suspend')->table($tenant));
$tenant->refresh();
$this->assertTrue((bool) $tenant->is_suspended);
Livewire::test(ListTenants::class)
->callAction(TestAction::make('unsuspend')->table($tenant));
$tenant->refresh();
$this->assertFalse((bool) $tenant->is_suspended);
}
public function test_superadmin_can_dispatch_tenant_anonymization(): void
{
Queue::fake();
$user = User::factory()->create(['role' => 'super_admin']);
$tenant = Tenant::factory()->create();
$this->bootSuperAdminPanel($user);
Livewire::test(ListTenants::class)
->callAction(TestAction::make('anonymize_now')->table($tenant));
Queue::assertPushed(AnonymizeAccount::class, function (AnonymizeAccount $job) use ($tenant) {
return $job->tenantId() === $tenant->id;
});
}
private function bootSuperAdminPanel(User $user): void
{
$panel = Filament::getPanel('superadmin');
$this->assertNotNull($panel);
Filament::setCurrentPanel($panel);
Filament::bootCurrentPanel();
Filament::auth()->login($user);
}
}