feat: Consider business hours while generating the reports (#4330)

* feat: Consider business hours while generating the reports
This commit is contained in:
Aswin Dev P.S
2022-04-08 12:48:18 +05:30
committed by GitHub
parent 57359be37e
commit d5536d65f7
19 changed files with 241 additions and 48 deletions

View File

@@ -17,6 +17,21 @@ describe ReportingEventListener do
listener.conversation_resolved(event)
expect(account.reporting_events.where(name: 'conversation_resolved').count).to be 1
end
context 'when business hours enabled for inbox' do
let(:created_at) { Time.zone.parse('March 20, 2022 00:00') }
let(:updated_at) { Time.zone.parse('March 26, 2022 23:59') }
let!(:new_inbox) { create(:inbox, working_hours_enabled: true, account: account) }
let!(:new_conversation) do
create(:conversation, created_at: created_at, updated_at: updated_at, account: account, inbox: new_inbox, assignee: user)
end
it 'creates conversation_resolved event with business hour value' do
event = Events::Base.new('conversation.resolved', Time.zone.now, conversation: new_conversation)
listener.conversation_resolved(event)
expect(account.reporting_events.where(name: 'conversation_resolved')[0]['value_in_business_hours']).to be 144_000.0
end
end
end
describe '#first_reply_created' do
@@ -26,5 +41,24 @@ describe ReportingEventListener do
listener.first_reply_created(event)
expect(account.reporting_events.where(name: 'first_response').count).to eql previous_count + 1
end
context 'when business hours enabled for inbox' do
let(:conversation_created_at) { Time.zone.parse('March 20, 2022 00:00') }
let(:message_created_at) { Time.zone.parse('March 26, 2022 23:59') }
let!(:new_inbox) { create(:inbox, working_hours_enabled: true, account: account) }
let!(:new_conversation) do
create(:conversation, created_at: conversation_created_at, account: account, inbox: new_inbox, assignee: user)
end
let!(:new_message) do
create(:message, message_type: 'outgoing', created_at: message_created_at,
account: account, inbox: new_inbox, conversation: new_conversation)
end
it 'creates first_response event with business hour value' do
event = Events::Base.new('first.reply.created', Time.zone.now, message: new_message)
listener.first_reply_created(event)
expect(account.reporting_events.where(name: 'first_response')[0]['value_in_business_hours']).to be 144_000.0
end
end
end
end