fix: calculation for resolution count (#7293)

* fix: calculation for resolution count

* test: resolution count bug fix

- ensure enqueued jobs are run
- fix the dates check, conversations resolved today should show up in today

* feat: ensure conversations are resolved

* test: do not count extra events if the conversation is not resolved currently

* fix: typo
This commit is contained in:
Shivam Mishra
2023-06-14 13:50:10 +05:30
committed by GitHub
parent a86e236d19
commit 2e79a32db7
2 changed files with 26 additions and 6 deletions

View File

@@ -29,7 +29,9 @@ module ReportHelper
end
def resolutions_count
(get_grouped_values scope.conversations.where(account_id: account.id).resolved).count
object_scope = scope.reporting_events.joins(:conversation).select(:conversation_id).where(account_id: account.id, name: :conversation_resolved,
conversations: { status: :resolved }).distinct
(get_grouped_values object_scope).count
end
def avg_first_response_time

View File

@@ -106,12 +106,20 @@ describe V2::ReportBuilder do
}
conversations = account.conversations.where('created_at < ?', 1.day.ago)
conversations.each(&:resolved!)
perform_enqueued_jobs do
# Resolve all 5 conversations
conversations.each(&:resolved!)
# Reopen 1 conversation
conversations.first.open!
end
builder = described_class.new(account, params)
metrics = builder.timeseries
expect(metrics[Time.zone.today]).to be 0
expect(metrics[Time.zone.today - 2.days]).to be 5
# 4 conversations are resolved
expect(metrics[Time.zone.today]).to be 4
expect(metrics[Time.zone.today - 2.days]).to be 0
end
it 'returns average first response time' do
@@ -216,11 +224,21 @@ describe V2::ReportBuilder do
}
conversations = account.conversations.where('created_at < ?', 1.day.ago)
conversations.each(&:resolved!)
perform_enqueued_jobs do
# ensure 5 reporting events are created
conversations.each(&:resolved!)
# open one of the conversations to check if it is not counted
conversations.last.open!
end
builder = described_class.new(account, params)
metrics = builder.timeseries
expect(metrics[Time.zone.today - 2.days]).to be 5
# this should count only 4 since the last conversation was reopened
expect(metrics[Time.zone.today]).to be 4
expect(metrics[Time.zone.today - 2.days]).to be 0
end
it 'returns average first response time' do