@@ -10,7 +10,7 @@ FactoryBot.define do
|
||||
|
||||
after(:build) do |message|
|
||||
message.sender ||= message.outgoing? ? create(:user, account: message.account) : create(:contact, account: message.account)
|
||||
message.inbox ||= create(:inbox, account: message.account)
|
||||
message.inbox ||= message.conversation&.inbox || create(:inbox, account: message.account)
|
||||
message.conversation ||= create(:conversation, account: message.account, inbox: message.inbox)
|
||||
end
|
||||
end
|
||||
|
||||
12
spec/factories/working_hours.rb
Normal file
12
spec/factories/working_hours.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :working_hour do
|
||||
inbox
|
||||
day_of_week { 1 }
|
||||
open_hour { 9 }
|
||||
open_minutes { 0 }
|
||||
close_hour { 17 }
|
||||
close_minutes { 0 }
|
||||
end
|
||||
end
|
||||
19
spec/models/concerns/out_of_offisable_spec.rb
Normal file
19
spec/models/concerns/out_of_offisable_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require 'rails_helper'
|
||||
|
||||
shared_examples_for 'out_of_offisable' do
|
||||
let(:obj) { create(described_class.to_s.underscore, working_hours_enabled: true, out_of_office_message: 'Message') }
|
||||
|
||||
it 'has after create callback' do
|
||||
expect(obj.working_hours.count).to eq(7)
|
||||
end
|
||||
|
||||
it 'is working on monday 10am' do
|
||||
travel_to '26.10.2020 10:00'.to_datetime
|
||||
expect(obj.working_now?).to be true
|
||||
end
|
||||
|
||||
it 'is out of office on sunday 1pm' do
|
||||
travel_to '01.11.2020 13:00'.to_datetime
|
||||
expect(obj.out_of_office?).to be true
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require Rails.root.join 'spec/models/concerns/out_of_offisable_spec.rb'
|
||||
|
||||
RSpec.describe Inbox do
|
||||
describe 'validations' do
|
||||
@@ -33,6 +34,10 @@ RSpec.describe Inbox do
|
||||
it { is_expected.to have_many(:hooks) }
|
||||
end
|
||||
|
||||
describe 'concerns' do
|
||||
it_behaves_like 'out_of_offisable'
|
||||
end
|
||||
|
||||
describe '#add_member' do
|
||||
let(:inbox) { FactoryBot.create(:inbox) }
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
29
spec/models/working_hour_spec.rb
Normal file
29
spec/models/working_hour_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe WorkingHour do
|
||||
context 'when on monday 10am' do
|
||||
before do
|
||||
Time.zone = 'UTC'
|
||||
create(:working_hour)
|
||||
travel_to '26.10.2020 10:00'.to_datetime
|
||||
end
|
||||
|
||||
it 'is considered working hour' do
|
||||
expect(described_class.today.open_now?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when on sunday 1pm' do
|
||||
before do
|
||||
Time.zone = 'UTC'
|
||||
create(:working_hour, day_of_week: 7, closed_all_day: true)
|
||||
travel_to '01.11.2020 13:00'.to_datetime
|
||||
end
|
||||
|
||||
it 'is considered out of office' do
|
||||
expect(described_class.today.closed_now?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -65,6 +65,7 @@ RSpec.configure do |config|
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
config.include SlackStubs
|
||||
config.include Devise::Test::IntegrationHelpers, type: :request
|
||||
config.include ActiveSupport::Testing::TimeHelpers
|
||||
end
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user