Files
portal/app/tests/Unit/Autopodbor/FakeCompetitorAgentTest.php
T

38 lines
1.8 KiB
PHP
Raw Normal View History

<?php
use App\Services\Autopodbor\Agent\CompetitorAgent;
use App\Services\Autopodbor\Agent\Dto\{FindCompetitorsRequest, StudyCompetitorRequest, ResolveByNameRequest};
it('заглушка резолвится через контейнер и отдаёт данные', function () {
$agent = app(CompetitorAgent::class);
expect($agent)->toBeInstanceOf(\App\Services\Autopodbor\Agent\FakeCompetitorAgent::class);
$found = $agent->findCompetitors(new FindCompetitorsRequest(16, ['okna.ru'], [], true, 15));
expect(count($found->competitors))->toBeGreaterThan(0)
->and($found->competitors[0])->toHaveKeys(['name','relevance_pct','site_url']);
$study = $agent->studyCompetitor(new StudyCompetitorRequest(['name'=>'Окна Комфорт','site_url'=>'okna-komfort-kzn.ru'], 16));
expect($study->sources)->not->toBeEmpty()
->and($study->sources[0])->toHaveKeys(['signal_type','identifier','provenance_url']);
$resolve = $agent->resolveByName(new ResolveByNameRequest('Окна Комфорт', 16));
expect($resolve->candidates)->not->toBeEmpty();
});
it('заглушка отдаёт полный набор типов телефонов вкл. 8-800 (tollfree)', function () {
$agent = app(CompetitorAgent::class);
$study = $agent->studyCompetitor(new StudyCompetitorRequest(['name'=>'Окна Комфорт','site_url'=>'okna-komfort-kzn.ru'], 16));
$phoneTypes = collect($study->sources)
->where('signal_type', 'call')
->pluck('phone_type')
->unique()
->values()
->all();
// Тупой клиент должен увидеть все три типа номера: городской, мобильный, 8-800.
expect($phoneTypes)->toContain('city')
->and($phoneTypes)->toContain('mobile')
->and($phoneTypes)->toContain('tollfree');
});