Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fixed API specs

Damian Legawiecb93388f06547
diff --git a/api/spec/serializers/spree/v2/storefront/product_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/product_serializer_spec.rb
index b25da88082..abc23604a9 100644
--- a/api/spec/serializers/spree/v2/storefront/product_serializer_spec.rb
+++ b/api/spec/serializers/spree/v2/storefront/product_serializer_spec.rb
@@ -44,8 +44,7 @@ describe Spree::V2::Storefront::ProductSerializer do
end
context 'with store-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
- let!(:store_rule) { create(:store_price_rule, price_list: price_list, store_ids: [other_store.id]) }
+ let!(:price_list) { create(:price_list, :active, store: other_store) }
let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 12.50, price_list: price_list) }
context 'when store matches' do
@@ -74,7 +73,7 @@ describe Spree::V2::Storefront::ProductSerializer do
end
context 'with zone-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
+ let!(:price_list) { create(:price_list, :active, store: store) }
let!(:zone_rule) { create(:zone_price_rule, price_list: price_list, zone_ids: [other_zone.id]) }
let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 15.00, price_list: price_list) }
@@ -104,7 +103,7 @@ describe Spree::V2::Storefront::ProductSerializer do
end
context 'with user-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
+ let!(:price_list) { create(:price_list, :active, store: store) }
let!(:user_rule) { create(:user_price_rule, price_list: price_list, user_ids: [user.id]) }
let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 14.00, price_list: price_list) }
@@ -134,7 +133,7 @@ describe Spree::V2::Storefront::ProductSerializer do
end
context 'with taxon-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
+ let!(:price_list) { create(:price_list, :active, store: store) }
let!(:taxon_rule) { create(:product_taxon_price_rule, price_list: price_list, taxon_ids: [taxon.id]) }
let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 11.00, price_list: price_list) }
@@ -144,18 +143,18 @@ describe Spree::V2::Storefront::ProductSerializer do
end
end
- context 'with combined rules (store AND zone)' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100, match_policy: 'all') }
- let!(:store_rule) { create(:store_price_rule, price_list: price_list, store_ids: [other_store.id]) }
+ context 'with combined rules (zone AND user)' do
+ let!(:price_list) { create(:price_list, :active, store: store, match_policy: 'all') }
let!(:zone_rule) { create(:zone_price_rule, price_list: price_list, zone_ids: [other_zone.id]) }
+ let!(:user_rule) { create(:user_price_rule, price_list: price_list, user_ids: [user.id]) }
let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 9.00, price_list: price_list) }
- context 'when both store and zone match' do
+ context 'when both zone and user match' do
let(:serializer_params) do
{
- store: other_store,
+ store: store,
currency: currency,
- user: nil,
+ user: user,
locale: locale,
price_options: { tax_zone: other_zone }
}
@@ -167,14 +166,14 @@ describe Spree::V2::Storefront::ProductSerializer do
end
end
- context 'when only store matches' do
+ context 'when only zone matches' do
let(:serializer_params) do
{
- store: other_store,
+ store: store,
currency: currency,
user: nil,
locale: locale,
- price_options: { tax_zone: zone }
+ price_options: { tax_zone: other_zone }
}
end
@@ -186,14 +185,12 @@ describe Spree::V2::Storefront::ProductSerializer do
end
context 'with multiple price lists' do
- let!(:low_priority_list) { create(:price_list, status: 'active', priority: 50) }
- let!(:high_priority_list) { create(:price_list, status: 'active', priority: 150) }
- let!(:store_rule_low) { create(:store_price_rule, price_list: low_priority_list, store_ids: [store.id]) }
- let!(:store_rule_high) { create(:store_price_rule, price_list: high_priority_list, store_ids: [store.id]) }
- let!(:low_price) { create(:price, variant: product.master, currency: currency, amount: 16.00, price_list: low_priority_list) }
- let!(:high_price) { create(:price, variant: product.master, currency: currency, amount: 10.00, price_list: high_priority_list) }
-
- it 'returns the highest priority price' do
+ let!(:second_position_list) { create(:price_list, :active, store: store, position: 2) }
+ let!(:first_position_list) { create(:price_list, :active, store: store, position: 1) }
+ let!(:second_price) { create(:price, variant: product.master, currency: currency, amount: 16.00, price_list: second_position_list) }
+ let!(:first_price) { create(:price, variant: product.master, currency: currency, amount: 10.00, price_list: first_position_list) }
+
+ it 'returns the first position price' do
expect(subject[:data][:attributes][:price]).to eq(BigDecimal('10.00'))
expect(subject[:data][:attributes][:display_price]).to eq('$10.00')
end
diff --git a/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb
index c198bfabbd..291d336120 100644
--- a/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb
+++ b/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb
@@ -48,8 +48,7 @@ describe Spree::V2::Storefront::VariantSerializer do
let(:user) { create(:user) }
context 'with store-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
- let!(:store_rule) { create(:store_price_rule, price_list: price_list, store_ids: [other_store.id]) }
+ let!(:price_list) { create(:price_list, :active, store: other_store) }
let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 7.50, price_list: price_list) }
context 'when store matches' do
@@ -78,7 +77,7 @@ describe Spree::V2::Storefront::VariantSerializer do
end
context 'with zone-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
+ let!(:price_list) { create(:price_list, :active, store: store) }
let!(:zone_rule) { create(:zone_price_rule, price_list: price_list, zone_ids: [other_zone.id]) }
let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 8.00, price_list: price_list) }
@@ -108,7 +107,7 @@ describe Spree::V2::Storefront::VariantSerializer do
end
context 'with user-specific pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100) }
+ let!(:price_list) { create(:price_list, :active, store: store) }
let!(:user_rule) { create(:user_price_rule, price_list: price_list, user_ids: [user.id]) }
let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 6.50, price_list: price_list) }
@@ -138,21 +137,19 @@ describe Spree::V2::Storefront::VariantSerializer do
end
context 'with multiple price lists' do
- let!(:low_priority_list) { create(:price_list, status: 'active', priority: 50) }
- let!(:high_priority_list) { create(:price_list, status: 'active', priority: 100) }
- let!(:store_rule_low) { create(:store_price_rule, price_list: low_priority_list, store_ids: [store.id]) }
- let!(:store_rule_high) { create(:store_price_rule, price_list: high_priority_list, store_ids: [store.id]) }
- let!(:low_price) { create(:price, variant: variant, currency: currency, amount: 8.00, price_list: low_priority_list) }
- let!(:high_price) { create(:price, variant: variant, currency: currency, amount: 5.00, price_list: high_priority_list) }
-
- it 'returns the highest priority price' do
+ let!(:second_position_list) { create(:price_list, :active, store: store, position: 2) }
+ let!(:first_position_list) { create(:price_list, :active, store: store, position: 1) }
+ let!(:second_price) { create(:price, variant: variant, currency: currency, amount: 8.00, price_list: second_position_list) }
+ let!(:first_price) { create(:price, variant: variant, currency: currency, amount: 5.00, price_list: first_position_list) }
+
+ it 'returns the first position price' do
expect(subject[:data][:attributes][:price]).to eq(BigDecimal('5.00'))
expect(subject[:data][:attributes][:display_price]).to eq('$5.00')
end
end
context 'with date-based pricing' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100, starts_at: 1.day.ago, ends_at: 1.day.from_now) }
+ let!(:price_list) { create(:price_list, :active, store: store, starts_at: 1.day.ago, ends_at: 1.day.from_now) }
let!(:date_rule) { create(:date_range_price_rule, price_list: price_list, starts_at: 1.day.ago, ends_at: 1.day.from_now) }
let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 7.00, price_list: price_list) }
@@ -162,7 +159,7 @@ describe Spree::V2::Storefront::VariantSerializer do
end
context 'when outside date range' do
- let!(:price_list) { create(:price_list, status: 'active', priority: 100, starts_at: 2.days.from_now, ends_at: 3.days.from_now) }
+ let!(:price_list) { create(:price_list, :active, store: store, starts_at: 2.days.from_now, ends_at: 3.days.from_now) }
it 'returns the base price' do
expect(subject[:data][:attributes][:price]).to eq(BigDecimal(10))
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 076699d48f..57a3860f3f 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -1694,9 +1694,6 @@ en:
product_taxon_rule:
description: Apply pricing to products in specific categories
name: Product Category
- store_rule:
- description: Apply different pricing per store
- name: Store
user_rule:
description: Apply pricing to specific customers
name: User
diff --git a/storefront/spec/helpers/spree/products_helper_spec.rb b/storefront/spec/helpers/spree/products_helper_spec.rb
index 1b764efb79..540ce6b08e 100644
--- a/storefront/spec/helpers/spree/products_helper_spec.rb
+++ b/storefront/spec/helpers/spree/products_helper_spec.rb
@@ -135,8 +135,10 @@ describe Spree::ProductsHelper, type: :helper do
end
context 'with a product' do
+ let(:product_with_compare_at_price) { create(:product, price: 10, compare_at_price: 15) }
+
it 'uses the default variant' do
- expect(helper.should_display_compare_at_price?(product)).to be true
+ expect(helper.should_display_compare_at_price?(product_with_compare_at_price)).to be true
end
end
end