Skip to content

Commit

Permalink
Add specs for filtering in taxons/products endpoint
Browse files Browse the repository at this point in the history
It also adds basic specs to this endpoint since it was also
having a spec related to caching, probably a regression of
some problem from the past.
  • Loading branch information
kennyadsl committed Jul 6, 2021
1 parent 33fe5dc commit 31607ca
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions api/spec/requests/spree/api/taxons_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,58 @@ module Spree
assert_unauthorized!
end

context "with caching enabled" do
let!(:product) { create(:product, taxons: [taxon]) }

context "getting all products into a taxon" do
before do
ActionController::Base.perform_caching = true
create_list(:product, 2, taxons: [taxon])
end

it "handles exclude_data correctly" do
it "returns all the products with detailed information" do
get spree.api_taxon_products_path, params: { id: taxon.id }
expect(response).to be_successful

expect(json_response["products"].size).to eq(2)
expect(json_response["products"][0]["description"]).not_to be_nil
end

it "returns a simplified json response when simple: true is passed" do
get spree.api_taxon_products_path, params: { id: taxon.id, simple: true }
expect(response).to be_successful
simple_response = json_response

get spree.api_taxon_products_path, params: { id: taxon.id }
expect(json_response["products"].size).to eq(2)
expect(json_response["products"][0]["description"]).to be_nil
end

it "can query the resulting products through a parameter" do
create(:product, name: 'Watch', taxons: [taxon])

get spree.api_taxon_products_path, params: { id: taxon.id, q: { name_eq: 'Watch' } }
expect(response).to be_successful
full_response = json_response

expect(simple_response["products"][0]["description"]).to be_nil
expect(full_response["products"][0]["description"]).not_to be_nil
expect(json_response["products"].size).to eq(1)
expect(json_response["products"][0]["name"]).to eq "Watch"
end

after do
ActionController::Base.perform_caching = false
context "with caching enabled" do
before do
ActionController::Base.perform_caching = true
end

it "handles exclude_data correctly" do
get spree.api_taxon_products_path, params: { id: taxon.id, simple: true }
expect(response).to be_successful
simple_response = json_response

get spree.api_taxon_products_path, params: { id: taxon.id }
expect(response).to be_successful
full_response = json_response

expect(simple_response["products"][0]["description"]).to be_nil
expect(full_response["products"][0]["description"]).not_to be_nil
end

after do
ActionController::Base.perform_caching = false
end
end
end
end
Expand Down

0 comments on commit 31607ca

Please sign in to comment.