Files
portal/app/tests/Unit/Autopodbor/Extract/SourceAggregatorTest.php
T

51 lines
3.3 KiB
PHP
Raw Normal View History

<?php
use App\Services\Autopodbor\Agent\Extract\SourceAggregator;
it('сливает один номер из разных мест в один источник с двумя где-нашли', function () {
$out = (new SourceAggregator)->aggregate([
['number' => '73912920000', 'kind' => 'code', 'label' => 'в коде сайта', 'url' => 'https://k.ru/', 'office' => null, 'tracker' => true],
['number' => '73912920000', 'kind' => 'contacts', 'label' => 'страница «Контакты»', 'url' => 'https://k.ru/c', 'office' => 'Единая справочная', 'tracker' => true],
]);
expect($out)->toHaveCount(1);
expect($out[0]->identifier)->toBe('73912920000');
expect($out[0]->confirmations())->toBe(2);
expect($out[0]->office)->toBe('Единая справочная');
expect($out[0]->phoneKind)->toBe('real');
expect($out[0]->phoneType)->toBe('city');
});
it('скрывает пул ротации и помечает видимый подменный', function () {
$out = (new SourceAggregator)->aggregate([
['number' => '79012414545', 'kind' => 'displayed', 'label' => 'Callibri (на сайте)', 'url' => 'https://k.ru/', 'office' => null, 'tracker' => true],
['number' => '70489624563', 'kind' => 'pool', 'label' => 'пул', 'url' => null, 'office' => null, 'tracker' => true],
]);
expect($out)->toHaveCount(1); // пул скрыт
expect($out[0]->identifier)->toBe('79012414545');
expect($out[0]->phoneKind)->toBe('substitute');
});
it('номер «требует проверки» не отбрасывает, помечает phoneKind=uncertain и не угадывает тип', function () {
$out = (new SourceAggregator)->aggregate([
['number' => '2713333', 'kind' => 'uncertain', 'label' => 'локальный номер — код города не определён', 'url' => 'https://k.ru/', 'office' => null, 'tracker' => false],
]);
expect($out)->toHaveCount(1); // НЕ потерян
expect($out[0]->identifier)->toBe('2713333');
expect($out[0]->phoneKind)->toBe('uncertain');
expect($out[0]->phoneType)->toBeNull(); // тип не выдумываем
});
it('сортирует: больше подтверждений — выше, подменные — в самый низ', function () {
$out = (new SourceAggregator)->aggregate([
// 1 подтверждение
['number' => '73912500000', 'kind' => 'contacts', 'label' => 'контакты', 'url' => null, 'office' => null, 'tracker' => true],
// 2 подтверждения
['number' => '73912920000', 'kind' => 'code', 'label' => 'код', 'url' => null, 'office' => null, 'tracker' => true],
['number' => '73912920000', 'kind' => 'contacts', 'label' => 'контакты', 'url' => null, 'office' => null, 'tracker' => true],
// подменный
['number' => '79012414545', 'kind' => 'displayed', 'label' => 'Callibri', 'url' => null, 'office' => null, 'tracker' => true],
]);
expect(array_map(fn ($s) => $s->identifier, $out))
->toBe(['73912920000', '73912500000', '79012414545']);
});