<?php

it('scopes economic transfer queue route reads and retries to the current user', function (): void {
    $economic_invoice_route = file_get_contents(app_path('routes/economicInvoiceRoute.php'));
    $collected_invoice_route = file_get_contents(app_path('routes/orderInvoicesRoute.php'));
    $queue = file_get_contents(app_path('classes/economic_transfer_queue.php'));

    expect($economic_invoice_route)->not->toBeFalse();
    expect($collected_invoice_route)->not->toBeFalse();
    expect($queue)->not->toBeFalse();

    expect($economic_invoice_route)->toContain('$queue->getJobByIdForUser((int)$job_id, (int)$user->id)');
    expect($economic_invoice_route)->toContain('$queue->retryJobForUser((int)$job_id, (int)$user->id)');

    expect($collected_invoice_route)->toContain('$queue->listJobsForCreatedBy(');
    expect($collected_invoice_route)->toContain('$this->countCollectedInvoiceQueueJobs($queue, $statuses, (int)$user->id)');
    expect($collected_invoice_route)->toContain('private function requireCollectedInvoiceQueueJobById(int $job_id, int $created_by, bool $mustBeFailed = false): array');
    expect($collected_invoice_route)->toContain('$queue->getJobByIdForUser($job_id, $created_by)');
    expect($collected_invoice_route)->toContain('$queue->retryJobForUser($job_id, (int)$user->id)');

    expect($queue)->toContain('SELECT * FROM economic_transfer_queue_jobs WHERE id = ? AND created_by = ? LIMIT 1');
    expect($queue)->toContain('WHERE q.created_by = $user_id');
    expect($queue)->toContain('AND created_by = ?');
});
