49 lines
2.6 KiB
PHP
49 lines
2.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Jobs\Bot\ProcessChatMessageJob;
|
||
|
|
use App\Mail\BotContactRequestMail;
|
||
|
|
use App\Models\BotDialog;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Illuminate\Support\Facades\Mail;
|
||
|
|
|
||
|
|
uses(RefreshDatabase::class);
|
||
|
|
|
||
|
|
it('в письме владельцу — вся переписка и откуда клиент', function () {
|
||
|
|
Mail::fake();
|
||
|
|
config(['services.support.email' => 'support@liderra.ru']);
|
||
|
|
$chat = str_repeat('a', 32);
|
||
|
|
|
||
|
|
// Длинный разговор: 13 реплик — старый лимит в 8 их бы обрезал.
|
||
|
|
for ($i = 1; $i <= 6; $i++) {
|
||
|
|
BotDialog::create(['chat_id' => $chat, 'direction' => 'in', 'message' => "вопрос {$i}", 'source' => 'portal', 'user_id' => 42, 'created_at' => now()]);
|
||
|
|
BotDialog::create(['chat_id' => $chat, 'direction' => 'out', 'message' => "ответ {$i}", 'created_at' => now()]);
|
||
|
|
}
|
||
|
|
BotDialog::create(['chat_id' => $chat, 'direction' => 'out', 'message' => 'Оставьте номер телефона, и специалист свяжется.', 'created_at' => now()]);
|
||
|
|
$in = BotDialog::create(['chat_id' => $chat, 'direction' => 'in', 'message' => '+7 999 000-11-22', 'source' => 'portal', 'user_id' => 42, 'created_at' => now()]);
|
||
|
|
|
||
|
|
(new ProcessChatMessageJob($chat, (int) $in->id, '+7 999 000-11-22'))->handle();
|
||
|
|
|
||
|
|
Mail::assertQueued(BotContactRequestMail::class, function (BotContactRequestMail $mail) {
|
||
|
|
return count($mail->transcript) >= 13
|
||
|
|
&& str_contains($mail->transcript[0], 'вопрос 1')
|
||
|
|
&& $mail->source === 'portal'
|
||
|
|
&& $mail->userId === 42;
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
it('письмо про гостя с лендинга помечено как гость', function () {
|
||
|
|
Mail::fake();
|
||
|
|
config(['services.support.email' => 'support@liderra.ru']);
|
||
|
|
$chat = str_repeat('b', 32);
|
||
|
|
|
||
|
|
BotDialog::create(['chat_id' => $chat, 'direction' => 'in', 'message' => 'а вы вообще законно работаете?', 'source' => 'landing', 'user_id' => null, 'created_at' => now()]);
|
||
|
|
BotDialog::create(['chat_id' => $chat, 'direction' => 'out', 'message' => 'Оставьте номер телефона, и специалист свяжется.', 'created_at' => now()]);
|
||
|
|
$in = BotDialog::create(['chat_id' => $chat, 'direction' => 'in', 'message' => '89990001122', 'source' => 'landing', 'user_id' => null, 'created_at' => now()]);
|
||
|
|
|
||
|
|
(new ProcessChatMessageJob($chat, (int) $in->id, '89990001122'))->handle();
|
||
|
|
|
||
|
|
Mail::assertQueued(BotContactRequestMail::class, fn (BotContactRequestMail $mail) => $mail->source === 'landing' && $mail->userId === null);
|
||
|
|
});
|