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
Fix SDK integration failure from the seeded pickup method
Damian Legawiecb9179cf95b8b
diff --git a/packages/sdk/tests/integration/helpers.ts b/packages/sdk/tests/integration/helpers.tsindex a0268bce7a..35685832b6 100644--- a/packages/sdk/tests/integration/helpers.ts+++ b/packages/sdk/tests/integration/helpers.ts@@ -57,11 +57,16 @@ export async function buildCart(throughStep: 'item' | 'address' | 'delivery' | 'if (throughStep === 'address') return { c, cart: withAddr, opts, creds }const ful = withAddr.fulfillments[0]+ // Rates come back cheapest first, and the seeded store offers free store+ // pickup — so the first rate costs nothing. Pick a paid one, since callers+ // assert that choosing a rate moves the delivery total.+ const paidRate = ful.delivery_rates.find((rate) => Number(rate.cost) > 0)+ const chosenRate = paidRate ?? ful.delivery_rates[0]const withRate = await c.carts.fulfillments.update(cart.id,ful.id,{- selected_delivery_rate_id: ful.delivery_rates[0].id,+ selected_delivery_rate_id: chosenRate.id,},opts,)diff --git a/spree/core/app/services/spree/seeds/stock_locations.rb b/spree/core/app/services/spree/seeds/stock_locations.rbindex fcbbe3c621..1ef2242ce9 100644--- a/spree/core/app/services/spree/seeds/stock_locations.rb+++ b/spree/core/app/services/spree/seeds/stock_locations.rb@@ -5,14 +5,19 @@ module Spreedef callSpree::Store.all.find_each do |store|- Spree::StockLocation.find_or_create_by!(+ # Match on identity alone. Folding the other attributes into the+ # finder made re-seeding fail once anything edited them (the pickup+ # seed enabling collection, a merchant flipping a flag): the lookup+ # missed the existing row and tried to create a duplicate name.+ Spree::StockLocation.where(store: store,- name: Spree.t(:default_stock_location_name),- propagate_all_variants: false,- country: store.default_country,- active: true,- default: true- )+ name: Spree.t(:default_stock_location_name)+ ).first_or_create! do |stock_location|+ stock_location.propagate_all_variants = false+ stock_location.country = store.default_country+ stock_location.active = true+ stock_location.default = true+ endendendenddiff --git a/spree/core/spec/services/spree/seeds/all_spec.rb b/spree/core/spec/services/spree/seeds/all_spec.rbindex cfcd3bed7e..111ab81ad1 100644--- a/spree/core/spec/services/spree/seeds/all_spec.rb+++ b/spree/core/spec/services/spree/seeds/all_spec.rb@@ -7,6 +7,19 @@ RSpec.describe Spree::Seeds::All doexpect { subject }.not_to raise_errorend+ # CI seeds a fresh app and re-seeds on rerun; a seed whose finder includes+ # mutable attributes stops matching once anything edits them and then tries+ # to create a duplicate.+ it 'is idempotent when the seeded data has since been edited' do+ subject++ store = Spree::Store.find_by(default: true)+ store.stock_locations.update_all(pickup_enabled: true, active: false)++ expect { described_class.call }.not_to raise_error+ expect(store.stock_locations.where(name: Spree.t(:default_stock_location_name)).count).to eq(1)+ end+# Store-scoped seeds iterate `Spree::Store.all`, so one ordered before# `Stores` silently creates nothing on a fresh install. The per-seed specs# can't catch it — they run against a suite that already has a store.