feat(external): CaptchaLivenessProbe — статус капчи
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\External;
|
||||
|
||||
/**
|
||||
* Живость капчи (Yandex SmartCaptcha). Оплата за вызов → активно НЕ пингуем.
|
||||
* driver=null/'' (выключена) → grey «выключена»; иначе → green «включена».
|
||||
*/
|
||||
class CaptchaLivenessProbe implements LivenessProbe
|
||||
{
|
||||
public function serviceKey(): string
|
||||
{
|
||||
return 'captcha';
|
||||
}
|
||||
|
||||
public function check(): LivenessReading
|
||||
{
|
||||
$driver = (string) config('services.captcha.driver', 'null');
|
||||
if ($driver === '' || $driver === 'null') {
|
||||
return LivenessReading::unknown('captcha', 'выключена');
|
||||
}
|
||||
|
||||
return LivenessReading::alive('captcha', 'включена');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\External\CaptchaLivenessProbe;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class); // нужен booted-app: config()
|
||||
|
||||
it('серый «выключена», когда driver=null', function () {
|
||||
config()->set('services.captcha.driver', 'null');
|
||||
$r = (new CaptchaLivenessProbe)->check();
|
||||
expect($r->serviceKey)->toBe('captcha');
|
||||
expect($r->light)->toBe('grey');
|
||||
expect($r->detail)->toContain('выключена');
|
||||
});
|
||||
|
||||
it('зелёный, когда капча включена', function () {
|
||||
config()->set('services.captcha.driver', 'yandex');
|
||||
expect((new CaptchaLivenessProbe)->check()->light)->toBe('green');
|
||||
});
|
||||
Reference in New Issue
Block a user