2020-01-23 17:29:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-03-01 13:36:13 +00:00
|
|
|
RSpec.describe ConversationReplyMailer, type: :mailer do
|
|
|
|
describe 'reply_with_summary' do
|
2020-06-02 18:20:39 +00:00
|
|
|
let!(:account) { create(:account) }
|
|
|
|
let!(:agent) { create(:user, email: 'agent1@example.com', account: account) }
|
2020-01-23 17:29:07 +00:00
|
|
|
let(:class_instance) { described_class.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:new).and_return(class_instance)
|
|
|
|
allow(class_instance).to receive(:smtp_config_set_or_development?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2020-05-10 08:33:11 +00:00
|
|
|
context 'with all mails' do
|
2020-04-30 14:50:26 +00:00
|
|
|
let(:conversation) { create(:conversation, assignee: agent) }
|
|
|
|
let(:message) { create(:message, conversation: conversation) }
|
2020-05-10 08:38:17 +00:00
|
|
|
let(:private_message) { create(:message, content: 'This is a private message', conversation: conversation) }
|
2020-04-30 14:50:26 +00:00
|
|
|
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
|
|
|
|
|
|
|
|
it 'renders the subject' do
|
2020-05-22 12:44:18 +00:00
|
|
|
expect(mail.subject).to eq("[##{message.conversation.display_id}] New messages on this conversation")
|
2020-04-30 14:50:26 +00:00
|
|
|
end
|
|
|
|
|
2020-05-10 08:33:11 +00:00
|
|
|
it 'not have private notes' do
|
|
|
|
# make the message private
|
|
|
|
private_message.private = true
|
|
|
|
private_message.save
|
|
|
|
|
|
|
|
expect(mail.body.decoded).not_to include(private_message.content)
|
|
|
|
expect(mail.body.decoded).to include(message.content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when custom domain and email is not enabled' do
|
2020-06-02 18:20:39 +00:00
|
|
|
let(:inbox) { create(:inbox, account: account) }
|
|
|
|
let(:inbox_member) { create(:inbox_member, user: agent, inbox: inbox) }
|
|
|
|
let(:conversation) { create(:conversation, assignee: agent, inbox: inbox_member.inbox, account: account) }
|
|
|
|
let!(:message) { create(:message, conversation: conversation, account: account) }
|
2020-05-10 08:33:11 +00:00
|
|
|
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
|
|
|
|
|
2020-04-30 14:50:26 +00:00
|
|
|
it 'renders the receiver email' do
|
|
|
|
expect(mail.to).to eq([message&.conversation&.contact&.email])
|
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
|
2020-04-30 14:50:26 +00:00
|
|
|
it 'renders the reply to email' do
|
|
|
|
expect(mail.reply_to).to eq([message&.conversation&.assignee&.email])
|
|
|
|
end
|
2020-05-22 12:44:18 +00:00
|
|
|
|
|
|
|
it 'sets the correct custom message id' do
|
|
|
|
expect(mail.message_id).to eq("<conversation/#{conversation.uuid}/messages/#{message.id}@>")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the correct in reply to id' do
|
|
|
|
expect(mail.in_reply_to).to eq("<account/#{conversation.account.id}/conversation/#{conversation.uuid}@>")
|
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
|
2020-04-30 14:50:26 +00:00
|
|
|
context 'when the cutsom domain emails are enabled' do
|
|
|
|
let(:conversation) { create(:conversation, assignee: agent) }
|
|
|
|
let(:message) { create(:message, conversation: conversation) }
|
|
|
|
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
|
|
|
|
|
|
|
|
before do
|
|
|
|
account = conversation.account
|
|
|
|
account.domain = 'example.com'
|
|
|
|
account.support_email = 'support@example.com'
|
|
|
|
account.domain_emails_enabled = true
|
|
|
|
account.save
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets reply to email to be based on the domain' do
|
|
|
|
reply_to_email = "reply+to+#{message.conversation.uuid}@#{conversation.account.domain}"
|
|
|
|
expect(mail.reply_to).to eq([reply_to_email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the from email to be the support email' do
|
|
|
|
expect(mail.from).to eq([conversation.account.support_email])
|
|
|
|
end
|
2020-05-22 12:44:18 +00:00
|
|
|
|
|
|
|
it 'sets the correct custom message id' do
|
|
|
|
expect(mail.message_id).to eq("conversation/#{conversation.uuid}/messages/#{message.id}@#{conversation.account.domain}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the correct in reply to id' do
|
|
|
|
expect(mail.in_reply_to).to eq("account/#{conversation.account.id}/conversation/#{conversation.uuid}@#{conversation.account.domain}")
|
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|