actingAs($user); $tenant->makeCurrent(); Filament::setTenant($tenant, true); $connection = ProviderConnection::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('provider', 'microsoft') ->where('is_default', true) ->firstOrFail(); $component = Livewire::test(ViewTenant::class, ['record' => $tenant->getRouteKey()]); $component->callAction('verify'); $component->callAction('verify'); $run = OperationRun::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('type', 'provider.connection.check') ->latest('id') ->first(); expect($run)->not->toBeNull(); expect($run?->status)->toBe('queued'); expect($run?->context)->toMatchArray([ 'provider' => 'microsoft', 'module' => 'health_check', 'provider_connection_id' => (int) $connection->getKey(), 'target_scope' => [ 'entra_tenant_id' => $connection->entra_tenant_id, ], ]); expect(OperationRun::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('type', 'provider.connection.check') ->count())->toBe(1); Queue::assertPushed(ProviderConnectionHealthCheckJob::class, 1); }); it('blocks tenant verification before queue when no provider connection is available', function (): void { Queue::fake(); [$user, $tenant] = createUserWithTenant(role: 'operator', ensureDefaultMicrosoftProviderConnection: false); $this->actingAs($user); $tenant->makeCurrent(); Filament::setTenant($tenant, true); Livewire::test(ViewTenant::class, ['record' => $tenant->getRouteKey()]) ->callAction('verify'); $run = OperationRun::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('type', 'provider.connection.check') ->latest('id') ->first(); expect($run)->not->toBeNull(); expect($run?->outcome)->toBe('blocked'); expect($run?->context['reason_code'] ?? null)->toBe(ProviderReasonCodes::ProviderConnectionMissing); Queue::assertNothingPushed(); });