From 5af33a63dd1fd6bc741a8d99d9ef11a8e42f894e Mon Sep 17 00:00:00 2001 From: rhymes Date: Thu, 29 Apr 2021 15:54:21 +0200 Subject: [PATCH] [Search 2.0] Remove search_2_listings, search_2_usernames feature flags (#13578) * Remove search_2_listings feature flag * Remove search_2_usernames feature flag --- app/controllers/search_controller.rb | 25 +++----- spec/requests/search_spec.rb | 94 ++++++++-------------------- 2 files changed, 32 insertions(+), 87 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 8649cdf37..c8bce729f 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -82,17 +82,12 @@ class SearchController < ApplicationController end def listings - result = - if FeatureFlag.enabled?(:search_2_listings) - Search::Postgres::Listing.search_documents( - category: listing_params[:category], - page: listing_params[:page], - per_page: listing_params[:per_page], - term: listing_params[:listing_search], - ) - else - Search::Listing.search_documents(params: listing_params.to_h) - end + result = Search::Postgres::Listing.search_documents( + category: listing_params[:category], + page: listing_params[:page], + per_page: listing_params[:per_page], + term: listing_params[:listing_search], + ) render json: { result: result } end @@ -102,15 +97,9 @@ class SearchController < ApplicationController end def usernames - result = if FeatureFlag.enabled?(:search_2_usernames) - Search::Postgres::Username.search_documents(params[:username]) - else - Search::User.search_usernames(params[:username]) - end + result = Search::Postgres::Username.search_documents(params[:username]) render json: { result: result } - rescue Search::Errors::Transport::BadRequest - render json: { result: [] } end # TODO: [@rhymes] the homepage feed uses `feed_content_search` as an index, diff --git a/spec/requests/search_spec.rb b/spec/requests/search_spec.rb index bce4d2013..9d731dc1c 100644 --- a/spec/requests/search_spec.rb +++ b/spec/requests/search_spec.rb @@ -39,43 +39,23 @@ RSpec.describe "Search", type: :request, proper_status: true do end describe "GET /search/listings" do - context "when using Elasticsearch" do - let(:mock_documents) do - [{ "title" => "listing1" }] - end - - it "returns json" do - allow(Search::Listing).to receive(:search_documents).and_return( - mock_documents, - ) - get "/search/listings" - expect(response.parsed_body).to eq("result" => mock_documents) - end + it "returns the correct keys" do + create(:listing) + get search_listings_path + expect(response.parsed_body["result"]).to be_present end - context "when using PostgreSQL" do - before do - allow(FeatureFlag).to receive(:enabled?).with(:search_2_listings).and_return(true) - end + it "supports the search params" do + listing = create(:listing) - it "returns the correct keys" do - create(:listing) - get search_listings_path - expect(response.parsed_body["result"]).to be_present - end + get search_listings_path( + category: listing.category, + page: 0, + per_page: 1, + term: listing.title.downcase, + ) - it "supports the search params" do - listing = create(:listing) - - get search_listings_path( - category: listing.category, - page: 0, - per_page: 1, - term: listing.title.downcase, - ) - - expect(response.parsed_body["result"].first).to include("title" => listing.title) - end + expect(response.parsed_body["result"].first).to include("title" => listing.title) end end @@ -96,49 +76,25 @@ RSpec.describe "Search", type: :request, proper_status: true do sign_in authorized_user end - context "when using Elasticsearch" do - let(:result) do - { - "username" => "molly", - "name" => "Molly", - "profile_image_90" => "something" - } - end - - it "returns json" do - allow(Search::User).to receive(:search_usernames).and_return( - result, - ) - get search_usernames_path - expect(response.parsed_body).to eq("result" => result) - end + it "returns nothing if there is no username parameter" do + get search_usernames_path + expect(response.parsed_body["result"]).to be_empty end - context "when using PostgreSQL" do - before do - allow(FeatureFlag).to receive(:enabled?).with(:search_2_usernames).and_return(true) - end + it "finds a username by a partial username" do + user = create(:user, username: "Sloan") - it "returns nothing if there is no username parameter" do - get search_usernames_path - expect(response.parsed_body["result"]).to be_empty - end + get search_usernames_path(username: "slo") - it "finds a username by a partial username" do - user = create(:user, username: "Sloan") + expect(response.parsed_body["result"].first).to include("username" => user.username) + end - get search_usernames_path(username: "slo") + it "finds a username by a partial name" do + user = create(:user, name: "Sloan") - expect(response.parsed_body["result"].first).to include("username" => user.username) - end + get search_usernames_path(username: "slo") - it "finds a username by a partial name" do - user = create(:user, name: "Sloan") - - get search_usernames_path(username: "slo") - - expect(response.parsed_body["result"].first).to include("username" => user.username) - end + expect(response.parsed_body["result"].first).to include("username" => user.username) end end