TenantAtlas/tests/Feature/ManagedTenantOnboardingWizardTest.php
2026-02-01 12:20:09 +01:00

56 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\TenantOnboardingWizard;
use App\Models\Tenant;
use App\Models\TenantOnboardingSession;
use Livewire\Livewire;
it('creates a tenant and persists onboarding session state', function (): void {
config()->set('tenantpilot.onboarding.credentials_required', true);
[$user, $portfolioTenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
$tenantGuid = fake()->uuid();
$component = Livewire::withQueryParams([
'tenant' => (string) $portfolioTenant->external_id,
])->test(TenantOnboardingWizard::class);
$component
->assertStatus(200)
->goToNextWizardStep()
->fillForm([
'name' => 'Acme Corp',
'environment' => 'prod',
'tenant_id' => $tenantGuid,
'domain' => 'acme.example',
], 'form')
->goToNextWizardStep()
->fillForm([
'app_client_id' => fake()->uuid(),
'app_client_secret' => 'super-secret-value',
'app_certificate_thumbprint' => null,
'app_notes' => 'Created via onboarding wizard',
'acknowledge_credentials' => true,
], 'form')
->goToNextWizardStep();
$tenant = Tenant::query()->where('tenant_id', $tenantGuid)->first();
expect($tenant)->toBeInstanceOf(Tenant::class);
expect($tenant->onboarding_status)->toBe('in_progress');
expect($user->tenants()->whereKey($tenant->getKey())->exists())->toBeTrue();
$session = TenantOnboardingSession::query()->where('tenant_id', $tenant->getKey())->first();
expect($session)->toBeInstanceOf(TenantOnboardingSession::class);
expect($session->status)->toBe('active');
expect($session->payload)->toBeArray();
expect($session->payload)->not->toHaveKey('app_client_secret');
});