FIX: Blank "Legacy Pageviews" report showed no data (#29502)

Followup bd4e8422fe

In the previous commit, we introduced the `page_view_legacy_total_reqs`
report. However this was not tested properly, and due to a typo
the report returned no data.

This commit fixes the issue and adds a spec to catch this.
This commit is contained in:
Martin Brennan 2024-10-31 12:51:29 +10:00 committed by GitHub
parent dc96b6e953
commit 1c717f733c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 1 deletions

View File

@ -311,7 +311,7 @@ class Report
# This is a separate report because if people have switched over
# to _not_ use legacy pageviews, we want to show both a Pageviews
# and Legacy Pageviews report.
elsif filter == :page_view_legacy_total_reqs
elsif filter == :page_view_legacy_total
legacy_page_view_requests
else
ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])

View File

@ -312,6 +312,49 @@ RSpec.describe Report do
end
end
describe "page_view_legacy_total_reqs" do
before do
freeze_time(Time.now.at_midnight)
Theme.clear_default!
end
let(:report) { Report.find("page_view_legacy_total_reqs") }
context "with no data" do
it "works" do
expect(report.data).to be_empty
end
end
context "with data" do
before do
CachedCounting.reset
CachedCounting.enable
ApplicationRequest.enable
end
after do
CachedCounting.reset
ApplicationRequest.disable
CachedCounting.disable
end
it "works and does not count browser or mobile pageviews" do
3.times { ApplicationRequest.increment!(:page_view_crawler) }
8.times { ApplicationRequest.increment!(:page_view_logged_in) }
6.times { ApplicationRequest.increment!(:page_view_logged_in_browser) }
2.times { ApplicationRequest.increment!(:page_view_logged_in_mobile) }
2.times { ApplicationRequest.increment!(:page_view_anon) }
1.times { ApplicationRequest.increment!(:page_view_anon_browser) }
4.times { ApplicationRequest.increment!(:page_view_anon_mobile) }
CachedCounting.flush
expect(report.data.sum { |r| r[:y] }).to eq(13)
end
end
end
describe "page_view_total_reqs" do
before do
freeze_time(Time.now.at_midnight)