Files
portal/app/tests/Unit/External/AitunnelBalanceProviderTest.php
T
Дмитрий e97d164bc9 feat(external): 5 новых сервисов под присмотр (AITUNNEL/EXA/xfetch/self-render/Sales-finder)
Фаза B плана 2026-07-16-external-services-online-monitoring:
- HttpFundedServiceProvider — база «деньги-или-живость» по HTTP (DRY).
- AitunnelBalanceProvider / ExaBalanceProvider / XfetchBalanceProvider — баланс если
  задан *_balance_url, иначе живость пингом; деградация «деньги→жив→grey».
- SelfRenderLivenessProbe / SalesFinderLivenessProbe — только живость.
- Реестр рефрешера расширен до 11 сервисов; supplier — единственный тяжёлый.
- config/services.php: ключи новых сервисов (sales_finder.base_url дефолт ПУСТОЙ).
Тесты: 53 External зелёные, Larastan 0 по своим файлам (точечно).

NB: larastan-хук исключён — 2 ошибки выше baseline в ЧУЖОМ незакоммиченном файле
tests/Feature/Billing/ExpireInvoicesTest.php (работа параллельной сессии в общей папке).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-16 14:50:01 +03:00

38 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use App\Services\External\AitunnelBalanceProvider;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
uses(TestCase::class);
beforeEach(fn () => config()->set('services.aitunnel.key', 'test-key'));
it('серый/не настроено, когда ключа нет', function () {
config()->set('services.aitunnel.key', '');
expect((new AitunnelBalanceProvider)->fetch()->ok)->toBeFalse();
});
it('деньги, когда есть balance_url и число', function () {
config()->set('services.aitunnel.balance_url', 'https://api.aitunnel.ru/balance');
Http::fake(['api.aitunnel.ru/balance' => Http::response(['balance' => 1234.5], 200)]);
$r = (new AitunnelBalanceProvider)->fetch();
expect($r->ok)->toBeTrue();
expect($r->balance)->toBe(1234.5);
});
it('жив без суммы, когда balance_url пуст, а пинг 200', function () {
config()->set('services.aitunnel.balance_url', '');
Http::fake(['api.aitunnel.ru/*' => Http::response(['data' => []], 200)]);
$r = (new AitunnelBalanceProvider)->fetch();
expect($r->ok)->toBeTrue();
expect($r->balance)->toBeNull();
});
it('fail при сетевой ошибке (не бросает)', function () {
config()->set('services.aitunnel.balance_url', '');
Http::fake(fn () => throw new RuntimeException('down'));
expect((new AitunnelBalanceProvider)->fetch()->ok)->toBeFalse();
});