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

32 lines
1.0 KiB
PHP
Raw Normal View History

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