Add first_reply_created event in conversation (#4576)

This commit is contained in:
Aswin Dev P.S
2022-05-19 09:46:33 +05:30
committed by GitHub
parent 20565d09c0
commit 8538660bbd
6 changed files with 117 additions and 22 deletions

View File

@@ -0,0 +1,48 @@
require 'rails_helper'
RSpec.describe Migration::ConversationsFirstReplySchedulerJob, type: :job do
subject(:job) { described_class.perform_later }
let!(:account) { create(:account) }
let!(:inbox) { create(:inbox, account: account) }
let!(:user) { create(:user, account: account) }
it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class)
.on_queue('scheduled_jobs')
end
context 'when there is an outgoing message in conversation' do
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: user) }
let!(:message) do
create(:message, content: 'Hi', message_type: 'outgoing', account: account, inbox: inbox,
conversation: conversation)
end
it 'updates the conversation first reply with the first outgoing message created time' do
create(:message, content: 'Hello', message_type: 'outgoing', account: account, inbox: inbox,
conversation: conversation)
described_class.perform_now(account)
conversation.reload
expect(conversation.messages.count).to eq 2
expect(conversation.first_reply_created_at.to_i).to eq message.created_at.to_i
end
end
context 'when there is no outgoing message in conversation' do
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: user) }
it 'updates the conversation first reply with nil' do
create(:message, content: 'Hello', message_type: 'incoming', account: account, inbox: inbox,
conversation: conversation)
described_class.perform_now(account)
conversation.reload
expect(conversation.messages.count).to eq 1
expect(conversation.first_reply_created_at).to be_nil
end
end
end