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\ProviderCredential;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
it('migrates legacy tenant app credentials into provider credentials when confirmed', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$tenant->forceFill([
|
|
'app_client_id' => '00000000-0000-0000-0000-000000000000',
|
|
'app_client_secret' => 'TENANT_SECRET_FOR_MIGRATION',
|
|
])->save();
|
|
|
|
$connection = ProviderConnection::factory()->for($tenant)->create([
|
|
'provider' => 'microsoft',
|
|
'is_default' => true,
|
|
]);
|
|
|
|
OnboardingSession::query()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'provider_connection_id' => $connection->getKey(),
|
|
'status' => 'in_progress',
|
|
'current_step' => 2,
|
|
'assigned_to_user_id' => $user->getKey(),
|
|
'metadata' => [],
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(TenantOnboardingWizard::class)
|
|
->assertActionVisible('migrate_legacy_credentials')
|
|
->mountAction('migrate_legacy_credentials')
|
|
->callMountedAction()
|
|
->assertSuccessful();
|
|
|
|
$credential = ProviderCredential::query()
|
|
->where('provider_connection_id', $connection->getKey())
|
|
->first();
|
|
|
|
expect($credential)->not->toBeNull();
|
|
expect($credential?->type)->toBe('client_secret');
|
|
expect($credential?->payload)->toBe([
|
|
'client_id' => '00000000-0000-0000-0000-000000000000',
|
|
'client_secret' => 'TENANT_SECRET_FOR_MIGRATION',
|
|
]);
|
|
|
|
$tenant->refresh();
|
|
expect($tenant->app_client_secret)->toBe('TENANT_SECRET_FOR_MIGRATION');
|
|
});
|