docbrown/spec/requests/search_spec.rb
Alex 832f59ff6d
Search ClassifiedListings frontend code (#6372) [deploy]
* Add /search/classified_listings route

* Add classified_listings search controller action

* Add spec for /search/classified_listings request

* Begin implementing frontend code

* Add debounce to classified_listings search

* before_action to format page & per_page as Integer

* Use new fetchSearch helper to fix codeclimate

* Refactor to reduce listingSearch function length

* Refactor into separate updateListings function

* Move updateListings function outside class

* Move page size to constant

* Add brackets to conditionals

* Add comment for tags param

* Add JS doc

* Move params logic/cleanup to search_controller

* Move listingIDs to const

* Rename remove_blank_params & move to before_action
2020-03-03 14:13:40 -08:00

58 lines
1.7 KiB
Ruby

require "rails_helper"
RSpec.describe "Search", type: :request, proper_status: true do
describe "GET /search/tags" do
let(:authorized_user) { create(:user) }
let(:mock_documents) do
[{ "name" => "tag1" }, { "name" => "tag2" }, { "name" => "tag3" }]
end
it "returns json" do
sign_in authorized_user
allow(Search::Tag).to receive(:search_documents).and_return(
mock_documents,
)
get "/search/tags"
expect(response.parsed_body).to eq("result" => mock_documents)
end
it "returns an empty array when a Bad Request error is raised" do
sign_in authorized_user
allow(Search::Client).to receive(:search).and_raise(Search::Errors::Transport::BadRequest)
get "/search/tags"
expect(response.parsed_body).to eq("result" => [])
end
end
describe "GET /search/chat_channels" do
let(:authorized_user) { create(:user) }
let(:mock_documents) do
[{ "channel_name" => "channel1" }]
end
it "returns json" do
sign_in authorized_user
allow(Search::ChatChannelMembership).to receive(:search_documents).and_return(
mock_documents,
)
get "/search/chat_channels"
expect(response.parsed_body).to eq("result" => mock_documents)
end
end
describe "GET /search/classified_listings" do
let(:authorized_user) { create(:user) }
let(:mock_documents) do
[{ "title" => "classified_listing1" }]
end
it "returns json" do
sign_in authorized_user
allow(Search::ClassifiedListing).to receive(:search_documents).and_return(
mock_documents,
)
get "/search/classified_listings"
expect(response.parsed_body).to eq("result" => mock_documents)
end
end
end