2026-06-28 15:15:16 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
2026-07-01 15:45:37 +03:00
|
|
|
|
use App\Models\AutopodborCompetitor;
|
|
|
|
|
|
use App\Models\AutopodborRun;
|
2026-06-28 15:15:16 +03:00
|
|
|
|
use App\Models\Tenant;
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
use Illuminate\Support\Facades\Queue;
|
2026-07-01 15:45:37 +03:00
|
|
|
|
use Tests\Concerns\SharesSupplierPdo;
|
2026-06-28 15:15:16 +03:00
|
|
|
|
|
2026-07-01 15:45:37 +03:00
|
|
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
2026-06-28 15:15:16 +03:00
|
|
|
|
beforeEach(fn () => Queue::fake());
|
|
|
|
|
|
|
|
|
|
|
|
it('GET /api/autopodbor/runs/{run}/competitors отдаёт конкурентов прогона по убыванию релевантности', function () {
|
|
|
|
|
|
$tenant = Tenant::factory()->create();
|
|
|
|
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
2026-07-01 15:45:37 +03:00
|
|
|
|
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']);
|
2026-06-28 15:15:16 +03:00
|
|
|
|
|
|
|
|
|
|
$resp = $this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}/competitors")
|
|
|
|
|
|
->assertOk()
|
2026-07-01 15:45:37 +03:00
|
|
|
|
->assertJsonStructure(['data' => [['id', 'name', 'relevance_pct']]]);
|
2026-06-28 15:15:16 +03:00
|
|
|
|
$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]);
|
2026-07-01 15:45:37 +03:00
|
|
|
|
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' => []]);
|
2026-06-28 15:15:16 +03:00
|
|
|
|
|
|
|
|
|
|
$this->actingAs($user)->getJson("/api/autopodbor/runs/{$study->id}")
|
|
|
|
|
|
->assertOk()
|
|
|
|
|
|
->assertJsonPath('data.competitor_id', $comp->id);
|
|
|
|
|
|
});
|