6be827aaa3
EXA (api.exa.ai) за Cloudflare блокирует российские IP боевого. Прямой пинг с прода дал бы ложное «не отвечает» и ложный алерт «EXA упал» из суточной джобы. Теперь ExaBalanceProvider ходит через services.exa.proxy (тот же тоннель, что ExaSiteFinder). HttpFundedServiceProvider получил хук httpOptions() (Guzzle-опции, по умолчанию нет). Тест: 4/4 ExaBalanceProviderTest, Larastan 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
39 lines
1.5 KiB
PHP
39 lines
1.5 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
use App\Services\External\ExaBalanceProvider;
|
||
use Illuminate\Support\Facades\Http;
|
||
use Tests\TestCase;
|
||
|
||
uses(TestCase::class);
|
||
|
||
beforeEach(fn () => config()->set('services.exa.key', 'test-key'));
|
||
|
||
it('не настроено, когда ключа нет', function () {
|
||
config()->set('services.exa.key', '');
|
||
expect((new ExaBalanceProvider)->fetch()->ok)->toBeFalse();
|
||
});
|
||
|
||
it('жив без суммы, когда пинг 200', function () {
|
||
config()->set('services.exa.balance_url', '');
|
||
config()->set('services.exa.base_url', 'https://api.exa.ai');
|
||
Http::fake(['api.exa.ai*' => Http::response([], 200)]);
|
||
$r = (new ExaBalanceProvider)->fetch();
|
||
expect($r->ok)->toBeTrue();
|
||
expect($r->balance)->toBeNull();
|
||
});
|
||
|
||
it('деньги при balance_url с числом', function () {
|
||
config()->set('services.exa.balance_url', 'https://api.exa.ai/billing/balance');
|
||
Http::fake(['api.exa.ai/billing/balance' => Http::response(['balance' => 40.0], 200)]);
|
||
expect((new ExaBalanceProvider)->fetch()->balance)->toBe(40.0);
|
||
});
|
||
|
||
it('с настроенным proxy поток не ломается (EXA за Cloudflare ходит через тоннель)', function () {
|
||
config()->set('services.exa.balance_url', '');
|
||
config()->set('services.exa.base_url', 'https://api.exa.ai');
|
||
config()->set('services.exa.proxy', 'socks5h://127.0.0.1:10808');
|
||
Http::fake(['api.exa.ai*' => Http::response([], 200)]);
|
||
expect((new ExaBalanceProvider)->fetch()->ok)->toBeTrue();
|
||
});
|