46 lines
1.9 KiB
PHP
46 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Services\Autopodbor\CompetitorElements;
|
||
|
|
|
||
|
|
it('normalize тримит, выкидывает пустые строки и пустые элементы', function () {
|
||
|
|
$in = [
|
||
|
|
['name' => ' Нанжуль ', 'sites' => [' nanzhul.ru ', ''], 'cards' => ['https://2gis.ru/x/firm/1']],
|
||
|
|
['name' => '', 'sites' => [], 'cards' => []], // пустой — отбросить
|
||
|
|
['name' => 'Плодово', 'sites' => [], 'cards' => []], // только имя — оставить
|
||
|
|
'мусор', // не массив — пропустить
|
||
|
|
];
|
||
|
|
|
||
|
|
expect(CompetitorElements::normalize($in))->toBe([
|
||
|
|
['name' => 'Нанжуль', 'sites' => ['nanzhul.ru'], 'cards' => ['https://2gis.ru/x/firm/1']],
|
||
|
|
['name' => 'Плодово', 'sites' => [], 'cards' => []],
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('normalize на не-массиве отдаёт пустой список', function () {
|
||
|
|
expect(CompetitorElements::normalize(null))->toBe([])
|
||
|
|
->and(CompetitorElements::normalize('строка'))->toBe([]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('deriveLegacy: site_url = первый сайт, directory_urls = все карточки уникальные', function () {
|
||
|
|
$elements = [
|
||
|
|
['name' => 'A', 'sites' => ['a.ru'], 'cards' => ['card1', 'card2']],
|
||
|
|
['name' => 'B', 'sites' => ['b.ru'], 'cards' => ['card2', 'card3']],
|
||
|
|
];
|
||
|
|
|
||
|
|
expect(CompetitorElements::deriveLegacy($elements))->toBe([
|
||
|
|
'site_url' => 'a.ru',
|
||
|
|
'directory_urls' => ['card1', 'card2', 'card3'],
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('deriveLegacy без сайтов даёт site_url = null', function () {
|
||
|
|
$elements = [['name' => 'A', 'sites' => [], 'cards' => ['c1']]];
|
||
|
|
|
||
|
|
expect(CompetitorElements::deriveLegacy($elements))->toBe([
|
||
|
|
'site_url' => null,
|
||
|
|
'directory_urls' => ['c1'],
|
||
|
|
]);
|
||
|
|
});
|