From e244d0c56db438d4ee66751485c6790785b50faa Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Tue, 20 Jan 2026 23:18:41 -0800 Subject: [PATCH] test(reports): stabilize metrics specs --- app/models/installation_config.rb | 2 - app/models/user.rb | 2 +- spec/builders/v2/report_builder_spec.rb | 8 ++- .../v2/reports/label_summary_builder_spec.rb | 51 ++++++++++++++----- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/models/installation_config.rb b/app/models/installation_config.rb index c3fad9192..6f9bf3269 100644 --- a/app/models/installation_config.rb +++ b/app/models/installation_config.rb @@ -58,8 +58,6 @@ class InstallationConfig < ApplicationRecord end def clear_cache - return if ConfigLoader.processing? - GlobalConfig.clear_cache end diff --git a/app/models/user.rb b/app/models/user.rb index badd4e31b..741c54107 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/builders/v2/report_builder_spec.rb b/spec/builders/v2/report_builder_spec.rb index 3f86b0348..1308e4c07 100644 --- a/spec/builders/v2/report_builder_spec.rb +++ b/spec/builders/v2/report_builder_spec.rb @@ -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, diff --git a/spec/builders/v2/reports/label_summary_builder_spec.rb b/spec/builders/v2/reports/label_summary_builder_spec.rb index f0eb6cefd..f32382802 100644 --- a/spec/builders/v2/reports/label_summary_builder_spec.rb +++ b/spec/builders/v2/reports/label_summary_builder_spec.rb @@ -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