Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
add specs for filtering by properties in Products::Find
Łukasz Adamczyk825db9416751
diff --git a/core/lib/spree/testing_support/factories/property_factory.rb b/core/lib/spree/testing_support/factories/property_factory.rbindex 2d6c148992..084f8116c1 100644--- a/core/lib/spree/testing_support/factories/property_factory.rb+++ b/core/lib/spree/testing_support/factories/property_factory.rb@@ -8,5 +8,17 @@ FactoryBot.define dopresentation { 'Brand' }filter_param { 'brand' }end++ trait :manufacturer do+ name { 'manufacturer' }+ presentation { 'Manufacturer' }+ filter_param { 'manufacturer' }+ end++ trait :material do+ name { 'material' }+ presentation { 'Material' }+ filter_param { 'material' }+ endendenddiff --git a/core/spec/finders/spree/products/find_spec.rb b/core/spec/finders/spree/products/find_spec.rbindex 64a8d12624..2a9cf49ece 100644--- a/core/spec/finders/spree/products/find_spec.rb+++ b/core/spec/finders/spree/products/find_spec.rb@@ -270,6 +270,77 @@ module Spreeendend+ describe 'filter by properties' do+ subject(:products) do+ described_class.new(+ scope: Spree::Product.all,+ params: params,+ current_currency: 'USD'+ ).execute+ end++ let(:params) do+ { filter: { properties: ActionController::Parameters.new(properties_param) } }+ end++ let(:brand) { create(:property, :brand) }+ let(:manufacturer) { create(:property, :manufacturer) }+ let(:material) { create(:property, :material) }++ let!(:product_1) do+ create(+ :product,+ product_properties: [+ create(:product_property, property: brand, value: 'Alpha'),+ create(:product_property, property: manufacturer, value: 'Wilson'),+ create(:product_property, property: manufacturer, value: 'Wannabe')+ ]+ )+ end++ let!(:product_2) do+ create(+ :product,+ product_properties: [+ create(:product_property, property: brand, value: 'Beta'),+ create(:product_property, property: manufacturer, value: 'Jerseys')+ ]+ )+ end++ let(:product_3) do+ create(+ :product,+ product_properties: [+ create(:product_property, property: brand, value: 'Alpha'),+ create(:product_property, property: brand, value: 'Gamma')+ ]+ )+ end++ before do+ create(:product, product_properties: [create(:product_property, property: manufacturer, value: 'Jerseys')])+ create(:product, product_properties: [create(:product_property, property: manufacturer, value: 'Wilson')])+ create(:product, product_properties: [create(:product_property, property: material, value: '100% Cotton')])+ end++ context 'when filtering by one Property' do+ let(:properties_param) { { brand: 'alpha,beta,gamma' } }++ it 'finds Products matching any of Property values' do+ expect(products).to contain_exactly(product_1, product_2, product_3)+ end+ end++ context 'when filtering by many Properties' do+ let(:properties_param) { { brand: 'alpha,beta,gamma', manufacturer: 'wilson,jerseys' } }++ it 'finds Products matching any of Property values, but for all given Properties' do+ expect(products).to contain_exactly(product_1, product_2)+ end+ end+ end+context 'ordered' docontext 'default' dosubject(:products) do