43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\TenantOnboardingWizard;
|
|
use App\Models\Tenant;
|
|
use Livewire\Livewire;
|
|
|
|
it('prevents creating a duplicate tenant for the same tenant_id', function (): void {
|
|
config()->set('tenantpilot.onboarding.credentials_required', false);
|
|
|
|
[$user, $portfolioTenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
|
|
$tenantGuid = fake()->uuid();
|
|
|
|
$existing = Tenant::factory()->create([
|
|
'name' => 'Already Exists',
|
|
'tenant_id' => $tenantGuid,
|
|
'environment' => 'prod',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$existing->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
Livewire::withQueryParams([
|
|
'tenant' => (string) $portfolioTenant->external_id,
|
|
])->test(TenantOnboardingWizard::class)
|
|
->goToNextWizardStep()
|
|
->fillForm([
|
|
'name' => 'Attempt Duplicate',
|
|
'environment' => 'prod',
|
|
'tenant_id' => $tenantGuid,
|
|
'domain' => 'dup.example',
|
|
], 'form')
|
|
->goToNextWizardStep();
|
|
|
|
expect(Tenant::query()->where('tenant_id', $tenantGuid)->count())->toBe(1);
|
|
});
|