<?php

use App\Jobs\SyncPoliciesJob;
use App\Models\OperationRun;
use Illuminate\Support\Facades\Bus;

it('dispatches SyncPoliciesJob with an OperationRun as the 4th argument', function () {
    Bus::fake();

    $operationRun = OperationRun::factory()->create();

    SyncPoliciesJob::dispatch((int) $operationRun->managed_environment_id, null, null, $operationRun);

    Bus::assertDispatched(SyncPoliciesJob::class, function (SyncPoliciesJob $job) use ($operationRun): bool {
        return $job->tenantId === (int) $operationRun->managed_environment_id
            && $job->types === null
            && $job->policyIds === null
            && (int) $job->operationRun?->getKey() === (int) $operationRun->getKey();
    });
});
