Files
portal/app/tests/Unit/Autopodbor/Fetch/XfetchClientTest.php
T

32 lines
1.1 KiB
PHP
Raw Normal View History

<?php
use App\Services\Autopodbor\Agent\Fetch\XfetchClient;
use Illuminate\Support\Facades\Http;
it('декодирует HTML из base64-ответа xfetch', function () {
Http::fake([
'xf4.ru/*' => Http::response([
'status_code' => 200,
'response_body_base64' => base64_encode('<html>привет</html>'),
]),
]);
$client = new XfetchClient('test-key');
expect($client->html('https://2gis.ru/x'))->toBe('<html>привет</html>');
});
it('без ключа не ходит в сеть и возвращает пусто', function () {
Http::fake();
$client = new XfetchClient(null);
expect($client->html('https://2gis.ru/x'))->toBe('');
Http::assertNothingSent();
});
it('шлёт url, api_key и render:true на endpoint xfetch', function () {
Http::fake(['xf4.ru/*' => Http::response(['response_body_base64' => base64_encode('ok')])]);
(new XfetchClient('k123'))->html('https://2gis.ru/y');
Http::assertSent(fn ($r) => $r->url() === 'https://xf4.ru/fetch'
&& $r['url'] === 'https://2gis.ru/y'
&& $r['api_key'] === 'k123'
&& $r['render'] === true);
});