feat: Group by filter in reports (#3973)

This commit is contained in:
Aswin Dev P.S
2022-02-15 03:40:49 -08:00
committed by GitHub
parent a703ef2de6
commit e6f8895c1b
14 changed files with 343 additions and 35 deletions

View File

@@ -147,6 +147,18 @@ describe ::V2::ReportBuilder do
expect(metrics[:avg_resolution_time]).to be 0
expect(metrics[:resolutions_count]).to be 0
end
it 'returns argument error for incorrect group by' do
params = {
type: :account,
since: (Time.zone.today - 3.days).to_time.to_i.to_s,
until: Time.zone.today.to_time.to_i.to_s,
group_by: 'test'.to_s
}
builder = V2::ReportBuilder.new(account, params)
expect { builder.summary }.to raise_error(ArgumentError)
end
end
context 'when report type is label' do
@@ -247,6 +259,38 @@ describe ::V2::ReportBuilder do
expect(metrics[:avg_resolution_time]).to be 0
expect(metrics[:resolutions_count]).to be 0
end
it 'returns summary for correct group by' do
params = {
type: :label,
id: label_2.id,
since: (Time.zone.today - 3.days).to_time.to_i.to_s,
until: Time.zone.today.to_time.to_i.to_s,
group_by: 'week'.to_s
}
builder = V2::ReportBuilder.new(account, params)
metrics = builder.summary
expect(metrics[:conversations_count]).to be 5
expect(metrics[:incoming_messages_count]).to be 5
expect(metrics[:outgoing_messages_count]).to be 15
expect(metrics[:avg_resolution_time]).to be 0
expect(metrics[:resolutions_count]).to be 0
end
it 'returns argument error for incorrect group by' do
params = {
type: :label,
id: label_2.id,
since: (Time.zone.today - 3.days).to_time.to_i.to_s,
until: Time.zone.today.to_time.to_i.to_s,
group_by: 'test'.to_s
}
builder = V2::ReportBuilder.new(account, params)
expect { builder.summary }.to raise_error(ArgumentError)
end
end
end
end