Files
portal/app/tests/Unit/Autopodbor/Search/SearchResultsParserTest.php
T

40 lines
1.7 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Services\Autopodbor\Agent\Search\SearchResultsParser;
// autopodborFixture() — глобальный хелпер из tests/Pest.php.
it('вытаскивает фирмы из реальной выдачи 2ГИС (ссылка + имя-подсказка)', function () {
$items = (new SearchResultsParser)->twoGis(autopodborFixture('2gis-search-kraslombard.html'));
expect(count($items))->toBe(4);
foreach ($items as $it) {
expect($it['path'])->toMatch('#^/[a-z0-9_-]+/firm/\d+$#');
expect($it['name'])->toBe('КрасЛомбард');
}
// ссылки уникальны
$paths = array_column($items, 'path');
expect($paths)->toBe(array_values(array_unique($paths)));
});
it('вытаскивает организации из реальной выдачи Яндекса (ссылка + имя)', function () {
$items = (new SearchResultsParser)->yandex(autopodborFixture('yandex-search-kraslombard.html'));
expect(count($items))->toBe(5);
$names = array_column($items, 'name');
expect($names)->toContain('КрасЛомбард')->toContain('Сибломбард')->toContain('Енисейская скупка золота');
foreach ($items as $it) {
expect($it['url'])->toMatch('#^/maps/org/[a-z0-9_-]+/\d+$#');
}
$urls = array_column($items, 'url');
expect($urls)->toBe(array_values(array_unique($urls)));
});
it('пустая/неподходящая страница → пустой список', function () {
$p = new SearchResultsParser;
expect($p->twoGis('<html><body>ничего</body></html>'))->toBe([]);
expect($p->yandex('<html><body>ничего</body></html>'))->toBe([]);
});