feat: Business hours

Data models and APIs for business hours

ref: #234
This commit is contained in:
Adam Zysko
2020-10-31 19:44:33 +01:00
committed by GitHub
parent 3d64ba49fc
commit 65ed4c78a4
23 changed files with 329 additions and 7 deletions

View File

@@ -45,4 +45,25 @@ describe ::MessageTemplates::HookExecutionService do
expect(email_collect_service).to have_received(:perform)
end
end
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)
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)
# 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
end

View File

@@ -0,0 +1,13 @@
require 'rails_helper'
describe ::MessageTemplates::Template::OutOfOffice 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).to eq(conversation.inbox.out_of_office_message)
end
end
end