active()->create(['name' => 'Lifecycle Audit Tenant']); [$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner'); $this->actingAs($user); Filament::setTenant($tenant, true); Livewire::test(ViewTenant::class, ['record' => $tenant->getRouteKey()]) ->assertActionExists('archive', function (Action $action): bool { return $action->getLabel() === 'Archive' && $action->isConfirmationRequired(); }) ->mountAction('archive') ->setActionData([ 'archive_reason' => 'Retiring this tenant from active management.', ]) ->callMountedAction() ->assertHasNoActionErrors(); $tenant->refresh(); expect($tenant->trashed())->toBeTrue(); expect(AuditLog::query() ->where('workspace_id', (int) $tenant->workspace_id) ->where('tenant_id', (int) $tenant->getKey()) ->where('action', AuditActionId::TenantArchived->value) ->exists())->toBeTrue(); $archiveAudit = AuditLog::query() ->where('workspace_id', (int) $tenant->workspace_id) ->where('tenant_id', (int) $tenant->getKey()) ->where('action', AuditActionId::TenantArchived->value) ->latest('id') ->first(); expect(data_get($archiveAudit?->metadata, 'reason'))->toBe('Retiring this tenant from active management.'); Filament::setTenant(null, true); Livewire::actingAs($user) ->test(ViewTenant::class, ['record' => $tenant->getRouteKey()]) ->assertActionExists('restore', function (Action $action): bool { return $action->getLabel() === 'Restore' && $action->isConfirmationRequired(); }) ->mountAction('restore') ->callMountedAction() ->assertHasNoActionErrors(); $tenant->refresh(); expect($tenant->trashed())->toBeFalse(); expect(AuditLog::query() ->where('workspace_id', (int) $tenant->workspace_id) ->where('tenant_id', (int) $tenant->getKey()) ->where('action', AuditActionId::TenantRestored->value) ->exists())->toBeTrue(); });