2026-07-02 20:58:24 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
use App\Services\Bot\JivoBotClient;
|
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2026-07-02 21:15:14 +03:00
|
|
|
|
use Tests\TestCase;
|
2026-07-02 20:58:24 +03:00
|
|
|
|
|
2026-07-02 21:15:14 +03:00
|
|
|
|
uses(TestCase::class);
|
2026-07-02 20:58:24 +03:00
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
|
config()->set('services.jivo_bot.outbound_url', 'https://bot.jivosite.com/webhooks/prov-1/tok-1');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('BOT_MESSAGE уходит с chat_id/client_id и текстом', function () {
|
|
|
|
|
|
Http::fake(['bot.jivosite.com/*' => Http::response(['ok' => true])]);
|
|
|
|
|
|
|
|
|
|
|
|
app(JivoBotClient::class)->sendMessage('chat-1', 'client-1', 'Проект — это…');
|
|
|
|
|
|
|
|
|
|
|
|
Http::assertSent(function ($request) {
|
|
|
|
|
|
return $request->url() === 'https://bot.jivosite.com/webhooks/prov-1/tok-1'
|
|
|
|
|
|
&& $request['event'] === 'BOT_MESSAGE'
|
|
|
|
|
|
&& $request['chat_id'] === 'chat-1'
|
|
|
|
|
|
&& $request['client_id'] === 'client-1'
|
|
|
|
|
|
&& $request['message']['type'] === 'TEXT'
|
|
|
|
|
|
&& $request['message']['text'] === 'Проект — это…';
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('INVITE_AGENT уходит без message', function () {
|
|
|
|
|
|
Http::fake(['bot.jivosite.com/*' => Http::response(['ok' => true])]);
|
|
|
|
|
|
|
|
|
|
|
|
app(JivoBotClient::class)->inviteAgent('chat-1', 'client-1');
|
|
|
|
|
|
|
|
|
|
|
|
Http::assertSent(fn ($r) => $r['event'] === 'INVITE_AGENT' && $r['chat_id'] === 'chat-1');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('пустой outbound_url (dev/CI) → ничего не шлёт и не падает', function () {
|
|
|
|
|
|
config()->set('services.jivo_bot.outbound_url', '');
|
|
|
|
|
|
Http::fake();
|
|
|
|
|
|
|
|
|
|
|
|
app(JivoBotClient::class)->sendMessage('chat-1', 'client-1', 'x');
|
|
|
|
|
|
|
|
|
|
|
|
Http::assertNothingSent();
|
|
|
|
|
|
});
|