feat(external): keyso — проба живости (зависимость поиска клиентов, 13-й ключ)

This commit is contained in:
Дмитрий
2026-07-16 17:03:47 +03:00
parent c1f46c0cc5
commit d4b466cf75
7 changed files with 92 additions and 10 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
use App\Services\External\KeysoLivenessProbe;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
uses(TestCase::class);
beforeEach(fn () => config()->set('services.keyso.base_url', 'https://api.keys.so'));
it('зелёный при 200', function () {
Http::fake(['api.keys.so/*' => Http::response('ok', 200)]);
expect((new KeysoLivenessProbe)->check()->light)->toBe('green');
});
it('зелёный при 404 (хост достучались — keys.so жив)', function () {
Http::fake(['api.keys.so/*' => Http::response('Not Found', 404)]);
expect((new KeysoLivenessProbe)->check()->light)->toBe('green');
});
it('красный при 5xx и при обрыве', function () {
Http::fake(['api.keys.so/*' => Http::response('err', 503)]);
expect((new KeysoLivenessProbe)->check()->light)->toBe('red');
Http::fake(fn () => throw new RuntimeException('down'));
expect((new KeysoLivenessProbe)->check()->light)->toBe('red');
});
it('серый, когда base_url пуст', function () {
config()->set('services.keyso.base_url', '');
expect((new KeysoLivenessProbe)->check()->light)->toBe('grey');
});
it('serviceKey = keyso', function () {
expect((new KeysoLivenessProbe)->serviceKey())->toBe('keyso');
});