70 lines
4.8 KiB
PHP
70 lines
4.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
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 App\Services\Autopodbor\Agent\Dto\FindCompetitorsRequest;
|
||
|
|
use App\Services\Autopodbor\Agent\Dto\FindCompetitorsResult;
|
||
|
|
use App\Services\Autopodbor\Agent\Dto\ResolveByNameRequest;
|
||
|
|
use App\Services\Autopodbor\Agent\Dto\ResolveByNameResult;
|
||
|
|
use App\Services\Autopodbor\Agent\Dto\StudyCompetitorRequest;
|
||
|
|
use App\Services\Autopodbor\Agent\Dto\StudyCompetitorResult;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Tests\Concerns\SharesSupplierPdo;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Сквозная проверка хранения строк «глубокого сбора» через настоящую джобу: строки в форме
|
||
|
|
* DeepStudyCollector → RunAutopodborStudyJob → AutopodborDedup → AutopodborSource. Главное —
|
||
|
|
* два сайта-близнеца сохраняются как ДВЕ отдельные записи (не сливаются в БД). Закрывает брешь
|
||
|
|
* «флаг-ON через реальную джобу не покрыт тестом» без похода в живые сервисы (агент заглушён).
|
||
|
|
*/
|
||
|
|
it('строки глубокого сбора доходят до хранения; сайты-близнецы — две записи (не слиты)', function () {
|
||
|
|
// Заглушка агента отдаёт ровно то, что выдаёт DeepStudyCollector: два сайта-близнеца + один номер.
|
||
|
|
$stub = new class implements CompetitorAgent
|
||
|
|
{
|
||
|
|
public function findCompetitors(FindCompetitorsRequest $r): FindCompetitorsResult
|
||
|
|
{
|
||
|
|
throw new LogicException('n/a');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function resolveByName(ResolveByNameRequest $r): ResolveByNameResult
|
||
|
|
{
|
||
|
|
throw new LogicException('n/a');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function studyCompetitor(StudyCompetitorRequest $r): StudyCompetitorResult
|
||
|
|
{
|
||
|
|
return new StudyCompetitorResult([
|
||
|
|
['signal_type' => 'site', 'identifier' => 'kraslombard24.ru', 'phone_kind' => null, 'phone_type' => null, 'provenance_url' => 'https://kraslombard24.ru/', 'provenance_label' => 'сайт конкурента', 'where_found' => [['label' => 'сайт конкурента', 'url' => 'https://kraslombard24.ru/']], 'office' => null, 'confirmations' => 1],
|
||
|
|
['signal_type' => 'site', 'identifier' => 'красломбард.рф', 'phone_kind' => null, 'phone_type' => null, 'provenance_url' => 'https://красломбард.рф/', 'provenance_label' => 'сайт конкурента', 'where_found' => [['label' => 'сайт конкурента', 'url' => 'https://красломбард.рф/']], 'office' => null, 'confirmations' => 1],
|
||
|
|
['signal_type' => 'call', 'identifier' => '73912920000', 'phone_kind' => 'real', 'phone_type' => 'city', 'provenance_url' => null, 'provenance_label' => 'в коде сайта', 'where_found' => [['label' => 'в коде сайта', 'url' => null]], 'office' => null, 'confirmations' => 1],
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
app()->instance(CompetitorAgent::class, $stub);
|
||
|
|
|
||
|
|
$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']);
|
||
|
|
$searchRun = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 29, 'params' => []]);
|
||
|
|
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $searchRun->id, 'name' => 'КрасЛомбард', 'dedup_key' => 'site:kraslombard24.ru', 'site_url' => 'kraslombard24.ru']);
|
||
|
|
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'queued', 'region_code' => 29, 'competitor_id' => $comp->id, 'params' => []]);
|
||
|
|
|
||
|
|
app()->call([new RunAutopodborStudyJob($run->id), 'handle']);
|
||
|
|
|
||
|
|
$sites = AutopodborSource::where('competitor_id', $comp->id)->where('signal_type', 'site')->pluck('identifier')->all();
|
||
|
|
|
||
|
|
expect($run->fresh()->status)->toBe('done')
|
||
|
|
->and(count($sites))->toBe(2) // близнецы — ДВЕ записи, не слиты
|
||
|
|
->and($sites)->toContain('kraslombard24.ru')
|
||
|
|
->and($sites)->toContain('красломбард.рф')
|
||
|
|
->and(AutopodborSource::where('competitor_id', $comp->id)->where('signal_type', 'call')->where('identifier', '73912920000')->exists())->toBeTrue();
|
||
|
|
});
|