mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Fix property filters and improve test coverage
This commit is contained in:
@@ -57,7 +57,7 @@ Darkswarm.controller "ProductsCtrl", ($scope, $filter, $rootScope, Products, Ord
|
||||
page: page || $scope.page,
|
||||
per_page: $scope.per_page,
|
||||
'q[name_or_meta_keywords_or_supplier_name_cont]': $scope.query,
|
||||
'q[properites_in_any][]': $scope.activeProperties,
|
||||
'q[properties_id_in_any][]': $scope.activeProperties,
|
||||
'q[primary_taxon_id_in_any][]': $scope.activeTaxons
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,9 @@ module Api
|
||||
end
|
||||
|
||||
def permitted_ransack_params
|
||||
[:name_or_meta_keywords_or_supplier_name_cont, :properites_in_any, :primary_taxon_id_in_any]
|
||||
[:name_or_meta_keywords_or_supplier_name_cont,
|
||||
:properties_id_in_any,
|
||||
:primary_taxon_id_in_any]
|
||||
end
|
||||
|
||||
def distributor
|
||||
|
||||
@@ -29,7 +29,6 @@ module Api
|
||||
it "loads products for distributed products in the order cycle" do
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id
|
||||
|
||||
product_ids = json_response.map{ |product| product['id'] }
|
||||
expect(product_ids).to include product1.id, product2.id, product3.id
|
||||
end
|
||||
|
||||
@@ -57,11 +56,30 @@ module Api
|
||||
it "does not return products where the variant overrides are out of stock" do
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id
|
||||
|
||||
product_ids = json_response.map{ |product| product['id'] }
|
||||
expect(product_ids).to_not include product2.id
|
||||
end
|
||||
end
|
||||
|
||||
context "with property filters" do
|
||||
it "filters by product property" do
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id,
|
||||
q: { properties_id_in_any: [property1.id, property2.id] }
|
||||
|
||||
expect(product_ids).to include product1.id, product2.id
|
||||
expect(product_ids).to_not include product3.id
|
||||
end
|
||||
end
|
||||
|
||||
context "with taxon filters" do
|
||||
it "filters by taxon" do
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id,
|
||||
q: { primary_taxon_id_in_any: [taxon2.id] }
|
||||
|
||||
expect(product_ids).to include product2.id, product3.id
|
||||
expect(product_ids).to_not include product1.id, product4.id
|
||||
end
|
||||
end
|
||||
|
||||
context "when tag rules apply" do
|
||||
let!(:vo1) {
|
||||
create(:variant_override,
|
||||
@@ -105,7 +123,6 @@ module Api
|
||||
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id
|
||||
|
||||
product_ids = json_response.map{ |product| product['id'] }
|
||||
expect(product_ids).to_not include product1.id
|
||||
end
|
||||
|
||||
@@ -115,7 +132,6 @@ module Api
|
||||
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id
|
||||
|
||||
product_ids = json_response.map{ |product| product['id'] }
|
||||
expect(product_ids).to_not include product2.id
|
||||
end
|
||||
|
||||
@@ -126,7 +142,6 @@ module Api
|
||||
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id
|
||||
|
||||
product_ids = json_response.map{ |product| product['id'] }
|
||||
expect(product_ids).to_not include product1.id
|
||||
expect(product_ids).to include product3.id
|
||||
end
|
||||
@@ -154,5 +169,11 @@ module Api
|
||||
expect(properties).to include property1.presentation, property2.presentation
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def product_ids
|
||||
json_response.map{ |product| product['id'] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user