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
Emit order.shipped when all order shipments were shipped. (#11443)
sebde2807278f25
diff --git a/api/app/models/spree/api/webhooks/shipment_decorator.rb b/api/app/models/spree/api/webhooks/shipment_decorator.rbindex 19824edbc0..c7c6ae2d7e 100644--- a/api/app/models/spree/api/webhooks/shipment_decorator.rb+++ b/api/app/models/spree/api/webhooks/shipment_decorator.rb@@ -5,6 +5,13 @@ module Spreedef after_shipsuperqueue_webhooks_requests!('shipment.shipped')+ order.queue_webhooks_requests!('order.shipped') if all_order_shipments_were_shipped?+ end++ private++ def all_order_shipments_were_shipped?+ order.shipments.shipped.size == order.shipments.sizeendendenddiff --git a/api/spec/models/spree/api/webhooks/order_spec.rb b/api/spec/models/spree/api/webhooks/order_decorator_spec.rbsimilarity index 100%rename from api/spec/models/spree/api/webhooks/order_spec.rbrename to api/spec/models/spree/api/webhooks/order_decorator_spec.rbdiff --git a/api/spec/models/spree/api/webhooks/payment_spec.rb b/api/spec/models/spree/api/webhooks/payment_decorator_spec.rbsimilarity index 100%rename from api/spec/models/spree/api/webhooks/payment_spec.rbrename to api/spec/models/spree/api/webhooks/payment_decorator_spec.rbdiff --git a/api/spec/models/spree/api/webhooks/shipment_spec.rb b/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rbsimilarity index 50%rename from api/spec/models/spree/api/webhooks/shipment_spec.rbrename to api/spec/models/spree/api/webhooks/shipment_decorator_spec.rbindex 7df966e8f2..d47385d726 100644--- a/api/spec/models/spree/api/webhooks/shipment_spec.rb+++ b/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rb@@ -19,10 +19,44 @@ describe Spree::Shipment dolet(:queue_requests) { instance_double(Spree::Webhooks::Subscribers::QueueRequests) }- it 'executes QueueRequests.call with a shipment.shipped event and {} body after invoking ship' do+ it 'emits a shipment.shipped event' doshipment.cancel # previous state that allows the object be shippedshipment.shipexpect(queue_requests).to have_received(:call).with(event: 'shipment.shipped', body: body).onceend++ context 'emitting order.shipped' do+ let(:body) do+ order.reload+ Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash.to_json+ end+ let(:order) { create(:order) }+ let!(:shipments) do+ create_list(+ :shipment, 2,+ order: order,+ shipping_methods: [create(:shipping_method)],+ stock_location: build(:stock_location)+ )+ end++ context 'when all order shipments were shipped' do+ it 'emits an order.shipped event' do+ shipments[0].cancel+ shipments[0].ship+ shipments[1].cancel+ shipments[1].ship+ expect(queue_requests).to have_received(:call).with(event: 'order.shipped', body: body).once+ end+ end++ context 'when not all order shipments were shipped' do+ it 'does not emits an order.shipped event' do+ shipments[0].cancel+ shipments[0].ship+ expect(queue_requests).not_to have_received(:call).with(event: 'order.shipped', body: body)+ end+ end+ endendend