Skip to content

Commit

Permalink
Improve test coverage for the Views & Navigation processor
Browse files Browse the repository at this point in the history
`ga_response_with_govuk_prefix` has not been used in any of the tests and
looks like it has been missed previously. We should expect paths that
contain the gov.uk prefix to be transformed into it's base path. If an
an event already exists with the same path in the Events::GA table, it
should update the entry with the aggregative total for the metrics which is
then reflected in the Facts::Metrics table.
  • Loading branch information
deborahchua committed Jan 5, 2024
1 parent e040577 commit 8ebd99f
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions spec/domain/etl/ga/views_and_navigation_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
before { allow(Etl::GA::ViewsAndNavigationService).to receive(:find_in_batches).and_yield(ga_response) }

it "update the facts with the GA metrics" do
fact1 = create :metric,
edition: edition1,
date: "2018-02-20"
fact1 = create :metric, edition: edition1, date: "2018-02-20"
fact2 = create :metric, edition: edition2, date: "2018-02-20"

described_class.process(date:)
Expand Down Expand Up @@ -68,6 +66,58 @@
end
end

context "When the GA path contains the gov.uk prefix" do
before { allow(Etl::GA::ViewsAndNavigationService).to receive(:find_in_batches).and_yield(ga_response_with_govuk_prefix) }

context "when an event does not already exist with the same page_path" do
it "updates the fact with the GA metrics" do
fact1 = create :metric, edition: edition1, date: "2018-02-20"

described_class.process(date:)

expect(fact1.reload).to have_attributes(pviews: 1, upviews: 1)
end
end

context "when an event already exists with the same page_path" do
before do
create(:ga_event, :with_views, date: "2018-02-20", page_path: "/path1")
end

it "updates the fact with the aggregated GA metrics" do
fact1 = create :metric, edition: edition1, date: "2018-02-20"

described_class.process(date:)

expect(fact1.reload).to have_attributes(pviews: 11, upviews: 6)
end

it "does not update metrics for other days" do
fact1 = create :metric, edition: edition1, date: "2018-02-20", pviews: 20, upviews: 10

day_before = date - 1
described_class.process(date: day_before)

expect(fact1.reload).to have_attributes(pviews: 20, upviews: 10)
end

it "does not update metrics for other items" do
edition = create :edition, base_path: "/non-matching-path", date: "2018-02-20"
fact = create :metric, edition:, date: "2018-02-20", pviews: 99, upviews: 90

described_class.process(date:)

expect(fact.reload).to have_attributes(pviews: 99, upviews: 90)
end

it "deletes events after updating facts metrics" do
described_class.process(date:)

expect(Events::GA.count).to eq(0)
end
end
end

it_behaves_like "traps and logs errors in process", Etl::GA::ViewsAndNavigationService, :find_in_batches

private
Expand Down

0 comments on commit 8ebd99f

Please sign in to comment.