Files
portal/app/tests/Unit/External/AitunnelBalanceProviderTest.php
T

38 lines
1.4 KiB
PHP
Raw Normal View History

<?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();
});