Http::response([[ 'qc' => 0, 'type' => 'Мобильный', 'phone' => '+7 921 555-12-34', 'provider' => 'МегаФон', 'region' => 'Санкт-Петербург и область', ]], 200)]); $out = app(CompetitorPhoneEnricher::class)->enrich(['79215551234']); expect($out)->toHaveCount(1); expect($out[0])->toMatchArray([ 'phone' => '79215551234', 'type' => 'mobile', 'region' => 'Санкт-Петербург и область', 'valid' => true, ]); }); it('qc!=0 (неоднозначный номер) → негоден', function () { Http::fake(['cleaner.dadata.ru/*' => Http::response([[ 'qc' => 3, 'type' => 'Мобильный', 'region' => 'Москва', ]], 200)]); $out = app(CompetitorPhoneEnricher::class)->enrich(['79991234567']); expect($out[0]['valid'])->toBeFalse(); }); it('тип 8-800 из DaData → tollfree', function () { Http::fake(['cleaner.dadata.ru/*' => Http::response([[ 'qc' => 0, 'type' => 'Бесплатный', 'region' => 'Россия', ]], 200)]); $out = app(CompetitorPhoneEnricher::class)->enrich(['78001234567']); expect($out[0]['type'])->toBe('tollfree'); expect($out[0]['valid'])->toBeTrue(); }); it('DaData недоступна → не роняем подбор: тип по префиксу, регион пуст, негоден', function () { Http::fake(fn () => throw new ConnectionException('timeout')); $out = app(CompetitorPhoneEnricher::class)->enrich(['78001234567', '79991112233']); expect($out)->toHaveCount(2); expect($out[0])->toMatchArray(['phone' => '78001234567', 'type' => 'tollfree', 'region' => null, 'valid' => false]); expect($out[1])->toMatchArray(['phone' => '79991112233', 'type' => 'mobile', 'region' => null, 'valid' => false]); });