test(reports): stabilize metrics specs

This commit is contained in:
Sojan Jose
2026-01-20 23:18:41 -08:00
parent 59bf85d993
commit e244d0c56d
4 changed files with 44 additions and 19 deletions
-2
View File
@@ -58,8 +58,6 @@ class InstallationConfig < ApplicationRecord
end
def clear_cache
return if ConfigLoader.processing?
GlobalConfig.clear_cache
end
+1 -1
View File
@@ -137,7 +137,7 @@ class User < ApplicationRecord
end
def serializable_hash(options = nil)
super.merge(confirmed: confirmed?)
super(options).merge(confirmed: confirmed?)
end
def push_event_data
+6 -2
View File
@@ -21,8 +21,10 @@ describe V2::ReportBuilder do
perform_enqueued_jobs do
10.times do
conversation = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: Time.zone.today)
conversation.reload
conversation.update_column(:assignee_id, user.id)
create_list(:message, 5, message_type: 'outgoing',
account: account, inbox: inbox,
conversation: conversation, created_at: Time.zone.today + 2.hours)
@@ -37,8 +39,10 @@ describe V2::ReportBuilder do
5.times do
conversation = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: (Time.zone.today - 2.days))
conversation.reload
conversation.update_column(:assignee_id, user.id)
create_list(:message, 3, message_type: 'outgoing',
account: account, inbox: inbox,
conversation: conversation,
@@ -92,8 +92,10 @@ RSpec.describe V2::Reports::LabelSummaryBuilder do
# Create conversations with label_1
3.times do
conversation = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: Time.zone.today)
conversation.reload
conversation.update_column(:assignee_id, user.id)
create_list(:message, 2, message_type: 'outgoing',
account: account, inbox: inbox,
conversation: conversation,
@@ -110,8 +112,10 @@ RSpec.describe V2::Reports::LabelSummaryBuilder do
# Create conversations with label_2
2.times do
conversation = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: Time.zone.today)
conversation.reload
conversation.update_column(:assignee_id, user.id)
create_list(:message, 1, message_type: 'outgoing',
account: account, inbox: inbox,
conversation: conversation,
@@ -229,8 +233,10 @@ RSpec.describe V2::Reports::LabelSummaryBuilder do
perform_enqueued_jobs do
# Conversation within range
conversation_in_range = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: 2.days.ago)
conversation_in_range.reload
conversation_in_range.update_column(:assignee_id, user.id)
conversation_in_range.update_labels('label_1')
conversation_in_range.label_list
conversation_in_range.save!
@@ -244,8 +250,10 @@ RSpec.describe V2::Reports::LabelSummaryBuilder do
# Conversation outside range (too old)
conversation_out_of_range = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: 1.week.ago)
conversation_out_of_range.reload
conversation_out_of_range.update_column(:assignee_id, user.id)
conversation_out_of_range.update_labels('label_1')
conversation_out_of_range.label_list
conversation_out_of_range.save!
@@ -286,8 +294,10 @@ RSpec.describe V2::Reports::LabelSummaryBuilder do
perform_enqueued_jobs do
conversation = create(:conversation, account: account,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: Time.zone.today)
conversation.reload
conversation.update_column(:assignee_id, user.id)
conversation.update_labels('label_1')
conversation.label_list
conversation.save!
@@ -343,20 +353,33 @@ RSpec.describe V2::Reports::LabelSummaryBuilder do
perform_enqueued_jobs do
conversation = create(:conversation, account: account2,
inbox: inbox, assignee: user,
inbox: inbox,
created_at: test_date)
conversation.reload
conversation.update_column(:assignee_id, user.id)
conversation.update_labels(unique_label_name)
conversation.label_list
conversation.save!
# First resolution
conversation.resolved!
# Reopen conversation
conversation.open!
# Second resolution
conversation.resolved!
resolved_at = Time.zone.local(test_date.year, test_date.month, test_date.day, 10, 0, 0)
create(:reporting_event,
account: account2,
conversation: conversation,
inbox: inbox,
user: user,
name: 'conversation_resolved',
created_at: resolved_at,
event_start_time: resolved_at - 1.hour,
event_end_time: resolved_at)
create(:reporting_event,
account: account2,
conversation: conversation,
inbox: inbox,
user: user,
name: 'conversation_resolved',
created_at: resolved_at + 1.hour,
event_start_time: resolved_at,
event_end_time: resolved_at + 1.hour)
end
end
end