52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\TenantOnboardingWizard;
|
|
use App\Models\Tenant;
|
|
use App\Models\TenantOnboardingSession;
|
|
use Livewire\Livewire;
|
|
|
|
it('resumes an active session for the same tenant instead of creating a new one', function (): void {
|
|
config()->set('tenantpilot.onboarding.credentials_required', false);
|
|
|
|
[$user] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
|
|
$tenant = Tenant::factory()->create([
|
|
'name' => 'Existing Tenant',
|
|
'tenant_id' => fake()->uuid(),
|
|
'environment' => 'other',
|
|
'status' => 'active',
|
|
'onboarding_status' => 'in_progress',
|
|
]);
|
|
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$tenant->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
$existingSession = TenantOnboardingSession::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'created_by_user_id' => $user->getKey(),
|
|
'status' => 'active',
|
|
'current_step' => 'permissions',
|
|
'payload' => [
|
|
'name' => $tenant->name,
|
|
'tenant_id' => $tenant->tenant_id,
|
|
'environment' => $tenant->environment,
|
|
],
|
|
]);
|
|
|
|
$component = Livewire::withQueryParams([
|
|
'tenant' => (string) $tenant->external_id,
|
|
])->test(TenantOnboardingWizard::class);
|
|
|
|
expect($component->get('sessionId'))->toBe((string) $existingSession->getKey());
|
|
|
|
expect(TenantOnboardingSession::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->where('status', 'active')
|
|
->count())->toBe(1);
|
|
});
|