63 lines
2.7 KiB
PHP
63 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Services\Autopodbor\Agent\ChannelA\PlaywrightYandexDirectory;
|
||
|
|
use App\Services\Autopodbor\Agent\Fetch\YandexListSource;
|
||
|
|
|
||
|
|
// После расшивки на YandexListSource оркестрация тестируема офлайн (раньше — только через сеть).
|
||
|
|
// Проверяем: URL по рубрике+городу, потолок maxQueries, слияние рубрик, дедуп по slug (парсер).
|
||
|
|
|
||
|
|
function fakeSource(array $orgsPerCall): YandexListSource
|
||
|
|
{
|
||
|
|
return new class($orgsPerCall) implements YandexListSource
|
||
|
|
{
|
||
|
|
/** @var list<array{url:string,scrolls:int}> */
|
||
|
|
public array $calls = [];
|
||
|
|
|
||
|
|
public function __construct(private array $orgsPerCall) {}
|
||
|
|
|
||
|
|
public function fetch(string $url, int $scrolls): array
|
||
|
|
{
|
||
|
|
$this->calls[] = ['url' => $url, 'scrolls' => $scrolls];
|
||
|
|
|
||
|
|
return array_shift($this->orgsPerCall) ?? [];
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
it('строит URL по рубрике+городу и сливает организации разных рубрик', function () {
|
||
|
|
$source = fakeSource([
|
||
|
|
[['name' => 'КрасЛомбард', 'id' => '1', 'href' => '/maps/org/kraslombard/1']],
|
||
|
|
[['name' => 'Корунд', 'id' => '2', 'href' => '/maps/org/korund/2']],
|
||
|
|
]);
|
||
|
|
|
||
|
|
$rows = (new PlaywrightYandexDirectory($source, scrolls: 3))->collect('Красноярск', ['ломбард', 'автозайм']);
|
||
|
|
|
||
|
|
// Две рубрики → два вызова с правильными URL и scrolls.
|
||
|
|
expect($source->calls)->toHaveCount(2)
|
||
|
|
->and($source->calls[0]['url'])->toContain('yandex.ru/maps/?text=')
|
||
|
|
->and($source->calls[0]['scrolls'])->toBe(3);
|
||
|
|
$names = array_column($rows, 'name');
|
||
|
|
expect($names)->toContain('КрасЛомбард')->toContain('Корунд');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('дедуп по slug: филиалы одной сети схлопываются', function () {
|
||
|
|
$source = fakeSource([[
|
||
|
|
['name' => 'КрасЛомбард', 'id' => '1', 'href' => '/maps/org/kraslombard/1'],
|
||
|
|
['name' => 'КрасЛомбард', 'id' => '2', 'href' => '/maps/org/kraslombard/2'],
|
||
|
|
]]);
|
||
|
|
|
||
|
|
$rows = (new PlaywrightYandexDirectory($source))->collect('Красноярск', ['ломбард']);
|
||
|
|
|
||
|
|
expect($rows)->toHaveCount(1)
|
||
|
|
->and($rows[0]['slug'])->toBe('kraslombard');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('потолок maxQueries режет число рубрик', function () {
|
||
|
|
$source = fakeSource([[], [], []]);
|
||
|
|
(new PlaywrightYandexDirectory($source, maxQueries: 2))->collect('Красноярск', ['a', 'b', 'c']);
|
||
|
|
|
||
|
|
expect($source->calls)->toHaveCount(2); // 3-я рубрика не запрашивается
|
||
|
|
});
|