2026-07-02 20:37:47 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
it('bot_dialogs принимает запись входа и выхода', function () {
|
|
|
|
|
DB::table('bot_dialogs')->insert([
|
2026-07-13 06:45:54 +03:00
|
|
|
'chat_id' => 'chat-1',
|
2026-07-02 20:37:47 +03:00
|
|
|
'direction' => 'in',
|
|
|
|
|
'message' => 'что такое проект?',
|
|
|
|
|
'created_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
DB::table('bot_dialogs')->insert([
|
2026-07-13 06:45:54 +03:00
|
|
|
'chat_id' => 'chat-1',
|
2026-07-02 20:37:47 +03:00
|
|
|
'direction' => 'out',
|
|
|
|
|
'message' => 'Проект — это…',
|
|
|
|
|
'matched_chunks' => json_encode([1, 2]),
|
|
|
|
|
'latency_ms' => 2100,
|
|
|
|
|
'escalated' => false,
|
|
|
|
|
'created_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-07-13 06:45:54 +03:00
|
|
|
expect(DB::table('bot_dialogs')->where('chat_id', 'chat-1')->count())->toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('журнал разговоров хранит номер разговора, откуда пришёл и кто клиент', function () {
|
|
|
|
|
$columns = DB::select("
|
|
|
|
|
SELECT column_name FROM information_schema.columns
|
|
|
|
|
WHERE table_name = 'bot_dialogs'
|
|
|
|
|
");
|
|
|
|
|
$names = array_map(fn ($c) => $c->column_name, $columns);
|
|
|
|
|
|
|
|
|
|
expect($names)->toContain('chat_id')
|
|
|
|
|
->and($names)->toContain('source')
|
|
|
|
|
->and($names)->toContain('user_id')
|
|
|
|
|
->and($names)->toContain('ip')
|
|
|
|
|
->and($names)->not->toContain('jivo_chat_id');
|
2026-07-02 20:37:47 +03:00
|
|
|
});
|