70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Jobs\Onboarding\OnboardingConsentStatusJob;
|
|
use App\Models\OnboardingEvidence;
|
|
use App\Models\OnboardingSession;
|
|
use App\Models\OperationRun;
|
|
use App\Models\ProviderConnection;
|
|
use App\Support\Onboarding\OnboardingTaskType;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
|
|
it('writes consent status evidence and completes the run', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$connection = ProviderConnection::factory()
|
|
->for($tenant)
|
|
->create([
|
|
'status' => 'connected',
|
|
'health_status' => 'ok',
|
|
]);
|
|
|
|
$session = OnboardingSession::factory()
|
|
->for($tenant)
|
|
->create([
|
|
'provider_connection_id' => $connection->getKey(),
|
|
'assigned_to_user_id' => $user->getKey(),
|
|
'status' => 'in_progress',
|
|
'current_step' => 4,
|
|
]);
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'initiator_name' => $user->name,
|
|
'type' => OnboardingTaskType::ConsentStatus,
|
|
'status' => OperationRunStatus::Queued->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
]);
|
|
|
|
$job = new OnboardingConsentStatusJob(
|
|
tenantId: (int) $tenant->getKey(),
|
|
userId: (int) $user->getKey(),
|
|
providerConnectionId: (int) $connection->getKey(),
|
|
onboardingSessionId: (int) $session->getKey(),
|
|
operationRun: $run,
|
|
);
|
|
|
|
$job->handle(
|
|
evidence: app(\App\Services\Onboarding\OnboardingEvidenceWriter::class),
|
|
runs: app(\App\Services\OperationRunService::class),
|
|
);
|
|
|
|
$evidence = OnboardingEvidence::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->where('onboarding_session_id', $session->getKey())
|
|
->where('provider_connection_id', $connection->getKey())
|
|
->where('task_type', OnboardingTaskType::ConsentStatus)
|
|
->orderByDesc('id')
|
|
->first();
|
|
|
|
expect($evidence)->not->toBeNull();
|
|
expect($evidence?->status)->toBe('ok');
|
|
|
|
$run->refresh();
|
|
expect($run->status)->toBe(OperationRunStatus::Completed->value);
|
|
expect($run->outcome)->toBe(OperationRunOutcome::Succeeded->value);
|
|
});
|