Queue::fake()); it('GET /api/autopodbor/runs/{run}/competitors отдаёт конкурентов прогона по убыванию релевантности', 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' => []]); AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Б', 'relevance_pct' => 60, 'dedup_key' => 'b']); AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'А', 'relevance_pct' => 100, 'dedup_key' => 'a']); $resp = $this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}/competitors") ->assertOk() ->assertJsonStructure(['data' => [['id', 'name', 'relevance_pct']]]); $data = $resp->json('data'); expect($data[0]['name'])->toBe('А')->and($data[1]['name'])->toBe('Б'); // 100 раньше 60 }); it('study-прогон в RunResource отдаёт competitor_id', function () { $tenant = Tenant::factory()->create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement('SET app.current_tenant_id = '.$tenant->id); $search = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 16, 'params' => []]); $comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $search->id, 'name' => 'Окна', 'dedup_key' => 'o']); $study = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'done', 'region_code' => 16, 'competitor_id' => $comp->id, 'params' => []]); $this->actingAs($user)->getJson("/api/autopodbor/runs/{$study->id}") ->assertOk() ->assertJsonPath('data.competitor_id', $comp->id); });