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(:perform_at) { (Time.zone.today + 6.hours).to_datetime }
|
|
|
|
let(:scheduled_job) { described_class.perform_at(perform_at, 1, Time.zone.now) }
|
|
|
|
let(:conversation) { build(:conversation, display_id: nil) }
|
|
|
|
|
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)
|
|
|
|
mailer = double
|
2020-03-01 13:36:13 +00:00
|
|
|
allow(ConversationReplyMailer).to receive(:reply_with_summary).and_return(mailer)
|
2020-01-23 17:29:07 +00:00
|
|
|
allow(mailer).to receive(:deliver_later).and_return(true)
|
|
|
|
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)
|
|
|
|
described_class.new.perform(1, Time.zone.now)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with actions performed by the worker' do
|
2020-03-01 13:36:13 +00:00
|
|
|
it 'calls ConversationSummaryMailer' do
|
2020-01-23 17:29:07 +00:00
|
|
|
described_class.new.perform(1, Time.zone.now)
|
2020-03-01 13:36:13 +00:00
|
|
|
expect(ConversationReplyMailer).to have_received(:reply_with_summary)
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|