fix: Handle invalid metric in ReportsController (#8086)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>

Fixes CW-2643
This commit is contained in:
Vishnu Narayanan
2023-10-12 17:01:23 +05:30
committed by GitHub
parent 9e173fca3c
commit 415bb23c37
2 changed files with 42 additions and 1 deletions

View File

@@ -171,6 +171,34 @@ describe V2::ReportBuilder do
builder = described_class.new(account, params)
expect { builder.timeseries }.to raise_error(ArgumentError)
end
it 'logs error when metric is nil' do
params = {
metric: nil, # Set metric to nil to test this case
type: :account,
since: (Time.zone.today - 3.days).to_time.to_i.to_s,
until: Time.zone.today.end_of_day.to_time.to_i.to_s
}
builder = described_class.new(account, params)
expect(Rails.logger).to receive(:error).with('ReportBuilder: Invalid metric - ')
builder.timeseries
end
it 'calls the appropriate metric method for a valid metric' do
params = {
metric: 'not_conversation_count', # Provide a invalid metric
type: :account,
since: (Time.zone.today - 3.days).to_time.to_i.to_s,
until: Time.zone.today.end_of_day.to_time.to_i.to_s
}
builder = described_class.new(account, params)
expect(Rails.logger).to receive(:error).with('ReportBuilder: Invalid metric - not_conversation_count')
builder.timeseries
end
end
context 'when report type is label' do