2020-01-09 07:36:40 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ::MessageTemplates::HookExecutionService do
|
|
|
|
context 'when it is a first message from web widget' do
|
|
|
|
it 'calls ::MessageTemplates::Template::EmailCollect' do
|
2020-04-03 07:34:58 +00:00
|
|
|
contact = create(:contact, email: nil)
|
|
|
|
conversation = create(:conversation, contact: contact)
|
|
|
|
|
2020-06-09 18:24:35 +00:00
|
|
|
# ensure greeting hook is enabled
|
|
|
|
conversation.inbox.update(greeting_enabled: true)
|
2020-01-09 07:36:40 +00:00
|
|
|
|
|
|
|
email_collect_service = double
|
2020-06-09 18:24:35 +00:00
|
|
|
greeting_service = double
|
2020-01-09 07:36:40 +00:00
|
|
|
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service)
|
|
|
|
allow(email_collect_service).to receive(:perform).and_return(true)
|
2020-06-09 18:24:35 +00:00
|
|
|
allow(::MessageTemplates::Template::Greeting).to receive(:new).and_return(greeting_service)
|
|
|
|
allow(greeting_service).to receive(:perform).and_return(true)
|
2020-01-09 07:36:40 +00:00
|
|
|
|
2020-06-09 18:24:35 +00:00
|
|
|
# described class gets called in message after commit
|
|
|
|
message = create(:message, conversation: conversation)
|
2020-01-09 07:36:40 +00:00
|
|
|
|
2020-06-09 18:24:35 +00:00
|
|
|
expect(::MessageTemplates::Template::Greeting).to have_received(:new).with(conversation: message.conversation)
|
|
|
|
expect(greeting_service).to have_received(:perform)
|
2020-01-09 07:36:40 +00:00
|
|
|
expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation)
|
|
|
|
expect(email_collect_service).to have_received(:perform)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|