Files
portal/app/tests/Unit/External/YooKassaLivenessProbeTest.php
T
2026-07-02 07:55:42 +03:00

39 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\External\YooKassaLivenessProbe;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
uses(TestCase::class); // нужен booted-app: config()/Http::fake()
beforeEach(function () {
config()->set('services.yookassa.shop_id', '1392092');
config()->set('services.yookassa.secret_key', 'test_secret');
config()->set('services.yookassa.api_url', 'https://api.yookassa.ru/v3');
});
it('зелёный при 200 от /me', function () {
Http::fake(['api.yookassa.ru/v3/me' => Http::response(['account_id' => '1392092'], 200)]);
$r = (new YooKassaLivenessProbe)->check();
expect($r->serviceKey)->toBe('yookassa');
expect($r->light)->toBe('green');
});
it('красный при 401', function () {
Http::fake(['api.yookassa.ru/v3/me' => Http::response(['type' => 'error'], 401)]);
expect((new YooKassaLivenessProbe)->check()->light)->toBe('red');
});
it('серый, когда ключи не заданы', function () {
config()->set('services.yookassa.shop_id', '');
config()->set('services.yookassa.secret_key', '');
expect((new YooKassaLivenessProbe)->check()->light)->toBe('grey');
});
it('красный при сетевой ошибке (проба не бросает)', function () {
Http::fake(fn () => throw new RuntimeException('network down'));
expect((new YooKassaLivenessProbe)->check()->light)->toBe('red');
});