2020-01-23 17:29:07 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
Sidekiq::Testing.fake!
|
2020-03-01 13:36:13 +00:00
|
|
|
RSpec.describe ConversationReplyEmailWorker, type: :worker do
|
2020-01-23 17:29:07 +00:00
|
|
|
let(:conversation) { build(:conversation, display_id: nil) }
|
2020-07-15 11:03:52 +00:00
|
|
|
let(:message) { build(:message, conversation: conversation, content_type: 'incoming_email', inbox: conversation.inbox) }
|
2021-06-08 17:15:01 +00:00
|
|
|
let(:mailer) { double }
|
|
|
|
let(:mailer_action) { double }
|
2020-01-23 17:29:07 +00:00
|
|
|
|
2020-03-01 13:36:13 +00:00
|
|
|
describe 'testing ConversationSummaryEmailWorker' do
|
2020-01-23 17:29:07 +00:00
|
|
|
before do
|
|
|
|
conversation.save!
|
|
|
|
allow(Conversation).to receive(:find).and_return(conversation)
|
2021-06-08 17:15:01 +00:00
|
|
|
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
|
|
|
|
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
|
|
|
|
allow(mailer).to receive(:reply_with_summary).and_return(mailer_action)
|
|
|
|
allow(mailer).to receive(:reply_without_summary).and_return(mailer_action)
|
|
|
|
allow(mailer_action).to receive(:deliver_later).and_return(true)
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'worker jobs are enqueued in the mailers queue' do
|
|
|
|
described_class.perform_async
|
|
|
|
assert_equal :mailers, described_class.queue
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'goes into the jobs array for testing environment' do
|
|
|
|
expect do
|
|
|
|
described_class.perform_async
|
|
|
|
end.to change(described_class.jobs, :size).by(1)
|
2021-10-14 07:25:46 +00:00
|
|
|
described_class.new.perform(1, message.id)
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with actions performed by the worker' do
|
2020-07-15 11:03:52 +00:00
|
|
|
it 'calls ConversationSummaryMailer#reply_with_summary when last incoming message was not email' do
|
2021-10-14 07:25:46 +00:00
|
|
|
described_class.new.perform(1, message.id)
|
2021-06-08 17:15:01 +00:00
|
|
|
expect(mailer).to have_received(:reply_with_summary)
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
2020-07-15 11:03:52 +00:00
|
|
|
|
|
|
|
it 'calls ConversationSummaryMailer#reply_without_summary when last incoming message was from email' do
|
|
|
|
message.save
|
2021-10-14 07:25:46 +00:00
|
|
|
described_class.new.perform(1, message.id)
|
2021-06-08 17:15:01 +00:00
|
|
|
expect(mailer).to have_received(:reply_without_summary)
|
2020-07-15 11:03:52 +00:00
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|