mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
fix: Include waiting on agent conversations to unattended view (#7667)
Updating the `unattended` tab to include conversations where the customer responded and is awaiting an agent's response. Previously it showed only the conversations where the first response was pending. Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -95,56 +95,81 @@ RSpec.describe Message do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Check if message is a valid first reply' do
|
||||
it 'is valid if it is outgoing' do
|
||||
outgoing_message = create(:message, message_type: :outgoing)
|
||||
expect(outgoing_message.valid_first_reply?).to be true
|
||||
describe 'message create event' do
|
||||
let(:conversation) { create(:conversation) }
|
||||
|
||||
it 'updates the conversation first reply created at if it is the first outgoing message' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
outgoing_message = create(:message, message_type: :outgoing, conversation: conversation)
|
||||
|
||||
expect(conversation.first_reply_created_at).to eq outgoing_message.created_at
|
||||
expect(conversation.waiting_since).to be_nil
|
||||
end
|
||||
|
||||
it 'is invalid if it is not outgoing' do
|
||||
incoming_message = create(:message, message_type: :incoming)
|
||||
expect(incoming_message.valid_first_reply?).to be false
|
||||
it 'does not update the conversation first reply created at if the message is incoming' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
activity_message = create(:message, message_type: :activity)
|
||||
expect(activity_message.valid_first_reply?).to be false
|
||||
create(:message, message_type: :incoming, conversation: conversation)
|
||||
|
||||
template_message = create(:message, message_type: :template)
|
||||
expect(template_message.valid_first_reply?).to be false
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
end
|
||||
|
||||
it 'is invalid if it is outgoing but private' do
|
||||
conversation = create(:conversation)
|
||||
it 'does not update the conversation first reply created at if the message is template' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
outgoing_message = create(:message, message_type: :outgoing, conversation: conversation, private: true)
|
||||
expect(outgoing_message.valid_first_reply?).to be false
|
||||
create(:message, message_type: :template, conversation: conversation)
|
||||
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
end
|
||||
|
||||
it 'does not update the conversation first reply created at if the message is activity' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
create(:message, message_type: :activity, conversation: conversation)
|
||||
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
end
|
||||
|
||||
it 'does not update the conversation first reply created at if the message is a private message' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
create(:message, message_type: :outgoing, conversation: conversation, private: true)
|
||||
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
# next message should be a valid reply
|
||||
next_message = create(:message, message_type: :outgoing, conversation: conversation)
|
||||
expect(next_message.valid_first_reply?).to be true
|
||||
expect(conversation.first_reply_created_at).to eq next_message.created_at
|
||||
expect(conversation.waiting_since).to be_nil
|
||||
end
|
||||
|
||||
it 'is invalid if it is not the first reply' do
|
||||
conversation = create(:conversation)
|
||||
first_message = create(:message, message_type: :outgoing, conversation: conversation)
|
||||
expect(first_message.valid_first_reply?).to be true
|
||||
it 'does not update first reply if the message is sent as campaign' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
second_message = create(:message, message_type: :outgoing, conversation: conversation)
|
||||
expect(second_message.valid_first_reply?).to be false
|
||||
create(:message, message_type: :outgoing, conversation: conversation, additional_attributes: { campaign_id: 1 })
|
||||
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
end
|
||||
|
||||
it 'is invalid if it is sent as campaign' do
|
||||
conversation = create(:conversation)
|
||||
campaign_message = create(:message, message_type: :outgoing, conversation: conversation, additional_attributes: { campaign_id: 1 })
|
||||
expect(campaign_message.valid_first_reply?).to be false
|
||||
it 'does not update first reply if the message is sent by automation' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
|
||||
second_message = create(:message, message_type: :outgoing, conversation: conversation)
|
||||
expect(second_message.valid_first_reply?).to be true
|
||||
end
|
||||
create(:message, message_type: :outgoing, conversation: conversation, content_attributes: { automation_rule_id: 1 })
|
||||
|
||||
it 'is invalid if it is sent by automation' do
|
||||
conversation = create(:conversation)
|
||||
automation_message = create(:message, message_type: :outgoing, conversation: conversation, content_attributes: { automation_rule_id: 1 })
|
||||
expect(automation_message.valid_first_reply?).to be false
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
expect(conversation.waiting_since).to eq conversation.created_at
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user