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 flaky tests: handle prefixed IDs and non-deterministic positions (#13547)
Damian Legawiec83ffd6eef21a
diff --git a/admin/spec/controllers/spree/admin/products_controller_spec.rb b/admin/spec/controllers/spree/admin/products_controller_spec.rbindex 2a87e9cc62..1d625a384c 100644--- a/admin/spec/controllers/spree/admin/products_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/products_controller_spec.rb@@ -1459,8 +1459,11 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller doit 'assigns the product positions on the taxon list' dosend_request- expect(product.reload.classifications.last.position).to eq(1)- expect(product2.reload.classifications.last.position).to eq(2)+ positions = [+ product.reload.classifications.find_by(taxon: category).position,+ product2.reload.classifications.find_by(taxon: category).position+ ]+ expect(positions).to contain_exactly(1, 2)endit 'touches the products' dodiff --git a/core/app/subscribers/spree/product_metrics_subscriber.rb b/core/app/subscribers/spree/product_metrics_subscriber.rbindex 2813cfcc90..854da77f29 100644--- a/core/app/subscribers/spree/product_metrics_subscriber.rb+++ b/core/app/subscribers/spree/product_metrics_subscriber.rb@@ -13,16 +13,16 @@ module Spreedef refresh_product_metrics(event)order_id = event.payload['id']- store_id = event.payload['store_id']- return unless order_id && store_id+ return unless order_id- order = Spree::Order.find_by(id: order_id)+ order = Spree::Order.find_by_param(order_id)return unless order+ return unless order.store_idproduct_ids = order.line_items.includes(:variant).map { |li| li.variant.product_id }.uniqreturn if product_ids.empty?- jobs = product_ids.map { |product_id| Spree::Products::RefreshMetricsJob.new(product_id, store_id) }+ jobs = product_ids.map { |product_id| Spree::Products::RefreshMetricsJob.new(product_id, order.store_id) }ActiveJob.perform_all_later(jobs)endenddiff --git a/core/spec/subscribers/spree/product_metrics_subscriber_spec.rb b/core/spec/subscribers/spree/product_metrics_subscriber_spec.rbindex b9b13c79eb..a0ce9653e4 100644--- a/core/spec/subscribers/spree/product_metrics_subscriber_spec.rb+++ b/core/spec/subscribers/spree/product_metrics_subscriber_spec.rb@@ -65,11 +65,17 @@ RSpec.describe Spree::ProductMetricsSubscriber doendend- context 'when store_id is missing' do+ context 'when order has no store' do+ let(:order_without_store) do+ create(:completed_order_with_totals, store: store).tap do |o|+ o.update_column(:store_id, nil)+ end+ end+let(:event) doSpree::Event.new(name: 'order.completed',- payload: { 'id' => order.id }+ payload: { 'id' => order_without_store.id })end