From d86c8d1edef57e206d2710716c37a897ce16ba82 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 9 Mar 2026 12:55:49 +0530 Subject: [PATCH] style: rubcop issues --- .../timeseries/average_report_builder_spec.rb | 114 ++++++++++-------- .../timeseries/count_report_builder_spec.rb | 11 +- 2 files changed, 71 insertions(+), 54 deletions(-) diff --git a/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb b/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb index f79349bde..3b67307b3 100644 --- a/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb +++ b/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb @@ -80,9 +80,11 @@ describe V2::Reports::Timeseries::AverageReportBuilder do end context 'when rollups are enabled' do + let(:timezone_offset) { '5.5' } + before do - account.update!(reporting_timezone: 'UTC') - allow(subject).to receive(:use_rollup?).and_return(true) + account.update!(reporting_timezone: 'Chennai') + allow(account).to receive(:feature_enabled?).with('reporting_events_rollup').and_return(true) create(:reporting_events_rollup, account: account, @@ -106,18 +108,27 @@ describe V2::Reports::Timeseries::AverageReportBuilder do end it 'preserves empty buckets in the timeseries' do - expect(subject.timeseries).to eq( - [ - { count: 1, timestamp: 1_603_065_600, value: 93.0 }, - { count: 0, timestamp: 1_603_152_000, value: 0 }, - { count: 0, timestamp: 1_603_238_400, value: 0 }, - { count: 0, timestamp: 1_603_324_800, value: 0 }, - { count: 0, timestamp: 1_603_411_200, value: 0 }, - { count: 0, timestamp: 1_603_497_600, value: 0 }, - { count: 0, timestamp: 1_603_584_000, value: 0 }, - { count: 2, timestamp: 1_603_670_400, value: 90.0 } - ] - ) + expected_timeseries = subject.send(:rollup_date_range).map do |date| + value = if date == (current_time - 1.week).to_date + 93.0 + elsif date == current_time.to_date + 90.0 + else + 0 + end + + count = if date == (current_time - 1.week).to_date + 1 + elsif date == current_time.to_date + 2 + else + 0 + end + + { count: count, timestamp: date.in_time_zone('Chennai').to_i, value: value } + end + + expect(subject.timeseries).to eq(expected_timeseries) end end @@ -133,42 +144,6 @@ describe V2::Reports::Timeseries::AverageReportBuilder do ] ) end - - context 'when rollups are enabled' do - before do - account.update!(reporting_timezone: 'UTC') - allow(subject).to receive(:use_rollup?).and_return(true) - - create(:reporting_events_rollup, - account: account, - date: current_time.to_date - 1.day, - dimension_type: 'account', - dimension_id: account.id, - metric: 'first_response', - count: 1, - sum_value: 80.0, - sum_value_business_hours: 10.0) - - create(:reporting_events_rollup, - account: account, - date: current_time.to_date, - dimension_type: 'account', - dimension_id: account.id, - metric: 'first_response', - count: 1, - sum_value: 100.0, - sum_value_business_hours: 20.0) - end - - it 'groups weeks using sunday boundaries' do - expect(subject.timeseries).to eq( - [ - { count: 0, timestamp: (current_time - 1.week).beginning_of_week(:sunday).to_i, value: 0 }, - { count: 2, timestamp: current_time.beginning_of_week(:sunday).to_i, value: 90.0 } - ] - ) - end - end end context 'when timezone offset is provided' do @@ -185,6 +160,45 @@ describe V2::Reports::Timeseries::AverageReportBuilder do ) end end + + context 'when weekly rollups are enabled' do + let(:group_by) { 'week' } + let(:timezone_offset) { '5.5' } + + before do + account.update!(reporting_timezone: 'Chennai') + allow(account).to receive(:feature_enabled?).with('reporting_events_rollup').and_return(true) + + create(:reporting_events_rollup, + account: account, + date: current_time.to_date - 1.day, + dimension_type: 'account', + dimension_id: account.id, + metric: 'first_response', + count: 1, + sum_value: 80.0, + sum_value_business_hours: 10.0) + + create(:reporting_events_rollup, + account: account, + date: current_time.to_date, + dimension_type: 'account', + dimension_id: account.id, + metric: 'first_response', + count: 1, + sum_value: 100.0, + sum_value_business_hours: 20.0) + end + + it 'groups weeks using sunday boundaries' do + expect(subject.timeseries).to eq( + [ + { count: 0, timestamp: (current_time - 1.week).in_time_zone('Chennai').beginning_of_week(:sunday).to_i, value: 0 }, + { count: 2, timestamp: current_time.in_time_zone('Chennai').beginning_of_week(:sunday).to_i, value: 90.0 } + ] + ) + end + end end context 'when the label filter is applied' do diff --git a/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb b/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb index 0a4f98d80..77199958f 100644 --- a/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb +++ b/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb @@ -16,12 +16,14 @@ describe V2::Reports::Timeseries::CountReportBuilder do metric: 'resolutions_count', since: since_time.beginning_of_day.to_i.to_s, until: current_time.end_of_day.to_i.to_s, + timezone_offset: timezone_offset, group_by: group_by, id: user.id.to_s } end let(:group_by) { 'day' } let(:since_time) { current_time - 1.day } + let(:timezone_offset) { nil } before do travel_to current_time @@ -106,10 +108,11 @@ describe V2::Reports::Timeseries::CountReportBuilder do let(:group_by) { 'week' } let(:current_time) { Time.zone.parse('2020-10-26 10:00:00 UTC') } let(:since_time) { current_time - 1.week } + let(:timezone_offset) { '5.5' } before do - account.update!(reporting_timezone: 'UTC') - allow(subject).to receive(:use_rollup?).and_return(true) + account.update!(reporting_timezone: 'Chennai') + allow(account).to receive(:feature_enabled?).with('reporting_events_rollup').and_return(true) create(:reporting_events_rollup, account: account, @@ -135,8 +138,8 @@ describe V2::Reports::Timeseries::CountReportBuilder do it 'groups weeks using sunday boundaries' do expect(subject.timeseries).to eq( [ - { value: 0, timestamp: (current_time - 1.week).beginning_of_week(:sunday).to_i }, - { value: 2, timestamp: current_time.beginning_of_week(:sunday).to_i } + { value: 0, timestamp: (current_time - 1.week).in_time_zone('Chennai').beginning_of_week(:sunday).to_i }, + { value: 2, timestamp: current_time.in_time_zone('Chennai').beginning_of_week(:sunday).to_i } ] ) end