style: rubcop issues

This commit is contained in:
Shivam Mishra
2026-03-09 12:55:49 +05:30
parent 8324d84fbf
commit d86c8d1ede
2 changed files with 71 additions and 54 deletions
@@ -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
@@ -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