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
Update examples. Include Spree::Webhooks when initializing.
Sebastian Palma2f200693eb60
diff --git a/api/lib/spree/api/engine.rb b/api/lib/spree/api/engine.rbindex 242a7ec7c1..cb76b69d40 100644--- a/api/lib/spree/api/engine.rb+++ b/api/lib/spree/api/engine.rb@@ -20,6 +20,10 @@ module Spree# FIXME: we should only notify about deprecated preferences that are in use, not all of them# warn "[DEPRECATION] Spree::Api::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"end+ end++ initializer 'Spree::Webhooks' do+ Spree::Base.include(Spree::Webhooks::HasWebhooks)Spree::Order.prepend(Spree::Api::Order)Spree::Payment.prepend(Spree::Api::Payment)Spree::Shipment.prepend(Spree::Api::Shipment)diff --git a/api/spec/models/spree/order_spec.rb b/api/spec/models/spree/order_spec.rbindex d45c24344d..4c7f428f45 100644--- a/api/spec/models/spree/order_spec.rb+++ b/api/spec/models/spree/order_spec.rb@@ -5,7 +5,7 @@ enddescribe Spree::Order dodescribe 'sending webhooks after transitioning from states' do- let(:order) { Spree::Order.create(store: build(:store, default: true)) }+ let(:order) { Spree::Order.create }let(:payload) { {} }let(:queue_requests) { instance_double(Spree::Webhooks::Endpoints::QueueRequests) }diff --git a/api/spec/models/spree/payment_spec.rb b/api/spec/models/spree/payment_spec.rbindex bffc042079..b9c2d9f412 100644--- a/api/spec/models/spree/payment_spec.rb+++ b/api/spec/models/spree/payment_spec.rb@@ -4,12 +4,7 @@ class TextFormatterenddescribe Spree::Payment do- let(:payment) do- create(:payment,- source: build(:credit_card),- order: build(:order),- payment_method: Spree::Gateway::Bogus.create(active: true))- end+ let(:payment) { create(:payment) }describe '#after_void' dolet(:payload) { {} }diff --git a/api/spec/models/spree/shipment_spec.rb b/api/spec/models/spree/shipment_spec.rbindex 66d1f2fdaf..376464ec8b 100644--- a/api/spec/models/spree/shipment_spec.rb+++ b/api/spec/models/spree/shipment_spec.rb@@ -4,16 +4,7 @@ class TextFormatterenddescribe Spree::Shipment do- let(:order) do- mock_model Spree::Order, backordered?: false,- canceled?: false,- can_ship?: true,- currency: 'USD',- number: 'S12345',- paid?: false,- touch_later: false- end- let(:shipment) { create(:shipment, stock_location: create(:stock_location)) }+ let(:shipment) { create(:shipment) }context '#after_ship' dobefore do@@ -24,10 +15,8 @@ describe Spree::Shipment doendend- allow_any_instance_of(Spree::ShipmentHandler).to receive(:update_order_shipment_state)allow(Spree::Webhooks::Endpoints::QueueRequests).to receive(:new).and_return(queue_requests)allow(queue_requests).to receive(:call).with(any_args)- allow(shipment).to receive(:determine_state).and_return('shipped')endlet(:payload) { {} }@@ -39,7 +28,8 @@ describe Spree::Shipment dodouble(:scope).tap { |scope| expect(scope).to receive(:to_s) }))- shipment.update!(order)+ shipment.cancel # previous state that allows the object be shipped+ shipment.shipexpect(queue_requests).to have_received(:call).with(event: 'shipment.ship', payload: payload).onceendenddiff --git a/api/spec/models/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/spree/webhooks/has_webhooks_spec.rbindex 14221a6d6c..c498b9f28d 100644--- a/api/spec/models/spree/webhooks/has_webhooks_spec.rb+++ b/api/spec/models/spree/webhooks/has_webhooks_spec.rb@@ -10,10 +10,8 @@ enddescribe Spree::Webhooks::HasWebhooks dolet(:connection) { ActiveRecord::Base.connection }- let(:url) { 'https://google.com' }before do- stub_request(:post, url)connection.create_table :test_products, force: true do |t|t.string :nameend@@ -56,11 +54,10 @@ describe Spree::Webhooks::HasWebhooks docontext 'when able to infer the serializer from the class' dolet!(:images) { create_list(:image, 2) }let!(:product) do- create(:product_in_stock,- name: 'Test Product',- price: 10.00,- compare_at_price: 15.00,- variants_including_master: [create(:variant, images: images), create(:variant)])+ create(+ :product_in_stock,+ variants_including_master: [create(:variant, images: images), build(:variant)]+ )endlet(:payload) doSpree::Api::V2::Platform::ProductSerializer.new(diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex 671fb17002..db9b71d70a 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -10,11 +10,6 @@ describe Spree::Order, type: :model dolet(:user) { stub_model(Spree::LegacyUser, email: '[email protected]') }let!(:store) { create(:store, default: true) }let(:order) { stub_model(Spree::Order, user: user, store: store) }- let(:url) { 'https://google.com' }-- before(:all) do- stub_request(:any, 'https://google.com')- endbefore doallow(Spree::LegacyUser).to receive_messages(current: mock_model(Spree::LegacyUser, id: 123))@@ -70,16 +65,6 @@ describe Spree::Order, type: :model doexpect(order.payments.first).to be_voidend-- it 'executes a webhook callback' do- order.cancel- expect(WebMock).to(- have_requested(:post, 'https://google.com').with(- body: {foo: :bar}.to_json,- headers: {'Content-Type' => 'application/json'}- ).times(72)- )- endendcontext '#canceled_by' do@@ -191,16 +176,6 @@ describe Spree::Order, type: :model doorder.finalize!end- it 'executes a webhook callback' do- order.finalize!- expect(WebMock).to(- have_requested(:post, 'https://google.com').with(- body: {foo: :bar}.to_json,- headers: {'Content-Type' => 'application/json'}- ).times(6)- )- end-context 'order is considered risky' dobefore doallow(order).to receive_messages is_risky?: truediff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rbindex 1f6b731292..a6b6cdbe7f 100644--- a/core/spec/models/spree/shipment_spec.rb+++ b/core/spec/models/spree/shipment_spec.rb@@ -22,10 +22,6 @@ describe Spree::Shipment, type: :model dolet(:variant) { mock_model(Spree::Variant) }let(:line_item) { mock_model(Spree::LineItem, variant: variant) }- before(:all) do- stub_request(:any, 'https://google.com')- end-def create_shipment(order, stock_location)order.shipments.create(stock_location_id: stock_location.id).inventory_units.create(order_id: order.id,@@ -373,18 +369,6 @@ describe Spree::Shipment, type: :model doshipment.update!(order)end- it 'executes a webhook callback' do- allow(shipment).to receive_messages determine_state: 'shipped'- shipment.update!(order)-- expect(WebMock).to(- have_requested(:post, 'https://google.com').with(- body: {foo: :bar}.to_json,- headers: {'Content-Type' => 'application/json'}- ).times(13)- )- end-context 'when using the default shipment handler' doit "calls the 'perform' method" doshipment.state = 'pending'diff --git a/core/spec/spec_helper.rb b/core/spec/spec_helper.rbindex 493c9787a8..0623d3f17e 100644--- a/core/spec/spec_helper.rb+++ b/core/spec/spec_helper.rb@@ -34,7 +34,6 @@ endrequire 'rspec/rails'require 'database_cleaner'require 'ffaker'-require 'webmock/rspec'Dir['./spec/support/**/*.rb'].sort.each { |f| require f }