Files
portal/app/tests/Feature/Autopodbor/AutopodborSourceWhereFoundTest.php
T
Дмитрий a42647c6fe feat(автоподбор): богатый провенанс источника — список «где нашли», офис, подтверждения
Шаг 2 «Конкурентного поля»: один номер встречается в нескольких местах —
код сайта плюс карточки 2ГИС/Яндекс с разными адресами. Раньше хранилось
одно provenance_url/label — список терялся. Теперь сквозной провод
движок→контракт→джоб→БД→API; фронт уже умел показывать кликабельным
списком с подтверждениями.

- autopodbor_sources +3 колонки where_found/office/confirmations
  миграция 2026_06_30_120000, идемпотентная, RLS-review APPROVE 7/7
- canon-sync schema.sql v8.59 плюс CHANGELOG, вкл. catch-up phone_type/box 29.06
- тесты бэкенда автоподбора 122/122

НЕ на проде, воркстри avtopodbor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 15:40:30 +03:00

64 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use App\Http\Resources\Autopodbor\SourceResource;
use App\Jobs\Autopodbor\RunAutopodborStudyJob;
use App\Models\AutopodborCompetitor;
use App\Models\AutopodborRun;
use App\Models\AutopodborSource;
use App\Models\SystemSetting;
use App\Models\Tenant;
use App\Services\Autopodbor\Agent\CompetitorAgent;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;
use Tests\Doubles\RichCompetitorAgent;
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
it('изучение сохраняет «где нашли», офис и подтверждения в БД', function () {
app()->bind(CompetitorAgent::class, RichCompetitorAgent::class);
$tenant = Tenant::factory()->create(['balance_rub' => '100000.00']);
DB::statement('SET app.current_tenant_id = '.$tenant->id);
SystemSetting::updateOrCreate(['key' => 'autopodbor_price_study_rub'], ['value' => '900', 'type' => 'decimal']);
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'КрасЛомбард', 'dedup_key' => 'site:k.ru', 'site_url' => 'k.ru']);
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'queued', 'region_code' => 24, 'competitor_id' => $comp->id, 'params' => []]);
app()->call([new RunAutopodborStudyJob($run->id), 'handle']);
$src = AutopodborSource::where('competitor_id', $comp->id)->where('signal_type', 'call')->firstOrFail();
expect($src->where_found)->toBeArray()->toHaveCount(2);
expect(collect($src->where_found)->pluck('url'))->toContain('https://2gis.ru/firm/1');
expect($src->office)->toBe('Единая справочная');
expect($src->confirmations)->toBe(2);
});
it('API-ресурс источника отдаёт where_found, office и confirmations', function () {
$tenant = Tenant::factory()->create();
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'К', 'dedup_key' => 'site:k.ru', 'site_url' => 'k.ru']);
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'done', 'region_code' => 24, 'competitor_id' => $comp->id, 'params' => []]);
$src = AutopodborSource::create([
'tenant_id' => $tenant->id,
'competitor_id' => $comp->id,
'study_run_id' => $run->id,
'signal_type' => 'call',
'identifier' => '73912920000',
'phone_kind' => 'real',
'phone_type' => 'city',
'provenance_url' => 'https://k.ru',
'provenance_label' => 'в коде сайта',
'dedup_key' => 'call:73912920000',
'where_found' => [['label' => 'в коде сайта', 'url' => 'https://k.ru'], ['label' => '2ГИС', 'url' => 'https://2gis.ru/firm/1']],
'office' => 'Единая справочная',
'confirmations' => 2,
]);
$arr = (new SourceResource($src))->toArray(request());
expect($arr['where_found'])->toHaveCount(2);
expect($arr['office'])->toBe('Единая справочная');
expect($arr['confirmations'])->toBe(2);
});