50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Services\Autopodbor\Agent\Phone\DaDataValidityLayer;
|
||
|
|
use Illuminate\Http\Client\ConnectionException;
|
||
|
|
use Illuminate\Support\Facades\Http;
|
||
|
|
|
||
|
|
beforeEach(function (): void {
|
||
|
|
config(['services.dadata.daily_cap_rub' => 10000]); // бюджет открыт
|
||
|
|
});
|
||
|
|
|
||
|
|
it('qc=2 (мусор) → номер невалиден (выкидываем)', function (): void {
|
||
|
|
Http::fake(['cleaner.dadata.ru/*' => Http::response([['qc' => 2]], 200)]);
|
||
|
|
|
||
|
|
expect(app(DaDataValidityLayer::class)->isValid('79215555123'))->toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('qc=7 (иностранец) → номер невалиден', function (): void {
|
||
|
|
Http::fake(['cleaner.dadata.ru/*' => Http::response([['qc' => 7]], 200)]);
|
||
|
|
|
||
|
|
expect(app(DaDataValidityLayer::class)->isValid('79215555123'))->toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('qc=0 (годный) → валиден', function (): void {
|
||
|
|
Http::fake(['cleaner.dadata.ru/*' => Http::response([['qc' => 0]], 200)]);
|
||
|
|
|
||
|
|
expect(app(DaDataValidityLayer::class)->isValid('79215555123'))->toBeTrue();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('qc=1 (неоднозначный) → оставляем (не режем по сомнению)', function (): void {
|
||
|
|
Http::fake(['cleaner.dadata.ru/*' => Http::response([['qc' => 1]], 200)]);
|
||
|
|
|
||
|
|
expect(app(DaDataValidityLayer::class)->isValid('79215555123'))->toBeTrue();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('бюджет исчерпан → не тратим и не режем, ДаДату не дёргаем', function (): void {
|
||
|
|
config(['services.dadata.daily_cap_rub' => 0]); // касса закрыта
|
||
|
|
Http::fake();
|
||
|
|
|
||
|
|
expect(app(DaDataValidityLayer::class)->isValid('79215555123'))->toBeTrue();
|
||
|
|
Http::assertNothingSent();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('сбой ДаДаты (сеть) → не роняем и не режем', function (): void {
|
||
|
|
Http::fake(fn () => throw new ConnectionException('timeout'));
|
||
|
|
|
||
|
|
expect(app(DaDataValidityLayer::class)->isValid('79215555123'))->toBeTrue();
|
||
|
|
});
|