6d48503a0e
Stage 1: опознавалка фирмы по сайту/карточкам, ProposalClassifier new/actualize/archived/hidden, box=archived, bulk удалить всех ранее удалённых. Backend 249/249, front autopodbor 61/61. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
50 lines
2.7 KiB
PHP
50 lines
2.7 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]);
|
||
|
||
$groups = $this->actingAs($user)->getJson('/api/autopodbor/proposals')
|
||
->assertOk()
|
||
->json('groups');
|
||
|
||
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([]);
|
||
});
|
||
|
||
it('GET /api/autopodbor/proposals — чужой тенант своих не видит (группы пусты)', function () {
|
||
$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]);
|
||
$groups = $this->actingAs($other)->getJson('/api/autopodbor/proposals')->assertOk()->json('groups');
|
||
|
||
expect($groups['new'])->toBe([])
|
||
->and($groups['actualize'])->toBe([])
|
||
->and($groups['archived'])->toBe([]);
|
||
});
|