Skip to content

Commit

Permalink
fix: calculation for resolution count (#7293)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
scmmishra committed Jun 14, 2023
1 parent a86e236 commit 2e79a32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/helpers/report_helper.rb
Expand Up @@ -29,7 +29,9 @@ def outgoing_messages_count
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
Expand Down
28 changes: 23 additions & 5 deletions spec/builders/v2/report_builder_spec.rb
Expand Up @@ -106,12 +106,20 @@
}

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
Expand Down Expand Up @@ -216,11 +224,21 @@
}

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
Expand Down

0 comments on commit 2e79a32

Please sign in to comment.