[Feature] Email collect message hooks (#331)
- Add email collect hook on creating conversation - Merge contact if it already exist
This commit is contained in:
@@ -57,19 +57,17 @@ RSpec.describe Conversation, type: :model do
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::ASSIGNEE_CHANGED, kind_of(Time), conversation: conversation)
|
||||
|
||||
# create_activity
|
||||
expect(conversation.messages.pluck(:content)).to eq(
|
||||
[
|
||||
"Conversation was marked resolved by #{old_assignee.name}",
|
||||
"Assigned to #{new_assignee.name} by #{old_assignee.name}"
|
||||
]
|
||||
)
|
||||
|
||||
# send_email_notification_to_assignee
|
||||
expect(AssignmentMailer).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
|
||||
|
||||
it 'creates conversation activities' do
|
||||
# create_activity
|
||||
expect(conversation.messages.pluck(:content)).to include("Conversation was marked resolved by #{old_assignee.name}")
|
||||
expect(conversation.messages.pluck(:content)).to include("Assigned to #{new_assignee.name} by #{old_assignee.name}")
|
||||
end
|
||||
end
|
||||
|
||||
describe '.after_create' do
|
||||
@@ -169,7 +167,7 @@ RSpec.describe Conversation, type: :model do
|
||||
end
|
||||
|
||||
it 'returns unread messages' do
|
||||
expect(unread_messages).to contain_exactly(message)
|
||||
expect(unread_messages).to include(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
26
spec/models/message_spec.rb
Normal file
26
spec/models/message_spec.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Message, type: :model do
|
||||
context 'with validations' do
|
||||
it { is_expected.to validate_presence_of(:inbox_id) }
|
||||
it { is_expected.to validate_presence_of(:conversation_id) }
|
||||
it { is_expected.to validate_presence_of(:account_id) }
|
||||
end
|
||||
|
||||
context 'when message is created' do
|
||||
let(:message) { build(:message) }
|
||||
|
||||
it 'triggers ::MessageTemplates::HookExecutionService' do
|
||||
hook_execution_service = double
|
||||
allow(::MessageTemplates::HookExecutionService).to receive(:new).and_return(hook_execution_service)
|
||||
allow(hook_execution_service).to receive(:perform).and_return(true)
|
||||
|
||||
message.save!
|
||||
|
||||
expect(::MessageTemplates::HookExecutionService).to have_received(:new).with(message: message)
|
||||
expect(hook_execution_service).to have_received(:perform)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user