2020-03-01 13:36:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :mailer do
|
|
|
|
let(:class_instance) { described_class.new }
|
2021-01-26 18:34:11 +00:00
|
|
|
let!(:account) { create(:account) }
|
|
|
|
let(:agent) { create(:user, email: 'agent1@example.com', account: account) }
|
|
|
|
let(:conversation) { create(:conversation, assignee: agent, account: account) }
|
2020-03-01 13:36:13 +00:00
|
|
|
|
|
|
|
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-01 09:23:43 +00:00
|
|
|
describe 'conversation_creation' do
|
2021-08-01 12:45:39 +00:00
|
|
|
let(:mail) { described_class.with(account: account).conversation_creation(conversation, agent).deliver_now }
|
2020-03-01 13:36:13 +00:00
|
|
|
|
|
|
|
it 'renders the subject' do
|
2020-08-01 13:00:47 +00:00
|
|
|
expect(mail.subject).to eq("#{agent.available_name}, A new conversation [ID - #{conversation
|
2020-03-01 13:36:13 +00:00
|
|
|
.display_id}] has been created in #{conversation.inbox&.name}.")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the receiver email' do
|
|
|
|
expect(mail.to).to eq([agent.email])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-01 09:23:43 +00:00
|
|
|
describe 'conversation_assignment' do
|
2021-08-01 12:45:39 +00:00
|
|
|
let(:mail) { described_class.with(account: account).conversation_assignment(conversation, agent).deliver_now }
|
2020-03-01 13:36:13 +00:00
|
|
|
|
|
|
|
it 'renders the subject' do
|
2020-08-01 13:00:47 +00:00
|
|
|
expect(mail.subject).to eq("#{agent.available_name}, A new conversation [ID - #{conversation.display_id}] has been assigned to you.")
|
2020-03-01 13:36:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the receiver email' do
|
|
|
|
expect(mail.to).to eq([agent.email])
|
|
|
|
end
|
|
|
|
end
|
2020-09-10 13:49:15 +00:00
|
|
|
|
2021-01-26 18:34:11 +00:00
|
|
|
describe 'conversation_mention' do
|
2021-08-18 09:58:45 +00:00
|
|
|
let(:another_agent) { create(:user, email: 'agent2@example.com', account: account) }
|
|
|
|
let(:message) { create(:message, conversation: conversation, account: account, sender: another_agent) }
|
2021-08-01 12:45:39 +00:00
|
|
|
let(:mail) { described_class.with(account: account).conversation_mention(message, agent).deliver_now }
|
2021-01-26 18:34:11 +00:00
|
|
|
|
|
|
|
it 'renders the subject' do
|
|
|
|
expect(mail.subject).to eq("#{agent.available_name}, You have been mentioned in conversation [ID - #{conversation.display_id}]")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the receiver email' do
|
|
|
|
expect(mail.to).to eq([agent.email])
|
|
|
|
end
|
2021-08-18 09:58:45 +00:00
|
|
|
|
|
|
|
it 'renders the senders name' do
|
|
|
|
expect(mail.body.encoded).to match("You've been mentioned in a conversation. <b>#{another_agent.display_name}</b> wrote:")
|
|
|
|
end
|
2021-01-26 18:34:11 +00:00
|
|
|
end
|
|
|
|
|
2020-09-10 13:49:15 +00:00
|
|
|
describe 'assigned_conversation_new_message' do
|
2021-03-31 11:09:57 +00:00
|
|
|
let(:message) { create(:message, conversation: conversation, account: account) }
|
2021-08-01 12:45:39 +00:00
|
|
|
let(:mail) { described_class.with(account: account).assigned_conversation_new_message(message, agent).deliver_now }
|
2020-09-10 13:49:15 +00:00
|
|
|
|
|
|
|
it 'renders the subject' do
|
2021-03-31 11:09:57 +00:00
|
|
|
expect(mail.subject).to eq("#{agent.available_name}, New message in your assigned conversation [ID - #{message.conversation.display_id}].")
|
2020-09-10 13:49:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the receiver email' do
|
|
|
|
expect(mail.to).to eq([agent.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'will not send email if agent is online' do
|
|
|
|
::OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id)
|
|
|
|
expect(mail).to eq nil
|
|
|
|
end
|
|
|
|
end
|
2020-03-01 13:36:13 +00:00
|
|
|
end
|