edf98d9ace
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
use App\Services\Bot\JivoBotClient;
|
||
use Illuminate\Support\Facades\Http;
|
||
use Tests\TestCase;
|
||
|
||
uses(TestCase::class);
|
||
|
||
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();
|
||
});
|