Feat: Out of office autoresponder (#2992)

This change allows the user to enable autoresponder during the out-of-office time.

Fixes: #2035
This commit is contained in:
Aswin Dev P.S
2021-09-17 22:17:11 +05:30
committed by GitHub
parent 6ad5a7452c
commit 794a56d4cc
5 changed files with 68 additions and 26 deletions

View File

@@ -154,25 +154,41 @@ describe ::MessageTemplates::HookExecutionService do
end
end
# TODO: remove this if this hook is removed
# context 'when it is after working hours' do
# it 'calls ::MessageTemplates::Template::OutOfOffice' do
# contact = create :contact
# conversation = create :conversation, contact: contact
context 'when it is after working hours' do
it 'calls ::MessageTemplates::Template::OutOfOffice' do
contact = create :contact
conversation = create :conversation, contact: contact
# conversation.inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office')
# conversation.inbox.working_hours.today.update!(closed_all_day: true)
conversation.inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office')
conversation.inbox.working_hours.today.update!(closed_all_day: true)
# out_of_office_service = double
out_of_office_service = double
# allow(::MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service)
# allow(out_of_office_service).to receive(:perform).and_return(true)
allow(::MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service)
allow(out_of_office_service).to receive(:perform).and_return(true)
# # described class gets called in message after commit
# message = create(:message, conversation: conversation)
# described class gets called in message after commit
message = create(:message, conversation: conversation)
# expect(::MessageTemplates::Template::OutOfOffice).to have_received(:new).with(conversation: message.conversation)
# expect(out_of_office_service).to have_received(:perform)
# end
# end
expect(::MessageTemplates::Template::OutOfOffice).to have_received(:new).with(conversation: message.conversation)
expect(out_of_office_service).to have_received(:perform)
end
it 'will not call ::MessageTemplates::Template::OutOfOffice if its a tweet conversation' do
twitter_channel = create(:channel_twitter_profile)
twitter_inbox = create(:inbox, channel: twitter_channel)
twitter_inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office')
conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' })
out_of_office_service = double
allow(::MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service)
allow(out_of_office_service).to receive(:perform).and_return(false)
message = create(:message, conversation: conversation)
expect(::MessageTemplates::Template::OutOfOffice).not_to have_received(:new).with(conversation: message.conversation)
expect(out_of_office_service).not_to receive(:perform)
end
end
end