Feature: Inbox greeting message (#927)

Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
Sojan Jose
2020-06-09 23:54:35 +05:30
committed by GitHub
parent 8b022311c0
commit 432dad203b
48 changed files with 262 additions and 120 deletions

View File

@@ -24,8 +24,8 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
# 2 messages created + 3 messages by the template hook
expect(json_response.length).to eq(5)
# 2 messages created + 2 messages by the email hook
expect(json_response.length).to eq(4)
end
end
end

View File

@@ -15,7 +15,7 @@ describe ::MessageFinder do
create(:message, account: account, inbox: inbox, conversation: conversation)
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
# this outgoing message creates 3 additional messages because of the hook execution service
# this outgoing message creates 2 additional messages because of the email hook execution service
create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation)
end
@@ -25,7 +25,7 @@ describe ::MessageFinder do
it 'filter conversations by status' do
result = message_finder.perform
expect(result.count).to be 7
expect(result.count).to be 6
end
end
@@ -34,7 +34,7 @@ describe ::MessageFinder do
it 'filter conversations by status' do
result = message_finder.perform
expect(result.count).to be 5
expect(result.count).to be 4
end
end
@@ -44,7 +44,7 @@ describe ::MessageFinder do
it 'filter conversations by status' do
result = message_finder.perform
expect(result.count).to be 7
expect(result.count).to be 6
end
end
end

View File

@@ -7,7 +7,7 @@ describe Webhooks::Twitter do
let!(:account) { create(:account) }
# FIX ME: recipient id is set to 1 inside event factories
let!(:twitter_channel) { create(:channel_twitter_profile, account: account, profile_id: '1') }
let!(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account) }
let!(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account, greeting_enabled: false) }
let!(:dm_params) { build(:twitter_message_create_event).with_indifferent_access }
let!(:tweet_params) { build(:tweet_create_event).with_indifferent_access }

View File

@@ -6,7 +6,7 @@ RSpec.describe ConversationMailbox, type: :mailbox do
describe 'add mail as reply in a conversation' do
let(:agent) { create(:user, email: 'agent1@example.com') }
let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') }
let(:conversation) { create(:conversation, assignee: agent) }
let(:conversation) { create(:conversation, assignee: agent, inbox: create(:inbox, greeting_enabled: false)) }
let(:described_subject) { described_class.receive reply_mail }
let(:serialized_attributes) { %w[text_content html_content number_of_attachments subject date to from in_reply_to cc bcc message_id] }

View File

@@ -5,17 +5,22 @@ describe ::MessageTemplates::HookExecutionService do
it 'calls ::MessageTemplates::Template::EmailCollect' do
contact = create(:contact, email: nil)
conversation = create(:conversation, contact: contact)
message = create(:message, conversation: conversation)
# this hook will only get executed for conversations with out any template messages
message.conversation.messages.template.destroy_all
# ensure greeting hook is enabled
conversation.inbox.update(greeting_enabled: true)
email_collect_service = double
greeting_service = double
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service)
allow(email_collect_service).to receive(:perform).and_return(true)
allow(::MessageTemplates::Template::Greeting).to receive(:new).and_return(greeting_service)
allow(greeting_service).to receive(:perform).and_return(true)
described_class.new(message: message).perform
# described class gets called in message after commit
message = create(:message, conversation: conversation)
expect(::MessageTemplates::Template::Greeting).to have_received(:new).with(conversation: message.conversation)
expect(greeting_service).to have_received(:perform)
expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation)
expect(email_collect_service).to have_received(:perform)
end

View File

@@ -6,7 +6,7 @@ describe ::MessageTemplates::Template::EmailCollect do
it 'creates the email collect messages' do
described_class.new(conversation: conversation).perform
expect(conversation.messages.count).to eq(3)
expect(conversation.messages.count).to eq(2)
end
end
end

View File

@@ -0,0 +1,12 @@
require 'rails_helper'
describe ::MessageTemplates::Template::Greeting do
context 'when this hook is called' do
let(:conversation) { create(:conversation) }
it 'creates the email collect messages' do
described_class.new(conversation: conversation).perform
expect(conversation.messages.count).to eq(1)
end
end
end

View File

@@ -3,7 +3,8 @@ require 'rails_helper'
describe Twilio::IncomingMessageService do
let!(:account) { create(:account) }
let!(:twilio_sms) do
create(:channel_twilio_sms, account: account, phone_number: '+1234567890', account_sid: 'ACxxx')
create(:channel_twilio_sms, account: account, phone_number: '+1234567890', account_sid: 'ACxxx',
inbox: create(:inbox, account: account, greeting_enabled: false))
end
let!(:contact) { create(:contact, account: account, phone_number: '+12345') }
let(:contact_inbox) { create(:contact_inbox, source_id: '+12345', contact: contact, inbox: twilio_sms.inbox) }