Files
portal/app/tests/Feature/Services/DaData/DaDataPartyClientTest.php
T
2026-06-18 22:25:23 +03:00

55 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\DaData\DaDataPartyClient;
use Illuminate\Http\Client\Factory as HttpFactory;
it('parses a party suggestion into a result', function () {
$http = new HttpFactory;
$http->fake([
'suggestions.dadata.ru/*' => $http->response([
'suggestions' => [[
'value' => 'ООО "РОМАШКА"',
'data' => [
'kpp' => '770101001',
'ogrn' => '1027700132195',
'type' => 'LEGAL',
'address' => ['value' => 'г Москва, ул Ленина, д 1'],
],
]],
]),
]);
config()->set('services.dadata.api_key', 'test-key');
$res = (new DaDataPartyClient($http))->findByInn('7707083893');
expect($res)->not->toBeNull();
expect($res->legalName)->toBe('ООО "РОМАШКА"');
expect($res->kpp)->toBe('770101001');
expect($res->type)->toBe('LEGAL');
});
it('returns null on empty suggestions', function () {
$http = new HttpFactory;
$http->fake(['suggestions.dadata.ru/*' => $http->response(['suggestions' => []])]);
config()->set('services.dadata.api_key', 'test-key');
expect((new DaDataPartyClient($http))->findByInn('0000000000'))->toBeNull();
});
it('returns null on HTTP error (soft)', function () {
$http = new HttpFactory;
$http->fake(['suggestions.dadata.ru/*' => $http->response('boom', 500)]);
config()->set('services.dadata.api_key', 'test-key');
expect((new DaDataPartyClient($http))->findByInn('7707083893'))->toBeNull();
});
it('returns null when api key is empty', function () {
$http = new HttpFactory;
config()->set('services.dadata.api_key', '');
expect((new DaDataPartyClient($http))->findByInn('7707083893'))->toBeNull();
});