fix: captain talking over support agent (#13673)

This commit is contained in:
Aakash Bakhle
2026-03-03 16:13:34 +05:30
committed by GitHub
parent 89da4a2292
commit 374d2258c7
7 changed files with 151 additions and 4 deletions

View File

@@ -23,4 +23,69 @@ RSpec.describe Message do
expect(conversation.first_reply_created_at).not_to be_nil
expect(conversation.waiting_since).to be_nil
end
describe '#mark_pending_conversation_as_open_for_human_response' do
let(:conversation) { create(:conversation, status: :pending) }
let(:captain_assistant) { create(:captain_assistant, account: conversation.account) }
let(:auto_open_activity_content) { I18n.t('conversations.activity.captain.auto_opened_after_agent_reply', locale: conversation.account.locale) }
before do
create(:captain_inbox, inbox: conversation.inbox, captain_assistant: captain_assistant)
end
it 'marks the conversation open when a human sends a public outgoing message' do
create(:message, message_type: :outgoing, conversation: conversation)
expect(conversation.reload.open?).to be true
end
it 'creates an activity message when a human sends a public outgoing message' do
expect do
create(:message, message_type: :outgoing, conversation: conversation)
end.to have_enqueued_job(Conversations::ActivityMessageJob).with(
conversation,
{
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: :activity,
content: auto_open_activity_content
}
)
end
it 'creates an activity message for external echo replies' do
message = build(
:message,
message_type: :outgoing,
conversation: conversation,
content_attributes: { external_echo: true }
)
message.sender = nil
expect do
message.save!
end.to have_enqueued_job(Conversations::ActivityMessageJob).with(
conversation,
{
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: :activity,
content: auto_open_activity_content
}
)
end
it 'does not mark the conversation open for private outgoing messages' do
create(:message, message_type: :outgoing, conversation: conversation, private: true)
expect(conversation.reload.pending?).to be true
end
it 'does not mark the conversation open for bot outgoing messages' do
agent_bot = create(:agent_bot, account: conversation.account)
create(:message, message_type: :outgoing, conversation: conversation, sender: agent_bot)
expect(conversation.reload.pending?).to be true
end
end
end