feat: Add a sort option for conversations waiting for a reply from an agent (#7364)
This commit is contained in:
@@ -32,6 +32,10 @@ RSpec.describe Conversation do
|
||||
expect(conversation.display_id).to eq(1)
|
||||
end
|
||||
|
||||
it 'sets waiting since' do
|
||||
expect(conversation.waiting_since).not_to be_nil
|
||||
end
|
||||
|
||||
it 'creates a UUID for every conversation automatically' do
|
||||
uuid_pattern = /[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}$/i
|
||||
expect(conversation.uuid).to match(uuid_pattern)
|
||||
@@ -523,6 +527,7 @@ RSpec.describe Conversation do
|
||||
contact_last_seen_at: conversation.contact_last_seen_at.to_i,
|
||||
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
||||
created_at: conversation.created_at.to_i,
|
||||
waiting_since: conversation.waiting_since.to_i,
|
||||
priority: nil,
|
||||
unread_count: 0
|
||||
}
|
||||
|
||||
@@ -138,6 +138,37 @@ RSpec.describe Message do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#waiting since' do
|
||||
let(:conversation) { create(:conversation) }
|
||||
let(:agent) { create(:user, account: conversation.account) }
|
||||
let(:message) { build(:message, conversation: conversation) }
|
||||
|
||||
it 'resets the waiting_since if an agent sent a reply' do
|
||||
message.message_type = :outgoing
|
||||
message.sender = agent
|
||||
message.save!
|
||||
|
||||
expect(conversation.waiting_since).to be_nil
|
||||
end
|
||||
|
||||
it 'sets the waiting_since if there is an incoming message' do
|
||||
conversation.update(waiting_since: nil)
|
||||
message.message_type = :incoming
|
||||
message.save!
|
||||
|
||||
expect(conversation.waiting_since).not_to be_nil
|
||||
end
|
||||
|
||||
it 'does not overwrite the previous value if there are newer messages' do
|
||||
old_waiting_since = conversation.waiting_since
|
||||
message.message_type = :incoming
|
||||
message.save!
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.waiting_since).to eq old_waiting_since
|
||||
end
|
||||
end
|
||||
|
||||
context 'with webhook_data' do
|
||||
it 'contains the message attachment when attachment is present' do
|
||||
message = create(:message)
|
||||
|
||||
Reference in New Issue
Block a user