Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate AA test ElasticSearch 6.7 #3135

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,6 +25,7 @@
<% end %>
<meta name="govuk:base_title" content="<%= yield :meta_title %> - GOV.UK">
<meta name="govuk:scroll-tracker" content="" data-module="ga4-scroll-tracker"/>
<%= yield :meta_tags %>
</head>

<body class="<%= yield :body_classes %>">
Expand Down
46 changes: 46 additions & 0 deletions spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,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