Skip to content

Commit

Permalink
Merge pull request #3053 from alphagov/aa-test-es-6.7
Browse files Browse the repository at this point in the history
AA test for Search Results
  • Loading branch information
Rosa-Fox authored Jul 18, 2023
2 parents 22eee2e + 397fe1e commit 3f11092
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/controllers/ab_tests/elastic_search_aa_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module AbTests::ElasticSearchAaTestable
def elastic_search_aa_test
GovukAbTesting::AbTest.new(
"EsSixPointSeven",
dimension: 41,
allowed_variants: %w[A B Z],
control_variant: "Z",
)
end

def page_under_test?
request.path.include?("/search/all")
end

def set_requested_variant
@requested_variant = elastic_search_aa_test.requested_variant(request.headers)
@requested_variant.configure_response(response)
end
end
7 changes: 6 additions & 1 deletion app/controllers/finders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FindersController < ApplicationController
layout "finder_layout"
include AbTests::ElasticSearchAaTestable

before_action do
set_expiry(content_item)
Expand All @@ -8,6 +9,10 @@ class FindersController < ApplicationController
def show
slimmer_template "gem_layout_full_width" if i_am_a_topic_page_finder

if page_under_test?
set_requested_variant
end

respond_to do |format|
format.html do
raise UnsupportedContentItem unless content_item.is_finder?
Expand Down Expand Up @@ -58,7 +63,7 @@ class UnsupportedContentItem < StandardError; end

attr_reader :search_query

helper_method :facet_tags, :i_am_a_topic_page_finder, :result_set_presenter, :content_item, :signup_links, :filter_params, :facets
helper_method :facet_tags, :i_am_a_topic_page_finder, :result_set_presenter, :content_item, :signup_links, :filter_params, :facets, :page_under_test?

def redirect_to_destination
@redirect = content_item.redirect
Expand Down
6 changes: 6 additions & 0 deletions app/views/finders/_show_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<% end %>
</div>

<% if page_under_test? %>
<% content_for :meta_tags do %>
<%= @requested_variant.analytics_meta_tag.html_safe %>
<% end %>
<% end %>
<% if content_item.summary %>
<div class="govuk-grid-column-two-thirds">
<div class="metadata-summary ">
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/finder_layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<meta name="robots" content="noindex">
<% end %>
<meta name="govuk:base_title" content="<%= yield :meta_title %> - GOV.UK">
<%= yield :meta_tags %>
</head>

<body class="<%= yield :body_classes %>">
Expand Down
47 changes: 47 additions & 0 deletions spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
after { Rails.cache.clear }

describe "GET show" do
render_views
describe "a finder content item exists" do
before do
stub_content_store_has_item(
Expand Down Expand Up @@ -108,6 +109,52 @@
get :show, params: { slug: "lunch-finder" }
expect(response.status).to eq(406)
end

context "with AA test" do
%w[A B Z].each do |variant|
it "renders the #{variant} variant for /search/all pages" do
stub_content_store_has_item(
"/search/all",
all_content_finder,
)

@request.headers["GOVUK-ABTest-EsSixPointSeven"] = variant

get :show, params: { slug: "search/all" }

expect(response.header["Vary"]).to eq("GOVUK-ABTest-EsSixPointSeven")
expect(response.body).to include("EsSixPointSeven:#{variant}")
end

it "doesn't render the #{variant} for finders" do
stub_content_store_has_item(
"/lunch-finder",
lunch_finder,
)

@request.headers["GOVUK-ABTest-EsSixPointSeven"] = variant

get :show, params: { slug: "lunch-finder" }

expect(response.status).to eq(200)
expect(response.header["Vary"]).not_to eq("GOVUK-ABTest-EsSixPointSeven")
expect(response.body).not_to include("EsSixPointSeven:#{variant}")
end
end

it "should render the page without an AB test variant for search" do
stub_content_store_has_item(
"/search/all",
all_content_finder,
)

get :show, params: { slug: "search/all" }

expect(response.status).to eq(200)
expect(response.header["Vary"]).to eq("GOVUK-ABTest-EsSixPointSeven")
expect(response.body).not_to include("<meta name=\"govuk:ab-test\">")
end
end
end

describe "a finder content item with a default order exists" do
Expand Down

0 comments on commit 3f11092

Please sign in to comment.