47 lines
2.6 KiB
PHP
47 lines
2.6 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
declare(strict_types=1);
|
|||
|
|
|
|||
|
|
use App\Models\AutopodborCompetitor;
|
|||
|
|
use App\Models\AutopodborRun;
|
|||
|
|
use App\Models\Tenant;
|
|||
|
|
use App\Models\User;
|
|||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Tests\Concerns\SharesSupplierPdo;
|
|||
|
|
|
|||
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
|||
|
|
|
|||
|
|
it('GET /api/autopodbor/proposals — отдаёт только конкурентов-предложения, сорт по похожести', 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' => 'Низкая', 'dedup_key' => 'low', 'box' => 'proposal', 'relevance_pct' => 40]);
|
|||
|
|
AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Высокая', 'dedup_key' => 'high', 'box' => 'proposal', 'relevance_pct' => 95]);
|
|||
|
|
// в поле — не предложение, не должен попасть
|
|||
|
|
AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'В поле', 'dedup_key' => 'fld', 'box' => 'field', 'relevance_pct' => 100]);
|
|||
|
|
|
|||
|
|
$data = $this->actingAs($user)->getJson('/api/autopodbor/proposals')
|
|||
|
|
->assertOk()
|
|||
|
|
->assertJsonStructure(['data' => [['id', 'name', 'box', 'relevance_pct']]])
|
|||
|
|
->json('data');
|
|||
|
|
|
|||
|
|
expect($data)->toHaveCount(2)
|
|||
|
|
->and($data[0]['name'])->toBe('Высокая') // сорт по похожести
|
|||
|
|
->and($data[1]['name'])->toBe('Низкая');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('GET /api/autopodbor/proposals — чужой тенант своих не видит', 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' => 'Чужой', 'dedup_key' => 'a', 'box' => 'proposal']);
|
|||
|
|
|
|||
|
|
$other = User::factory()->create(['tenant_id' => Tenant::factory()->create()->id]);
|
|||
|
|
$data = $this->actingAs($other)->getJson('/api/autopodbor/proposals')->assertOk()->json('data');
|
|||
|
|
expect($data)->toHaveCount(0);
|
|||
|
|
});
|