From 6f127d86b912a4d774bc97fbc05e81bcc15f2cc0 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 9 Mar 2026 13:57:49 +0530 Subject: [PATCH] feat: add validity gate --- app/services/reporting_events/rollup_service.rb | 4 ++-- .../v2/reports/concerns/rollup_conditions_spec.rb | 2 +- .../reporting_events/rollup_service_spec.rb | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/services/reporting_events/rollup_service.rb b/app/services/reporting_events/rollup_service.rb index 7cc0c3857..95dbee76b 100644 --- a/app/services/reporting_events/rollup_service.rb +++ b/app/services/reporting_events/rollup_service.rb @@ -30,10 +30,10 @@ module ReportingEvents::RollupService private # NOTE: This is intentionally not gated by the reporting_events_rollup feature flag. - # Rollup data is collected for all accounts with a reporting timezone (soft toggle). + # Rollup data is collected for all accounts with a valid reporting timezone (soft toggle). # The feature flag only controls the read path — whether reports query rollups or raw events. def rollup_enabled? - @account.reporting_timezone.present? + @account.reporting_timezone.present? && ActiveSupport::TimeZone[@account.reporting_timezone].present? end def event_date diff --git a/spec/builders/v2/reports/concerns/rollup_conditions_spec.rb b/spec/builders/v2/reports/concerns/rollup_conditions_spec.rb index dc817a27f..8f35bd0a6 100644 --- a/spec/builders/v2/reports/concerns/rollup_conditions_spec.rb +++ b/spec/builders/v2/reports/concerns/rollup_conditions_spec.rb @@ -301,7 +301,7 @@ describe V2::Reports::Concerns::RollupConditions do end it 'returns false when account timezone is not recognized' do - account.update!(reporting_timezone: 'Invalid/Zone') + allow(account).to receive(:reporting_timezone).and_return('Invalid/Zone') builder.params = { timezone_offset: current_ny_offset } expect(builder.timezone_matches_account?).to be false end diff --git a/spec/services/reporting_events/rollup_service_spec.rb b/spec/services/reporting_events/rollup_service_spec.rb index 8299c5f56..1fc49634c 100644 --- a/spec/services/reporting_events/rollup_service_spec.rb +++ b/spec/services/reporting_events/rollup_service_spec.rb @@ -23,6 +23,20 @@ describe ReportingEvents::RollupService do end end + context 'when reporting_timezone is invalid' do + it 'skips rollup creation' do + reporting_event = create(:reporting_event, + account: account, + name: 'conversation_resolved', + conversation: conversation) + allow(account).to receive(:reporting_timezone).and_return('Invalid/Zone') + + expect do + described_class.perform(reporting_event) + end.not_to change(ReportingEventsRollup, :count) + end + end + context 'when reporting_timezone is set' do describe 'conversation_resolved event' do let(:reporting_event) do