Feature: Conversation creation email notifications (#576)

* Clean up the mailers

* Disable assignment mailer if setting is turned off

* Email notifications on conversation create

* Specs
This commit is contained in:
Sojan Jose
2020-03-01 19:06:13 +05:30
committed by GitHub
parent d6237dfc59
commit cda65ea339
17 changed files with 160 additions and 31 deletions

View File

@@ -34,7 +34,7 @@ RSpec.describe Conversation, type: :model do
new_assignee
allow(Rails.configuration.dispatcher).to receive(:dispatch)
allow(AssignmentMailer).to receive(:conversation_assigned).and_return(assignment_mailer)
allow(AgentNotifications::ConversationNotificationsMailer).to receive(:conversation_assigned).and_return(assignment_mailer)
allow(assignment_mailer).to receive(:deliver_later)
Current.user = old_assignee
@@ -58,7 +58,7 @@ RSpec.describe Conversation, type: :model do
.with(described_class::ASSIGNEE_CHANGED, kind_of(Time), conversation: conversation)
# send_email_notification_to_assignee
expect(AssignmentMailer).to have_received(:conversation_assigned).with(conversation, new_assignee)
expect(AgentNotifications::ConversationNotificationsMailer).to have_received(:conversation_assigned).with(conversation, new_assignee)
expect(assignment_mailer).to have_received(:deliver_later) if ENV.fetch('SMTP_ADDRESS', nil).present?
end
@@ -117,11 +117,23 @@ RSpec.describe Conversation, type: :model do
let(:agent) do
create(:user, email: 'agent@example.com', account: conversation.account, role: :agent)
end
let(:assignment_mailer) { double(deliver: true) }
it 'assigns the agent to conversation' do
expect(update_assignee).to eq(true)
expect(conversation.reload.assignee).to eq(agent)
end
it 'does not send assignment mailer if notification setting is turned off' do
allow(AgentNotifications::ConversationNotificationsMailer).to receive(:conversation_assigned).and_return(assignment_mailer)
notification_setting = agent.notification_settings.first
notification_setting.unselect_all_email_flags
notification_setting.save!
expect(update_assignee).to eq(true)
expect(AgentNotifications::ConversationNotificationsMailer).not_to have_received(:conversation_assigned).with(conversation, agent)
end
end
describe '#toggle_status' do