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
Make tests pass using a dummy serializer.
Sebastian Palma9c8ecfda97cb
diff --git a/api/app/models/concerns/spree/webhooks/has_webhooks.rb b/api/app/models/concerns/spree/webhooks/has_webhooks.rbindex f19fa3e9aa..544c7aeba1 100644--- a/api/app/models/concerns/spree/webhooks/has_webhooks.rb+++ b/api/app/models/concerns/spree/webhooks/has_webhooks.rb@@ -31,8 +31,6 @@ module Spreedef bodyresource_serializer.new(self).serializable_hash.to_json- rescue NameError- ''enddef resource_serializerdiff --git a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rbindex d3326cf21c..a01d8a0f5e 100644--- a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb+++ b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb@@ -10,7 +10,13 @@ module Spreeendend-Spree::TestProduct = Spree::Webhooks::TestProduct+module Spree+ class TestProduct < ActiveRecord::Base+ self.table_name = 'test_products'++ include Spree::Webhooks::HasWebhooks+ end+enddescribe Spree::Webhooks::HasWebhooks dobefore(:all) do@@ -28,6 +34,8 @@ describe Spree::Webhooks::HasWebhooks doallow(queue_requests).to receive(:call).with(any_args)end+ after { ENV['DISABLE_SPREE_WEBHOOKS'] = 'true' }+let(:images) { create_list(:image, 2) }let(:product) dobuild(@@ -63,15 +71,15 @@ describe Spree::Webhooks::HasWebhooks doendend- context 'without DISABLE_SPREE_WEBHOOKS', :spree_webhooks do- before do- ENV['DISABLE_SPREE_WEBHOOKS'] = nil- product.save- end-+ context 'without DISABLE_SPREE_WEBHOOKS' docontext 'with a Spree::Webhooks descendant class' dolet(:product) { Spree::Webhooks::TestProduct.new(name: 'test') }+ before do+ ENV['DISABLE_SPREE_WEBHOOKS'] = nil+ product.save+ end+context 'after_create_commit' doit 'does not queue a request' doexpect(queue_requests).not_to have_received(:call).with(hash_including(event: 'test_product.create'))@@ -97,6 +105,11 @@ describe Spree::Webhooks::HasWebhooks docontext 'with a resource serializer' dolet(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash.to_json }+ before do+ ENV['DISABLE_SPREE_WEBHOOKS'] = nil+ product.save+ end+context 'after_create_commit' doit 'queues a request through QueueRequests for product.create' doexpect(queue_requests).to have_received(:call).with(event: 'product.create', body: body).once@@ -130,26 +143,30 @@ describe Spree::Webhooks::HasWebhooks doendend- context 'without a resource serializer - blank body' do+ context 'without a resource serializer' dolet(:product) { Spree::TestProduct.new(name: 'test') }+ let(:exception_msg) { /uninitialized constant Spree::Api::V2::Platform::TestProductSerializer/ }+context 'after_create_commit' do- it 'does not queue a request' do- expect(queue_requests).not_to have_received(:call).with(hash_including(event: 'test_product.create'))- end+ before { ENV['DISABLE_SPREE_WEBHOOKS'] = nil }++ it { expect { product.save }.to raise_error(NameError, exception_msg) }end- context 'after_destroy_commit' do- it 'does not queue a request' do- product.destroy- expect(queue_requests).not_to have_received(:call).with(hash_including(event: 'test_product.destroy'))+ context 'update/destroy' do+ before do+ ENV['DISABLE_SPREE_WEBHOOKS'] = 'true'+ product.save+ ENV['DISABLE_SPREE_WEBHOOKS'] = nilend- end- context 'after_update_commit' do- it 'does not queue a request' do- product.update(name: 'new name')- expect(queue_requests).not_to have_received(:call).with(hash_including(event: 'test_product.update'))+ context 'after_destroy_commit' do+ it { expect { product.destroy }.to raise_error(NameError, exception_msg) }+ end++ context 'after_update_commit' do+ it { expect { product.update(name: 'new name') }.to raise_error(NameError, exception_msg) }endendenddiff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rbindex 6e9cc381c3..048eec52b7 100644--- a/api/spec/spec_helper.rb+++ b/api/spec/spec_helper.rb@@ -66,6 +66,18 @@ RSpec.configure do |config|config.include Spree::TestingSupport::Preferencesconfig.include Spree::TestingSupport::ImageHelpers+ DummySerializer = Struct.new(:_) { def serializable_hash; {}; end }+ Spree::Api::V2::Platform::ShippingCategorySerializer = DummySerializer+ Spree::Api::V2::Platform::PriceSerializer = DummySerializer+ Spree::Api::V2::Platform::StoreProductSerializer = DummySerializer+ Spree::Api::V2::Platform::BogusSerializer = DummySerializer+ Spree::Api::V2::Platform::FlatRateSerializer = DummySerializer+ Spree::Api::V2::Platform::LegacyUserSerializer = DummySerializer+ Spree::Api::V2::Platform::OptionValueVariantSerializer = DummySerializer+ Spree::Api::V2::Platform::ShippingMethodCategorySerializer = DummySerializer+ Spree::Api::V2::Platform::ShippingMethodZoneSerializer = DummySerializer+ Spree::Api::V2::Platform::StockMovementSerializer = DummySerializer+config.before doENV['DISABLE_SPREE_WEBHOOKS'] = 'true'