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); } }