Files
portal/app/tests/Unit/External/JivoLivenessProbeTest.php
T
Дмитрий 41fb1e9d02 feat(external): JivoLivenessProbe — живость чата
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 08:09:56 +03:00

32 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\External\JivoLivenessProbe;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
uses(TestCase::class); // нужен booted-app: config()/Http::fake()
beforeEach(function () {
config()->set('services.jivosite.widget_id', 'ABC123');
config()->set('services.jivosite.widget_url_template', 'https://code.jivo.ru/widget/{id}');
});
it('зелёный при 200 на виджет-скрипт', function () {
Http::fake(['code.jivo.ru/widget/ABC123' => Http::response('/* jivo */', 200)]);
$r = (new JivoLivenessProbe)->check();
expect($r->serviceKey)->toBe('jivosite');
expect($r->light)->toBe('green');
});
it('красный при 404', function () {
Http::fake(['code.jivo.ru/widget/ABC123' => Http::response('', 404)]);
expect((new JivoLivenessProbe)->check()->light)->toBe('red');
});
it('серый, когда widget_id не задан', function () {
config()->set('services.jivosite.widget_id', '');
expect((new JivoLivenessProbe)->check()->light)->toBe('grey');
});