43 lines
2.2 KiB
PHP
43 lines
2.2 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
declare(strict_types=1);
|
|||
|
|
|
|||
|
|
use App\Models\Tenant;
|
|||
|
|
use App\Models\User;
|
|||
|
|
use App\Models\AutopodborRun;
|
|||
|
|
use App\Models\AutopodborCompetitor;
|
|||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Illuminate\Support\Facades\Queue;
|
|||
|
|
|
|||
|
|
uses(DatabaseTransactions::class, \Tests\Concerns\SharesSupplierPdo::class);
|
|||
|
|
beforeEach(fn () => 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);
|
|||
|
|
});
|