Queue::fake()); it('прогон в очереди отдаёт queue_position = длине общей очереди (честное ожидание)', function () { $tenant = Tenant::factory()->create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement('SET app.current_tenant_id = '.$tenant->id); $run = AutopodborRun::create([ 'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'queued', 'region_code' => 16, 'params' => [], ]); // Общая очередь автоподбора = 3 задачи (глобально, у всех клиентов). $this->mock(AutopodborQueue::class)->shouldReceive('pending')->andReturn(3); $this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}") ->assertOk() ->assertJsonPath('data.queue_position', 3) ->assertJsonPath('data.progress', null); }); it('идущий прогон отдаёт progress {stage,total,label}, queue_position пуст', function () { $tenant = Tenant::factory()->create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement('SET app.current_tenant_id = '.$tenant->id); $run = AutopodborRun::create([ 'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'running', 'region_code' => 16, 'params' => [], 'progress' => ['stage' => 2, 'total' => 4, 'label' => 'Ищем фирмы в справочниках'], ]); $this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}") ->assertOk() ->assertJsonPath('data.progress.stage', 2) ->assertJsonPath('data.progress.total', 4) ->assertJsonPath('data.progress.label', 'Ищем фирмы в справочниках') ->assertJsonPath('data.queue_position', null); }); it('завершённый прогон: queue_position пуст (очередь его не касается)', function () { $tenant = Tenant::factory()->create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement('SET app.current_tenant_id = '.$tenant->id); $run = AutopodborRun::create([ 'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 16, 'params' => [], ]); $this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}") ->assertOk() ->assertJsonPath('data.queue_position', null); });