2026-06-30 04:18:46 +03:00
|
|
|
|
<?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);
|
|
|
|
|
|
|
2026-07-01 15:45:11 +03:00
|
|
|
|
it('GET /api/autopodbor/proposals — делит на группы; новые сортируются по похожести', function () {
|
2026-06-30 04:18:46 +03:00
|
|
|
|
$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]);
|
2026-07-01 15:45:11 +03:00
|
|
|
|
// в поле — не предложение, в группы не попадает
|
2026-06-30 04:18:46 +03:00
|
|
|
|
AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'В поле', 'dedup_key' => 'fld', 'box' => 'field', 'relevance_pct' => 100]);
|
|
|
|
|
|
|
2026-07-01 15:45:11 +03:00
|
|
|
|
$groups = $this->actingAs($user)->getJson('/api/autopodbor/proposals')
|
2026-06-30 04:18:46 +03:00
|
|
|
|
->assertOk()
|
2026-07-01 15:45:11 +03:00
|
|
|
|
->json('groups');
|
2026-06-30 04:18:46 +03:00
|
|
|
|
|
2026-07-01 15:45:11 +03:00
|
|
|
|
expect($groups['new'])->toHaveCount(2)
|
|
|
|
|
|
->and($groups['new'][0]['name'])->toBe('Высокая') // сорт по похожести
|
|
|
|
|
|
->and($groups['new'][1]['name'])->toBe('Низкая')
|
|
|
|
|
|
->and($groups['actualize'])->toBe([])
|
|
|
|
|
|
->and($groups['archived'])->toBe([]);
|
2026-06-30 04:18:46 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-07-01 15:45:11 +03:00
|
|
|
|
it('GET /api/autopodbor/proposals — чужой тенант своих не видит (группы пусты)', function () {
|
2026-06-30 04:18:46 +03:00
|
|
|
|
$tenant = Tenant::factory()->create();
|
|
|
|
|
|
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]);
|
2026-07-01 15:45:11 +03:00
|
|
|
|
$groups = $this->actingAs($other)->getJson('/api/autopodbor/proposals')->assertOk()->json('groups');
|
|
|
|
|
|
|
|
|
|
|
|
expect($groups['new'])->toBe([])
|
|
|
|
|
|
->and($groups['actualize'])->toBe([])
|
|
|
|
|
|
->and($groups['archived'])->toBe([]);
|
2026-06-30 04:18:46 +03:00
|
|
|
|
});
|