57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\Onboarding\TenantOnboardingWizard;
|
|
use App\Models\OnboardingSession;
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
it('acquires a session lock for the first operator and blocks mutations for other operators', function () {
|
|
[$userA, $tenant] = createUserWithTenant(role: 'operator');
|
|
|
|
$userB = User::factory()->create();
|
|
createUserWithTenant(tenant: $tenant, user: $userB, role: 'operator');
|
|
|
|
$connectionA = ProviderConnection::factory()->for($tenant)->create([
|
|
'provider' => 'microsoft',
|
|
'is_default' => true,
|
|
]);
|
|
|
|
$connectionB = ProviderConnection::factory()->for($tenant)->create([
|
|
'provider' => 'microsoft',
|
|
'is_default' => false,
|
|
]);
|
|
|
|
$this->actingAs($userA);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(TenantOnboardingWizard::class)
|
|
->set('selectedProviderConnectionId', (int) $connectionA->getKey())
|
|
->assertSuccessful();
|
|
|
|
$session = OnboardingSession::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->first();
|
|
|
|
expect($session)->not->toBeNull();
|
|
expect($session?->provider_connection_id)->toBe((int) $connectionA->getKey());
|
|
expect($session?->locked_by_user_id)->toBe((int) $userA->getKey());
|
|
expect($session?->locked_until)->not->toBeNull();
|
|
expect($session?->locked_until?->isFuture())->toBeTrue();
|
|
|
|
$this->actingAs($userB);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(TenantOnboardingWizard::class)
|
|
->set('selectedProviderConnectionId', (int) $connectionB->getKey())
|
|
->assertSuccessful();
|
|
|
|
$session->refresh();
|
|
|
|
expect($session->provider_connection_id)->toBe((int) $connectionA->getKey());
|
|
expect($session->locked_by_user_id)->toBe((int) $userA->getKey());
|
|
});
|