feat: Add CSAT Message Template Hooks (#2494)

This commit is contained in:
Sojan Jose
2021-06-23 19:29:27 +05:30
committed by GitHub
parent 640e028bde
commit cd11efea1d
6 changed files with 115 additions and 7 deletions

View File

@@ -87,6 +87,55 @@ describe ::MessageTemplates::HookExecutionService do
end
end
context 'when CSAT Survey' do
let(:csat_survey) { double }
let(:conversation) { create(:conversation) }
before do
allow(::MessageTemplates::Template::CsatSurvey).to receive(:new).and_return(csat_survey)
allow(csat_survey).to receive(:perform).and_return(true)
end
it 'calls ::MessageTemplates::Template::CsatSurvey when a conversation is resolved in an inbox with survey enabled' do
conversation.inbox.update(csat_survey_enabled: true)
conversation.resolved!
expect(::MessageTemplates::Template::CsatSurvey).to have_received(:new).with(conversation: conversation)
expect(csat_survey).to have_received(:perform)
end
it 'will not call ::MessageTemplates::Template::CsatSurvey when Csat is not enabled' do
conversation.inbox.update(csat_survey_enabled: false)
conversation.resolved!
expect(::MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation)
expect(csat_survey).not_to have_received(:perform)
end
it 'will not call ::MessageTemplates::Template::CsatSurvey if its not a website widget' do
api_channel = create(:channel_api)
conversation = create(:conversation, inbox: create(:inbox, channel: api_channel))
conversation.inbox.update(csat_survey_enabled: true)
conversation.resolved!
expect(::MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation)
expect(csat_survey).not_to have_received(:perform)
end
it 'will not call ::MessageTemplates::Template::CsatSurvey if another Csat was already sent' do
conversation.inbox.update(csat_survey_enabled: true)
conversation.messages.create!(message_type: 'outgoing', content_type: :input_csat, account: conversation.account, inbox: conversation.inbox)
conversation.resolved!
expect(::MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation)
expect(csat_survey).not_to have_received(:perform)
end
end
# TODO: remove this if this hook is removed
# context 'when it is after working hours' do
# it 'calls ::MessageTemplates::Template::OutOfOffice' do

View File

@@ -0,0 +1,13 @@
require 'rails_helper'
describe ::MessageTemplates::Template::CsatSurvey do
context 'when this hook is called' do
let(:conversation) { create(:conversation) }
it 'creates the out of office messages' do
described_class.new(conversation: conversation).perform
expect(conversation.messages.template.count).to eq(1)
expect(conversation.messages.template.first.content_type).to eq('input_csat')
end
end
end