Chatwoot/spec/services/message_templates/hook_execution_service_spec.rb
Sojan Jose 722f540b03 [Feature] Email collect message hooks (#331)
- Add email collect hook on creating conversation
- Merge contact if it already exist
2020-01-09 13:06:40 +05:30

20 lines
850 B
Ruby

require 'rails_helper'
describe ::MessageTemplates::HookExecutionService do
context 'when it is a first message from web widget' do
it 'calls ::MessageTemplates::Template::EmailCollect' do
message = create(:message)
# this hook will only get executed for conversations with out any template messages
message.conversation.messages.template.destroy_all
email_collect_service = double
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service)
allow(email_collect_service).to receive(:perform).and_return(true)
described_class.new(message: message).perform
expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation)
expect(email_collect_service).to have_received(:perform)
end
end
end