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

53 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\TenantOnboardingWizard;
use App\Jobs\ProviderConnectionHealthCheckJob;
use App\Models\OperationRun;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
it('creates and dedupes a provider connection check OperationRun and dispatches a job', function (): void {
config()->set('tenantpilot.onboarding.credentials_required', true);
Bus::fake();
[$user, $portfolioTenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
$tenantGuid = fake()->uuid();
$component = Livewire::withQueryParams([
'tenant' => (string) $portfolioTenant->external_id,
])->test(TenantOnboardingWizard::class)
->goToNextWizardStep()
->fillForm([
'name' => 'Acme',
'environment' => 'other',
'tenant_id' => $tenantGuid,
'domain' => 'acme.example',
], 'form')
->goToNextWizardStep()
->fillForm([
'app_client_id' => fake()->uuid(),
'app_client_secret' => 'super-secret',
'acknowledge_credentials' => true,
], 'form')
->goToNextWizardStep()
->goToNextWizardStep();
$component->call('enqueueConnectionCheck');
expect(OperationRun::query()->where('type', 'provider.connection.check')->count())->toBe(1);
Bus::assertDispatched(ProviderConnectionHealthCheckJob::class, 1);
$component->call('enqueueConnectionCheck');
expect(OperationRun::query()->where('type', 'provider.connection.check')->count())->toBe(1);
Bus::assertDispatched(ProviderConnectionHealthCheckJob::class, 1);
});