Skip to content

Commit

Permalink
Pass AB params to Search::Query
Browse files Browse the repository at this point in the history
The ab_params is only needed to determine which version of search-api to call. It will not need be needed in search-api itself.

Rather than updating all of the tests to stub passing in the ab_params the ab_params argument is no longer being passed to the QueryBuilder because that would require updating all of the tests to stub passing the ab_params to search-api.

Uses "anything" as an RSpec matcher. This is a positional argument that allows you specify "anything"
if you don't care what the other arguments are.
  • Loading branch information
leenagupte committed Dec 13, 2023
1 parent edda1b1 commit db274c7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/controllers/ab_tests/vertex_search_ab_testable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ def set_requested_variant
@requested_variant.configure_response(response)
end

def ab_params
{ vertex: @requested_variant.variant_name }
end
end
2 changes: 1 addition & 1 deletion app/controllers/finders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def initialize_search_query(is_for_feed: false)
content_item,
filter_params,
override_sort_for_feed: is_for_feed,
ab_params: {},
ab_params: page_under_test? ? ab_params : {},
)
end

Expand Down
1 change: 0 additions & 1 deletion app/lib/search/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def fetch_search_response(content_item)
queries = QueryBuilder.new(
finder_content_item: content_item,
params: filter_params,
ab_params:,
override_sort_for_feed:,
).call

Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@
expect(response.header["Vary"]).not_to eq("GOVUK-ABTest-VertexSearch")
expect(response.body).not_to include("VertexSearch:#{variant}")
end

it "sends ab_params to search query if page is being tested" do
stub_content_store_has_item(
"/search/all",
all_content_finder,
)

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

expect(Search::Query).to receive(:new).with(anything, anything, hash_including(ab_params: { vertex: variant })).and_call_original

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

it "should render the page without an AB test variant for search" do
Expand Down

0 comments on commit db274c7

Please sign in to comment.