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
[SD-1535] Add the name event to the Webhook serializer payload/body (#11504)
seb6bb35cd1ec4f
diff --git a/api/app/jobs/spree/webhooks/subscribers/make_request_job.rb b/api/app/jobs/spree/webhooks/subscribers/make_request_job.rbindex 67e1940d55..d141146eda 100644--- a/api/app/jobs/spree/webhooks/subscribers/make_request_job.rb+++ b/api/app/jobs/spree/webhooks/subscribers/make_request_job.rb@@ -4,9 +4,9 @@ module Spreeclass MakeRequestJob < Spree::BaseJobqueue_as :spree_webhooks- def perform(body, event, subscriber)+ def perform(body, event_name, subscriber)Spree::Webhooks::Subscribers::HandleRequest.new(- body: body, event: event, subscriber: subscriber+ body: body, event_name: event_name, subscriber: subscriber).callendenddiff --git a/api/app/models/concerns/spree/webhooks/has_webhooks.rb b/api/app/models/concerns/spree/webhooks/has_webhooks.rbindex 097a127b95..691435bbab 100644--- a/api/app/models/concerns/spree/webhooks/has_webhooks.rb+++ b/api/app/models/concerns/spree/webhooks/has_webhooks.rb@@ -4,27 +4,27 @@ module Spreeextend ActiveSupport::Concernincluded do- after_create_commit(proc { queue_webhooks_requests!(event_name(:create)) })- after_destroy_commit(proc { queue_webhooks_requests!(event_name(:delete)) })- after_update_commit(proc { queue_webhooks_requests!(event_name(:update)) })+ after_create_commit(proc { queue_webhooks_requests!(inferred_event_name(:create)) })+ after_destroy_commit(proc { queue_webhooks_requests!(inferred_event_name(:delete)) })+ after_update_commit(proc { queue_webhooks_requests!(inferred_event_name(:update)) })- def queue_webhooks_requests!(event)+ def queue_webhooks_requests!(event_name)return if disable_spree_webhooks? || updating_only_timestamps? || body.blank?- Spree::Webhooks::Subscribers::QueueRequests.call(event: event, body: body)+ Spree::Webhooks::Subscribers::QueueRequests.call(body: body, event_name: event_name)endendprivate- def event_name(operation)- "#{self.class.name.demodulize.tableize.singularize}.#{operation}"- end-def bodyresource_serializer.new(self).serializable_hash.to_jsonend+ def inferred_event_name(operation)+ "#{self.class.name.demodulize.tableize.singularize}.#{operation}"+ end+def resource_serializerdemodulized_class_name = self.class.to_s.demodulize"Spree::Api::V2::Platform::#{demodulized_class_name}Serializer".constantizediff --git a/api/app/services/spree/webhooks/subscribers/handle_request.rb b/api/app/services/spree/webhooks/subscribers/handle_request.rbindex f6b9eb7618..9d5dec2c50 100644--- a/api/app/services/spree/webhooks/subscribers/handle_request.rb+++ b/api/app/services/spree/webhooks/subscribers/handle_request.rb@@ -4,9 +4,9 @@ module Spreemodule Webhooksmodule Subscribersclass HandleRequest- def initialize(body:, event:, subscriber:)- @body = body- @event = event+ def initialize(body:, event_name:, subscriber:)+ @body = JSON.parse(body)+ @event_name = event_name@subscriber = subscriberend@@ -14,40 +14,54 @@ module SpreeRails.logger.debug(msg("sending to '#{url}'"))Rails.logger.debug(msg("body: #{body}"))- return create_event(:warn, msg("can not make a request to '#{url}'")) if unprocessable_uri?- return create_event(:warn, msg("failed for '#{url}'")) if failed_request?+ return process(:warn, msg("can not make a request to '#{url}'")) if unprocessable_uri?+ return process(:warn, msg("failed for '#{url}'")) if failed_request?- create_event(:debug, msg("success for URL '#{url}'"))+ process(:debug, msg("success for URL '#{url}'"))endprivate- attr_reader :body, :event, :subscriber, :url+ attr_reader :body, :event_name, :subscriber- delegate :execution_time, :failed_request?, :response_code, :success?, :unprocessable_uri?,- to: :request+ delegate :execution_time, :failed_request?, :response_code, :success?, :unprocessable_uri?, to: :requestdelegate :id, :url, to: :subscriber+ delegate :created_at, :id, to: :event, prefix: true++ def process(log_level, msg)+ Rails.logger.public_send(log_level, msg)+ update_event(msg)+ nil+ end++ def update_event(msg)+ Spree::Webhooks::Event.+ find(event_id).+ update(+ execution_time: execution_time,+ request_errors: msg,+ response_code: response_code,+ success: success?+ )+ enddef request- @request ||= Spree::Webhooks::Subscribers::MakeRequest.new(body: body, url: url)+ @request ||=+ Spree::Webhooks::Subscribers::MakeRequest.new(body: body_with_event_metadata, url: url)end- def create_event(log_level, msg)- Rails.logger.public_send(log_level, msg)- Spree::Webhooks::Event.create(- execution_time: execution_time,- name: event,- request_errors: msg,- response_code: response_code,- subscriber_id: id,- success: success?,- url: url- )- nil+ def body_with_event_metadata+ body.+ merge(event_created_at: event_created_at, event_id: event_id, event_type: event.name).+ to_json+ end++ def event+ @event ||= Spree::Webhooks::Event.create(name: event_name, subscriber_id: id, url: url)enddef msg(msg)- "[SPREE WEBHOOKS] '#{event}' #{msg}"+ "[SPREE WEBHOOKS] '#{event_name}' #{msg}"endendenddiff --git a/api/app/services/spree/webhooks/subscribers/queue_requests.rb b/api/app/services/spree/webhooks/subscribers/queue_requests.rbindex fdd731b56c..6db2a943ee 100644--- a/api/app/services/spree/webhooks/subscribers/queue_requests.rb+++ b/api/app/services/spree/webhooks/subscribers/queue_requests.rb@@ -4,9 +4,9 @@ module Spreeclass QueueRequestsprepend Spree::ServiceModule::Base- def call(body:, event:)- Spree::Webhooks::Subscriber.active.with_urls_for(event).each do |subscriber|- Spree::Webhooks::Subscribers::MakeRequestJob.perform_later(body, event, subscriber)+ def call(body:, event_name:)+ Spree::Webhooks::Subscriber.active.with_urls_for(event_name).each do |subscriber|+ Spree::Webhooks::Subscribers::MakeRequestJob.perform_later(body, event_name, subscriber)endendenddiff --git a/api/lib/spree/api/testing_support/matchers/webhooks.rb b/api/lib/spree/api/testing_support/matchers/webhooks.rbindex 0fd46a34c0..29d451aa14 100644--- a/api/lib/spree/api/testing_support/matchers/webhooks.rb+++ b/api/lib/spree/api/testing_support/matchers/webhooks.rb@@ -27,18 +27,17 @@# way depending on what's the resource being tested.#RSpec::Matchers.define :emit_webhook_event do |event_to_emit|- match do |obj_method|- ENV['DISABLE_SPREE_WEBHOOKS'] = nil-+ match do |block|queue_requests = instance_double(Spree::Webhooks::Subscribers::QueueRequests)allow(Spree::Webhooks::Subscribers::QueueRequests).to receive(:new).and_return(queue_requests)allow(queue_requests).to receive(:call).with(any_args)- obj_method.call- expect(queue_requests).to have_received(:call).with(event: event_to_emit, body: body).once+ with_webhooks_enabled { Timecop.freeze { block.call } }- ENV['DISABLE_SPREE_WEBHOOKS'] = 'true'+ expect(queue_requests).to(+ have_received(:call).with(body: body.to_json, event_name: event_to_emit).once+ )enddef block_body_definition(obj_method)@@ -60,3 +59,9 @@ RSpec::Matchers.define :emit_webhook_event do |event_to_emit|supports_block_expectationsend++def with_webhooks_enabled+ ENV['DISABLE_SPREE_WEBHOOKS'] = nil+ yield+ ENV['DISABLE_SPREE_WEBHOOKS'] = 'true'+enddiff --git a/api/lib/spree/api/testing_support/serializers.rb b/api/lib/spree/api/testing_support/serializers.rbnew file mode 100644index 0000000000..207654bc29--- /dev/null+++ b/api/lib/spree/api/testing_support/serializers.rb@@ -0,0 +1,25 @@+module Spree+ class TestArgumentsJob < Spree::BaseJob+ def perform(serializer); end+ end+end++shared_examples 'an ActiveJob serializable hash' do+ context 'Rails < 6', if: Rails::VERSION::MAJOR < 6 do+ it 'can not be serialized by ActiveJob' do+ expect { Spree::TestArgumentsJob.perform_later(subject) }.to(+ raise_error(ActiveJob::SerializationError, 'Unsupported argument type: Symbol')+ )+ end+ end++ context 'Rails >= 6', if: Rails::VERSION::MAJOR >= 6 do+ it 'can be serialized by ActiveJob' do+ # It should fail if subject contains any custom instance (e.g Spree::Money)+ expect { Spree::TestArgumentsJob.perform_later(subject) }.not_to raise_error+ expect { Spree::TestArgumentsJob.perform_later(subject.merge(price: Spree::Money.new(0))) }.to(+ raise_error(ActiveJob::SerializationError)+ )+ end+ end+enddiff --git a/api/spec/factories/spree/webhooks/event_factory.rb b/api/spec/factories/spree/webhooks/event_factory.rbindex 77576e22ed..1288a394c1 100644--- a/api/spec/factories/spree/webhooks/event_factory.rb+++ b/api/spec/factories/spree/webhooks/event_factory.rb@@ -16,5 +16,12 @@ FactoryBot.define doresponse_code { '200' }success { true }end++ trait :blank do+ execution_time { nil }+ request_errors { nil }+ subscriber_id { nil }+ url { nil }+ endendenddiff --git a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rbindex a06c07e862..8886f62a13 100644--- a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb+++ b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb@@ -2,10 +2,13 @@ require 'spec_helper'describe Spree::Webhooks::HasWebhooks dolet(:images) { create_list(:image, 2) }+ let(:store) { create(:store) }+ let(:variant_with_images) { create(:variant, images: images) }+ let(:variant) { build(:variant) }let(:product) dobuild(:product_in_stock,- variants_including_master: [create(:variant, images: images), build(:variant)],+ variants_including_master: [variant_with_images, variant],stores: [store])end@@ -20,8 +23,8 @@ describe Spree::Webhooks::HasWebhooks doproduct.saveend- shared_examples 'not queueing an event request' do |event_to_emit|- it { expect(queue_requests).not_to have_received(:call).with(hash_including(event: event_to_emit)) }+ shared_examples 'not queueing an event request' do |event_name|+ it { expect(queue_requests).not_to have_received(:call).with(hash_including(event: event_name)) }endcontext 'after_create_commit' do@@ -42,7 +45,7 @@ describe Spree::Webhooks::HasWebhooks doendcontext 'without DISABLE_SPREE_WEBHOOKS' do- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }context 'after_create_commit' doit { expect { product.save }.to emit_webhook_event('product.create') }@@ -61,22 +64,25 @@ describe Spree::Webhooks::HasWebhooks doendcontext 'with a class name with multiple words' do- let(:body) { Spree::Api::V2::Platform::CmsPageSerializer.new(cms_page).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::CmsPageSerializer.new(cms_page).serializable_hash }let(:cms_page) { create(:cms_homepage, store: store, locale: 'en') }+ let(:event_name) { 'cms_page.create' }- it 'underscorize the event name' do- expect { cms_page }.to emit_webhook_event('cms_page.create')+ it 'underscorizes the event name' do+ expect { cms_page }.to emit_webhook_event(event_name)endendcontext 'when only timestamps change' do+ let(:event_name) { 'product.update' }+before { product.save }context 'on created_at change' doit doexpect doproduct.update(created_at: Date.yesterday)- end.not_to emit_webhook_event('product.update')+ end.not_to emit_webhook_event(event_name)endend@@ -84,7 +90,7 @@ describe Spree::Webhooks::HasWebhooks doit doexpect doproduct.update(updated_at: Date.yesterday)- end.not_to emit_webhook_event('product.update')+ end.not_to emit_webhook_event(event_name)endend@@ -94,7 +100,7 @@ describe Spree::Webhooks::HasWebhooks do# Doing product.touch in Rails 5.2 doesn't work at the first time.# It must be done twice in order to update the updated_at column.Spree::Product.find(product.id).touch- end.not_to emit_webhook_event('product.update')+ end.not_to emit_webhook_event(event_name)endend@@ -102,7 +108,7 @@ describe Spree::Webhooks::HasWebhooks doit doexpect doproduct.touch(:deleted_at)- end.to emit_webhook_event('product.update')+ end.to emit_webhook_event(event_name)endendenddiff --git a/api/spec/models/spree/api/webhooks/order_decorator_spec.rb b/api/spec/models/spree/api/webhooks/order_decorator_spec.rbindex ccae91e7f9..102fd5b07a 100644--- a/api/spec/models/spree/api/webhooks/order_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/order_decorator_spec.rb@@ -2,25 +2,28 @@ require 'spec_helper'describe Spree::Api::Webhooks::OrderDecorator dolet(:store) { create(:store, default: true) }- let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash }describe 'order.canceled' dodescribe 'completed -> canceled' do+ let(:event_name) { 'order.canceled' }let(:order) { create(:completed_order_with_totals, store: store) }- it { expect { Timecop.freeze { order.cancel } }.to emit_webhook_event('order.canceled') }+ it { expect { Timecop.freeze { order.cancel } }.to emit_webhook_event(event_name) }endenddescribe 'order.placed' dodescribe 'checkout -> completed' do+ let(:event_name) { 'order.placed' }let(:order) { create(:order, email: '[email protected]', store: store) }- it { expect { Timecop.freeze { order.finalize! } }.to emit_webhook_event('order.placed') }+ it { expect { order.finalize! }.to emit_webhook_event(event_name) }endenddescribe 'order.resumed' do+ let(:event_name) { 'order.resumed' }let(:order) { create(:order, store: store, state: :canceled) }context 'when order state changes' do@@ -29,17 +32,13 @@ describe Spree::Api::Webhooks::OrderDecorator do# this case does not create a state change recordsubject { Timecop.freeze { order.update(state: 'resumed') } }- it { expect { subject }.to emit_webhook_event('order.resumed') }+ it { expect { subject }.to emit_webhook_event(event_name) }endcontext 'when doing it through resume!' do- it do- expect do- Timecop.freeze do- order.resume!- end- end.to emit_webhook_event('order.resumed')- end+ subject { order.resume! }++ it { expect { subject }.to emit_webhook_event(event_name) }context 'after emitting the webhook' doit 'correctly sets state_machine_resumed used to avoid emitting the same event twice' do@@ -47,7 +46,7 @@ describe Spree::Api::Webhooks::OrderDecorator do# and another one is for setting the order state_changesorder.state_machine_resumed = trueexpect(order.state_machine_resumed).to eq(true)- order.resume!+ subjectexpect(order.state_machine_resumed).to eq(false)endend@@ -58,7 +57,7 @@ describe Spree::Api::Webhooks::OrderDecorator doit doexpect doorder.update(email: '[email protected]')- end.not_to emit_webhook_event('order.resumed')+ end.not_to emit_webhook_event(event_name)endendenddiff --git a/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb b/api/spec/models/spree/api/webhooks/payment_decorator_spec.rbindex 57dc3507c1..2126a1f170 100644--- a/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb@@ -1,58 +1,63 @@require 'spec_helper'describe Spree::Api::Webhooks::PaymentDecorator do- let(:body) { Spree::Api::V2::Platform::PaymentSerializer.new(payment).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::PaymentSerializer.new(payment).serializable_hash }let(:payment) { create(:payment) }before { allow(payment).to receive_message_chain(:state_changes, :create!) }describe 'payment.paid' do+ let(:event_name) { 'payment.paid' }+context 'processing -> completed' dobefore { payment.started_processing }- it { expect { payment.complete }.to emit_webhook_event('payment.paid') }+ it { expect { payment.complete }.to emit_webhook_event(event_name) }endcontext 'pending -> completed' dobefore { payment.pend }- it { expect { payment.complete }.to emit_webhook_event('payment.paid') }+ it { expect { payment.complete }.to emit_webhook_event(event_name) }endcontext 'checkout -> completed' do- it { expect { payment.complete }.to emit_webhook_event('payment.paid') }+ it { expect { payment.complete }.to emit_webhook_event(event_name) }endenddescribe 'payment.voided' do+ let(:event_name) { 'payment.voided' }+context 'pending -> void' dobefore { payment.pend }- it { expect { payment.void }.to emit_webhook_event('payment.voided') }+ it { expect { payment.void }.to emit_webhook_event(event_name) }endcontext 'processing -> void' dobefore { payment.started_processing }- it { expect { payment.void }.to emit_webhook_event('payment.voided') }+ it { expect { payment.void }.to emit_webhook_event(event_name) }endcontext 'completed -> void' dobefore { payment.complete }- it { expect { payment.void }.to emit_webhook_event('payment.voided') }+ it { expect { payment.void }.to emit_webhook_event(event_name) }endcontext 'checkout -> void' do- it { expect { payment.void }.to emit_webhook_event('payment.voided') }+ it { expect { payment.void }.to emit_webhook_event(event_name) }endenddescribe 'order.paid' dosubject { Timecop.freeze { another_payment.complete } }- let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash }let(:order) { payment.order }+ let(:event_name) { 'order.paid' }let!(:another_payment) { create(:payment, order: order) }context 'order.paid? == true' do@@ -63,7 +68,7 @@ describe Spree::Api::Webhooks::PaymentDecorator doanother_payment.started_processingend- it { expect { subject }.to emit_webhook_event('order.paid') }+ it { expect { subject }.to emit_webhook_event(event_name) }endcontext 'pending -> complete' do@@ -73,13 +78,13 @@ describe Spree::Api::Webhooks::PaymentDecorator doanother_payment.pendend- it { expect { subject }.to emit_webhook_event('order.paid') }+ it { expect { subject }.to emit_webhook_event(event_name) }endcontext 'checkout -> complete' dobefore { payment.complete }- it { expect { subject }.to emit_webhook_event('order.paid') }+ it { expect { subject }.to emit_webhook_event(event_name) }endend@@ -92,17 +97,17 @@ describe Spree::Api::Webhooks::PaymentDecorator docontext 'processing -> complete' dobefore { payment.started_processing }- it { expect { subject }.not_to emit_webhook_event('order.paid') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endcontext 'pending -> complete' dobefore { payment.pend }- it { expect { subject }.not_to emit_webhook_event('order.paid') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endcontext 'checkout -> complete' do- it { expect { subject }.not_to emit_webhook_event('order.paid') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endendenddiff --git a/api/spec/models/spree/api/webhooks/product_decorator_spec.rb b/api/spec/models/spree/api/webhooks/product_decorator_spec.rbindex a429178795..ae05c9b907 100644--- a/api/spec/models/spree/api/webhooks/product_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/product_decorator_spec.rb@@ -4,14 +4,15 @@ describe Spree::Api::Webhooks::ProductDecorator dolet(:product) { create(:product) }context 'emitting product.discontinued' do- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }+ let(:event_name) { 'product.discontinued' }context 'when product discontinued_on changes' docontext 'when the new value is "present"' doit doexpect doproduct.discontinue!- end.to emit_webhook_event('product.discontinued')+ end.to emit_webhook_event(event_name)endend@@ -21,7 +22,7 @@ describe Spree::Api::Webhooks::ProductDecorator doit doexpect doproduct.update(discontinue_on: nil)- end.not_to emit_webhook_event('product.discontinued')+ end.not_to emit_webhook_event(event_name)endendend@@ -30,7 +31,7 @@ describe Spree::Api::Webhooks::ProductDecorator doit doexpect doproduct.update(width: 180)- end.not_to emit_webhook_event('product.discontinued')+ end.not_to emit_webhook_event(event_name)endendenddiff --git a/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rb b/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rbindex 52785fac52..d2b2aff161 100644--- a/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rb@@ -13,7 +13,8 @@ describe Spree::Api::Webhooks::ShipmentDecorator doendcontext 'emitting shipment.shipped' do- let(:body) { Spree::Api::V2::Platform::ShipmentSerializer.new(shipment).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::ShipmentSerializer.new(shipment).serializable_hash }+ let(:event_name) { 'shipment.shipped' }context 'ready -> ship' dolet(:shipment) { create(:shipment, order: order) }@@ -24,21 +25,19 @@ describe Spree::Api::Webhooks::ShipmentDecorator doshipment.readyend- it { expect { shipment.ship }.to emit_webhook_event('shipment.shipped') }+ it { expect { shipment.ship }.to emit_webhook_event(event_name) }endcontext 'canceled -> ship' dobefore { shipment.cancel }- it { expect { shipment.ship }.to emit_webhook_event('shipment.shipped') }+ it { expect { shipment.ship }.to emit_webhook_event(event_name) }endendcontext 'emitting order.shipped' do- let(:body) do- order.reload- Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash.to_json- end+ let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order.reload).serializable_hash }+ let(:event_name) { 'order.shipped' }let!(:shipments) docreate_list(:shipment, 2,@@ -61,11 +60,11 @@ describe Spree::Api::Webhooks::ShipmentDecorator doshipments[1].readyend- it { expect { shipments[1].ship }.to emit_webhook_event('order.shipped') }+ it { expect { shipments[1].ship }.to emit_webhook_event(event_name) }endcontext 'without all order shipments shipped' do- it { expect { shipments[0].ship }.not_to emit_webhook_event('order.shipped') }+ it { expect { shipments[0].ship }.not_to emit_webhook_event(event_name) }endend@@ -78,11 +77,11 @@ describe Spree::Api::Webhooks::ShipmentDecorator doshipments[1].cancelend- it { expect { shipments[1].ship }.to emit_webhook_event('order.shipped') }+ it { expect { shipments[1].ship }.to emit_webhook_event(event_name) }endcontext 'without all order shipments shipped' do- it { expect { shipments[0].ship }.not_to emit_webhook_event('order.shipped') }+ it { expect { shipments[0].ship }.not_to emit_webhook_event(event_name) }endendenddiff --git a/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb b/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rbindex 8ed36f940a..2565e77aea 100644--- a/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb@@ -1,19 +1,17 @@require 'spec_helper'describe Spree::Api::Webhooks::StockItemDecorator do- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant.reload).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }let(:variant) { create(:variant) }let(:stock_item) { variant.stock_items.first }let(:stock_location) { variant.stock_locations.first }describe 'emitting product.backorderable' do- subject do- product.reload- Timecop.freeze { stock_item.update(backorderable: backorderable) }- end+ subject { stock_item.update(backorderable: backorderable) }- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product.reload).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }let(:product) { variant.product }+ let(:event_name) { 'product.backorderable' }let!(:variant2) { create(:variant, product: product) }before { Spree::StockItem.update_all(backorderable: false) }@@ -23,13 +21,13 @@ describe Spree::Api::Webhooks::StockItemDecorator docontext 'when one of the variants is made backorderable' dolet(:backorderable) { true }- it { expect { subject }.to emit_webhook_event('product.backorderable') }+ it { expect { subject }.to emit_webhook_event(event_name) }endcontext 'when none of the variants is made backorderable' dolet(:backorderable) { false }- it { expect { subject }.not_to emit_webhook_event('product.backorderable') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endend@@ -43,7 +41,7 @@ describe Spree::Api::Webhooks::StockItemDecorator doanother_stock_item.update(backorderable: true)end- it { expect { subject }.not_to emit_webhook_event('product.backorderable') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endendend@@ -59,13 +57,15 @@ describe Spree::Api::Webhooks::StockItemDecorator doendend- it { expect { subject }.not_to emit_webhook_event('product.backorderable') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endenddescribe 'emitting variant.backorderable' dosubject { stock_item.save }+ let(:event_name) { 'variant.backorderable' }+context 'when variant was out of stock' dobefore dostock_location.stock_movements.new.tap do |stock_movement|@@ -78,7 +78,7 @@ describe Spree::Api::Webhooks::StockItemDecorator docontext 'when variant was backorderable' dobefore { stock_item.backorderable = true }- it { expect { subject }.not_to emit_webhook_event('variant.backorderable') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endcontext 'when variant was not backorderable' do@@ -87,13 +87,13 @@ describe Spree::Api::Webhooks::StockItemDecorator docontext 'when variant is not set as backorderable' dobefore { stock_item.backorderable = false }- it { expect { subject }.not_to emit_webhook_event('variant.backorderable') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endcontext 'when variant is set as backorderable' dobefore { stock_item.backorderable = true }- it { expect { subject }.to emit_webhook_event('variant.backorderable') }+ it { expect { subject }.to emit_webhook_event(event_name) }endendend@@ -109,7 +109,7 @@ describe Spree::Api::Webhooks::StockItemDecorator dostock_item.backorderable = trueend- it { expect { subject }.not_to emit_webhook_event('variant.backorderable') }+ it { expect { subject }.not_to emit_webhook_event(event_name) }endendenddiff --git a/api/spec/models/spree/api/webhooks/stock_movement_decorator_spec.rb b/api/spec/models/spree/api/webhooks/stock_movement_decorator_spec.rbindex 2b69988034..1c2647ce05 100644--- a/api/spec/models/spree/api/webhooks/stock_movement_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/stock_movement_decorator_spec.rb@@ -1,16 +1,17 @@require 'spec_helper'describe Spree::Api::Webhooks::StockMovementDecorator do+ let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant.reload).serializable_hash }let(:stock_item) { create(:stock_item) }let(:stock_location) { variant.stock_locations.first }- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant.reload).serializable_hash.to_json }describe 'emitting product.back_in_stock' dolet!(:store) { create(:store) }let!(:product) { create(:product, stores: [store]) }let!(:variant) { create(:variant, product: product) }let!(:variant2) { create(:variant, product: product) }- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }+ let(:params) { 'product.back_in_stock' }before { Spree::StockItem.update_all(backorderable: false) }@@ -25,7 +26,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator doproduct.reloadend- it { expect { subject }.to emit_webhook_event('product.back_in_stock') }+ it { expect { subject }.to emit_webhook_event(params) }endcontext 'when none of the variants is back in stock' do@@ -38,7 +39,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator doproduct.reloadend- it { expect { subject }.not_to emit_webhook_event('product.back_in_stock') }+ it { expect { subject }.not_to emit_webhook_event(params) }endend@@ -59,12 +60,13 @@ describe Spree::Api::Webhooks::StockMovementDecorator doendend- it { expect { subject }.not_to emit_webhook_event('product.back_in_stock') }+ it { expect { subject }.not_to emit_webhook_event(params) }endenddescribe 'emitting variant.back_in_stock' dolet(:variant) { create(:variant, track_inventory: true) }+ let(:params) { 'variant.back_in_stock' }context 'when stock item was out of stock' docontext 'when stock item changes to be in stock' do@@ -76,7 +78,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator dostock_movement.stock_item = stock_location.set_up_stock_item(variant)stock_movement.saveend- end.to emit_webhook_event('variant.back_in_stock')+ end.to emit_webhook_event(params)endend@@ -89,7 +91,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator dostock_movement.stock_item = stock_location.set_up_stock_item(variant)stock_movement.saveend- end.not_to emit_webhook_event('variant.back_in_stock')+ end.not_to emit_webhook_event(params)endendend@@ -104,15 +106,16 @@ describe Spree::Api::Webhooks::StockMovementDecorator dostock_movement.stock_item = stock_location.set_up_stock_item(variant)stock_movement.saveend- end.not_to emit_webhook_event('variant.back_in_stock')+ end.not_to emit_webhook_event(params)endendend- describe '#update_stock_item_quantity' do+ describe 'emitting variant.out_of_stock' dosubject { stock_movement }let(:stock_movement) { create(:stock_movement, stock_item: stock_item, quantity: movement_quantity) }+ let(:params) { 'variant.out_of_stock' }let!(:variant) { stock_item.variant }before { Spree::StockItem.update_all(backorderable: false) }@@ -121,7 +124,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator dolet(:movement_quantity) { -stock_item.count_on_hand }it 'emits the variant.out_of_stock event' do- expect { subject }.to emit_webhook_event('variant.out_of_stock')+ expect { subject }.to emit_webhook_event(params)endend@@ -129,7 +132,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator dolet(:movement_quantity) { -stock_item.count_on_hand + 1 }it 'does not emit the variant.out_of_stock event' do- expect { subject }.not_to emit_webhook_event('variant.out_of_stock')+ expect { subject }.not_to emit_webhook_event(params)endend@@ -139,7 +142,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator dolet(:movement_quantity) { 0 }it 'does not emit the variant.out_of_stock event' do- expect { subject }.not_to emit_webhook_event('variant.out_of_stock')+ expect { subject }.not_to emit_webhook_event(params)endendenddiff --git a/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb b/api/spec/models/spree/api/webhooks/variant_decorator_spec.rbindex d26842a34c..d647b79e1c 100644--- a/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb+++ b/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb@@ -4,14 +4,15 @@ describe Spree::Api::Webhooks::VariantDecorator dolet(:variant) { create(:variant) }context 'emitting variant.discontinued' do- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }+ let(:event_name) { 'variant.discontinued' }context 'when variant discontinued_on changes' docontext 'when the new value is "present"' doit doexpect dovariant.discontinue!- end.to emit_webhook_event('variant.discontinued')+ end.to emit_webhook_event(event_name)endend@@ -21,7 +22,7 @@ describe Spree::Api::Webhooks::VariantDecorator doit doexpect dovariant.update(discontinue_on: nil)- end.not_to emit_webhook_event('variant.discontinued')+ end.not_to emit_webhook_event(event_name)endendend@@ -30,7 +31,7 @@ describe Spree::Api::Webhooks::VariantDecorator doit doexpect dovariant.update(width: 180)- end.not_to emit_webhook_event('variant.discontinued')+ end.not_to emit_webhook_event(event_name)endendenddiff --git a/api/spec/serializers/spree/api/v2/platform/address_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/address_serializer_spec.rbindex 5b96e05134..8ec2dd50c4 100644--- a/api/spec/serializers/spree/api/v2/platform/address_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/address_serializer_spec.rb@@ -1,14 +1,12 @@require 'spec_helper'describe Spree::Api::V2::Platform::AddressSerializer do- subject { described_class.new(address) }+ subject { described_class.new(address).serializable_hash }let(:address) { create(:address, user: create(:user)) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: address.id.to_s,@@ -55,4 +53,6 @@ describe Spree::Api::V2::Platform::AddressSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rbindex c9f1f23348..d9232f3a2c 100644--- a/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb@@ -40,4 +40,6 @@ describe Spree::Api::V2::Platform::AssetSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/cms_page_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/cms_page_serializer_spec.rbindex a4b3a22d5d..bb06259ae7 100644--- a/api/spec/serializers/spree/api/v2/platform/cms_page_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/cms_page_serializer_spec.rb@@ -1,14 +1,14 @@require 'spec_helper'describe Spree::Api::V2::Platform::CmsPageSerializer do- subject { described_class.new(cms_page) }+ subject { described_class.new(cms_page).serializable_hash }let(:cms_page) { create(:cms_feature_page, cms_sections: create_list(:cms_hero_image_section, 2)) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: cms_page.id.to_s,@@ -44,4 +44,6 @@ describe Spree::Api::V2::Platform::CmsPageSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rbindex 9f24fec84a..ccf04c0bfa 100644--- a/api/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::CreditCardSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:credit_card) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rbindex b2ea78782f..d6acc123d6 100644--- a/api/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::CustomerReturnSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:customer_return) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rbindex 568e40b6e8..0fe1654a16 100644--- a/api/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rb@@ -1,14 +1,14 @@require 'spec_helper'describe Spree::Api::V2::Platform::DigitalLinkSerializer do- subject { described_class.new(digital_link) }+ subject { described_class.new(digital_link).serializable_hash }let(:digital_link) { create(:digital_link) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: digital_link.id.to_s,@@ -36,6 +36,8 @@ describe Spree::Api::V2::Platform::DigitalLinkSerializer do)end- it { expect(subject.serializable_hash[:data][:id]).to be_kind_of(String) }- it { expect(subject.serializable_hash[:data][:type]).to be(:digital_link) }+ it { expect(subject[:data][:id]).to be_kind_of(String) }+ it { expect(subject[:data][:type]).to be(:digital_link) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rbindex 00577651ec..3b8e7a9467 100644--- a/api/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rb@@ -1,14 +1,14 @@require 'spec_helper'describe Spree::Api::V2::Platform::DigitalSerializer do- subject { described_class.new(digital) }+ subject { described_class.new(digital).serializable_hash }let(:digital) { create(:digital) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: digital.id.to_s,@@ -32,7 +32,9 @@ describe Spree::Api::V2::Platform::DigitalSerializer do)end- it { expect(subject.serializable_hash[:data][:id]).to be_kind_of(String) }- it { expect(subject.serializable_hash[:data][:type]).to be(:digital) }- it { expect(subject.serializable_hash[:data][:attributes][:url]).to include('thinking-cat.jpg') }+ it { expect(subject[:data][:id]).to be_kind_of(String) }+ it { expect(subject[:data][:type]).to be(:digital) }+ it { expect(subject[:data][:attributes][:url]).to include('thinking-cat.jpg') }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rbindex f070d2257f..df3a31866b 100644--- a/api/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::InventoryUnitSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:inventory_unit) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of file+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rbindex 08f593512b..cdcc05db87 100644--- a/api/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::LineItemSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:line_item) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of file+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/menu_item_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/menu_item_serializer_spec.rbindex 631fc31953..33a4f76466 100644--- a/api/spec/serializers/spree/api/v2/platform/menu_item_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/menu_item_serializer_spec.rb@@ -1,7 +1,7 @@require 'spec_helper'describe Spree::Api::V2::Platform::MenuItemSerializer do- subject { described_class.new(menu_item) }+ subject { described_class.new(menu_item).serializable_hash }let(:menu) { create(:menu) }let(:menu_item) { create(:menu_item, menu: menu, linked_resource: create(:taxon)) }@@ -12,10 +12,10 @@ describe Spree::Api::V2::Platform::MenuItemSerializer do]end- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: menu_item.id.to_s,@@ -81,4 +81,6 @@ describe Spree::Api::V2::Platform::MenuItemSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/menu_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/menu_serializer_spec.rbindex a4b0728336..2b3752519d 100644--- a/api/spec/serializers/spree/api/v2/platform/menu_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/menu_serializer_spec.rb@@ -1,14 +1,14 @@require 'spec_helper'describe Spree::Api::V2::Platform::MenuSerializer do- subject { described_class.new(menu) }+ subject { described_class.new(menu).serializable_hash }let(:menu) { create(:menu) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: menu.id.to_s,@@ -34,4 +34,6 @@ describe Spree::Api::V2::Platform::MenuSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rbindex 980d990de1..dc347eef3b 100644--- a/api/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rb@@ -1,14 +1,14 @@require 'spec_helper'describe Spree::Api::V2::Platform::OptionTypeSerializer do- subject { described_class.new(option_type) }+ subject { described_class.new(option_type).serializable_hash }let(:option_type) { create(:option_type, option_values: create_list(:option_value, 2)) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: option_type.id.to_s,@@ -41,4 +41,6 @@ describe Spree::Api::V2::Platform::OptionTypeSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rbindex c66169d1eb..f243c0dc82 100644--- a/api/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rb@@ -1,14 +1,14 @@require 'spec_helper'describe Spree::Api::V2::Platform::OptionValueSerializer do- subject { described_class.new(option_value) }+ subject { described_class.new(option_value).serializable_hash }let(:option_value) { create(:option_value) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: option_value.id.to_s,@@ -34,4 +34,6 @@ describe Spree::Api::V2::Platform::OptionValueSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/order_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/order_serializer_spec.rbindex e688b5f961..df85c0f1b0 100644--- a/api/spec/serializers/spree/api/v2/platform/order_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/order_serializer_spec.rb@@ -3,17 +3,21 @@ require 'spec_helper'describe Spree::Api::V2::Platform::OrderSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(order, params: serializer_params) }+ subject { described_class.new(order, params: serializer_params).serializable_hash }context 'cart' dolet(:order) { create(:order) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'endcontext 'completed order' dolet(:order) { create(:shipped_order) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'endenddiff --git a/api/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rbindex 12d2a0d10b..7d1861e0ed 100644--- a/api/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::PaymentCaptureEventSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:payment_capture_event) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rbindex 734b4e19e4..7a5218f67c 100644--- a/api/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::PaymentSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:payment) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of file+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/price_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/price_serializer_spec.rbindex 16c6bbf572..fd6e1e463d 100644--- a/api/spec/serializers/spree/api/v2/platform/price_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/price_serializer_spec.rb@@ -3,13 +3,13 @@ require 'spec_helper'describe Spree::Api::V2::Platform::PriceSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:price) }let(:type) { :price }it do- expect(subject.serializable_hash).to(+ expect(subject).to(eq(data: {id: resource.id.to_s,@@ -32,4 +32,6 @@ describe Spree::Api::V2::Platform::PriceSerializer do))end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/product_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/product_serializer_spec.rbindex 8621db825a..7d8d8a51d3 100644--- a/api/spec/serializers/spree/api/v2/platform/product_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/product_serializer_spec.rb@@ -3,7 +3,7 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ProductSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(product, params: serializer_params) }+ subject { described_class.new(product, params: serializer_params).serializable_hash }let!(:images) { create_list(:image, 2) }let(:product) do@@ -132,16 +132,16 @@ describe Spree::Api::V2::Platform::ProductSerializer doendcontext 'without a store in the params' do- subject { described_class.new(product, params: serializer_params.merge(store: nil)) }+ subject { described_class.new(product, params: serializer_params.merge(store: nil)).serializable_hash }it 'returns all the product taxons' do- expect(subject.serializable_hash).to eq(serializable_hash)+ expect(subject).to eq(serializable_hash)endend- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }- it do- expect(subject.serializable_hash).to eq(serializable_hash)- end+ it { expect(subject).to eq(serializable_hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rbindex 99ecc2f424..0f2c9bd9f5 100644--- a/api/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rb@@ -1,17 +1,17 @@require 'spec_helper'describe Spree::Api::V2::Platform::PromotionSerializer do- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }include_context 'API v2 serializers params'let(:promotion_category) { create(:promotion_category) }let(:promotion_rule) { create(:promotion_rule) }let(:resource) { create(:promotion_with_item_adjustment, promotion_category: promotion_category, promotion_rules: [promotion_rule]) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: resource.id.to_s,@@ -68,4 +68,6 @@ describe Spree::Api::V2::Platform::PromotionSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rbindex c2c92b7ed8..7303739250 100644--- a/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb@@ -26,4 +26,6 @@ describe Spree::Api::V2::Platform::PropertySerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rbindex 9b1994ada7..61f8127831 100644--- a/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb@@ -46,4 +46,6 @@ describe Spree::Api::V2::Platform::PrototypeSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rbindex 03119a81c2..0a9c18e767 100644--- a/api/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::RefundSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:refund, amount: 5.0) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rbindex a801790fbd..b3363f5a38 100644--- a/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb@@ -59,4 +59,6 @@ describe Spree::Api::V2::Platform::ReimbursementSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rbindex 433aa9e8b5..8edcf9dd24 100644--- a/api/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ReturnAuthorizationSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:return_authorization) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of file+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rbindex 05592766c1..96337d5255 100644--- a/api/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ReturnItemSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:return_item) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of file+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rbindex 531b625276..262774bea7 100644--- a/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb@@ -21,4 +21,6 @@ describe Spree::Api::V2::Platform::RoleSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rbindex 916a2a2314..dca94fd2da 100644--- a/api/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ShipmentSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:shipment) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of file+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rbindex 8a1fab468a..172508289c 100644--- a/api/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ShippingCategorySerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:shipping_category) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rbindex 9abeb09870..ee337d8a07 100644--- a/api/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rb@@ -3,17 +3,17 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ShippingMethodSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:shipping_category) {create(:shipping_category) }let(:tax_category) { create(:tax_category) }let(:resource) { create(:shipping_method, shipping_categories: [shipping_category], tax_category: tax_category) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: resource.id.to_s,@@ -60,4 +60,6 @@ describe Spree::Api::V2::Platform::ShippingMethodSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rbindex 1f653e6119..89e8160190 100644--- a/api/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ShippingRateSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:shipping_rate) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rbindex b317caf0c1..a3b3b9ff26 100644--- a/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb@@ -39,4 +39,6 @@ describe Spree::Api::V2::Platform::StockItemSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rbindex 983423e940..f6963a5a49 100644--- a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb@@ -41,4 +41,6 @@ describe Spree::Api::V2::Platform::StockLocationSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rbindex 33fd0066d6..468879e8fe 100644--- a/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb@@ -25,4 +25,6 @@ describe Spree::Api::V2::Platform::StockMovementSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rbindex 57dd095ed2..f36e0abc66 100644--- a/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb@@ -51,4 +51,6 @@ describe Spree::Api::V2::Platform::StockTransferSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rbindex cad6f38763..9dbe7dbdd5 100644--- a/api/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::StoreCreditSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:store_credit) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rbindex 7a484dae8d..5f041117ee 100644--- a/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb@@ -1,15 +1,15 @@require 'spec_helper'describe Spree::Api::V2::Platform::StoreSerializer do- subject { described_class.new(store) }+ subject { described_class.new(store).serializable_hash }let!(:store) { Spree::Store.default }let!(:menus) { [create(:menu, store: store), create(:menu, location: 'Footer', store: store)] }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: store.id.to_s,@@ -65,4 +65,6 @@ describe Spree::Api::V2::Platform::StoreSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/tax_category_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/tax_category_serializer_spec.rbnew file mode 100644index 0000000000..2f39ecac55--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/tax_category_serializer_spec.rb@@ -0,0 +1,35 @@+require 'spec_helper'++describe Spree::Api::V2::Platform::TaxCategorySerializer do+ include_context 'API v2 serializers params'++ subject { described_class.new(resource, params: serializer_params).serializable_hash }++ let(:resource) { create(:tax_category) }+ let(:type) { :tax_category }++ it do+ expect(subject).to eq(+ data: {+ id: resource.id.to_s,+ type: type,+ attributes: {+ name: resource.name,+ description: resource.description,+ is_default: resource.is_default,+ deleted_at: resource.deleted_at,+ created_at: resource.created_at,+ updated_at: resource.updated_at,+ tax_code: nil+ },+ relationships: {+ tax_rates: {+ data: []+ }+ }+ }+ )+ end++ it_behaves_like 'an ActiveJob serializable hash'+enddiff --git a/api/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rbindex 45b91c50c7..660cae6da3 100644--- a/api/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::TaxRateSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:tax_rate) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rbindex 96ab090d46..323099a6a3 100644--- a/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb@@ -3,17 +3,17 @@ require 'spec_helper'describe Spree::Api::V2::Platform::TaxonSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(taxon, params: serializer_params) }+ subject { described_class.new(taxon, params: serializer_params).serializable_hash }let(:taxonomy) { create(:taxonomy, store: store) }let(:taxon) { create(:taxon, products: create_list(:product, 2, stores: [store]), taxonomy: taxonomy) }let!(:children) { [create(:taxon, parent: taxon, taxonomy: taxonomy), create(:taxon, parent: taxon, taxonomy: taxonomy)] }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }context 'without products' doit do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: taxon.id.to_s,@@ -83,7 +83,7 @@ describe Spree::Api::V2::Platform::TaxonSerializer doendit do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: taxon.id.to_s,@@ -157,6 +157,7 @@ describe Spree::Api::V2::Platform::TaxonSerializer do})end-end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rbindex 6d9919a4ec..e4835a0864 100644--- a/api/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rb@@ -1,22 +1,23 @@require 'spec_helper'describe Spree::Api::V2::Platform::TaxonomySerializer, retry: 3 do- subject { described_class.new(taxonomy) }+ subject { described_class.new(taxonomy).serializable_hash }let(:taxonomy) { create(:taxonomy) }let(:taxon) { create(:taxon, taxonomy: taxonomy) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- taxons_json = taxonomy.taxons.map do |taxon|+ let(:taxons_json) do+ taxonomy.taxons.map do |taxon|{id: taxon.id.to_s,type: :taxon}end+ end- expect(subject.serializable_hash).to eq(+ it { expect(subject).to be_kind_of(Hash) }++ it do+ expect(subject).to eq({data: {id: taxonomy.id.to_s,@@ -44,4 +45,6 @@ describe Spree::Api::V2::Platform::TaxonomySerializer, retry: 3 do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rbindex c4f760f18e..326e4cd0db 100644--- a/api/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rb@@ -1,17 +1,17 @@require 'spec_helper'describe Spree::Api::V2::Platform::VariantSerializer do- subject { described_class.new(variant, params: serializer_params) }+ subject { described_class.new(variant, params: serializer_params).serializable_hash }include_context 'API v2 serializers params'let!(:variant) { create(:variant, price: 10, compare_at_price: 15, images: create_list(:image, 2), tax_category: create(:tax_category)) }let!(:digital) { create(:digital, variant: variant) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: variant.id.to_s,@@ -107,4 +107,6 @@ describe Spree::Api::V2::Platform::VariantSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rbindex 745a60585a..fe0794ec5f 100644--- a/api/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rb@@ -3,9 +3,11 @@ require 'spec_helper'describe Spree::Api::V2::Platform::ZoneSerializer doinclude_context 'API v2 serializers params'- subject { described_class.new(resource, params: serializer_params) }+ subject { described_class.new(resource, params: serializer_params).serializable_hash }let(:resource) { create(:zone) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rbindex 02082511c6..0d96d58883 100644--- a/api/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rb+++ b/api/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rb@@ -1,15 +1,15 @@require 'spec_helper'describe Spree::V2::Storefront::WishedItemSerializer do- subject { described_class.new(wished_item, params: { currency: 'USD' }) }+ subject { described_class.new(wished_item, params: { currency: 'USD' }).serializable_hash }let!(:wishlist) { create(:wishlist) }let!(:wished_item) { create(:wished_item, wishlist: wishlist, variant: create(:variant), quantity: 5) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: wished_item.id.to_s,@@ -33,4 +33,6 @@ describe Spree::V2::Storefront::WishedItemSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rbindex cad305003d..e0a1cc8c61 100644--- a/api/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb+++ b/api/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb@@ -1,15 +1,15 @@require 'spec_helper'describe Spree::V2::Storefront::WishlistSerializer do- subject { described_class.new(wishlist) }+ subject { described_class.new(wishlist).serializable_hash }let!(:wishlist) { create(:wishlist) }let!(:wished_item) { create(:wished_item, wishlist: wishlist, variant: create(:variant), quantity: 1) }- it { expect(subject.serializable_hash).to be_kind_of(Hash) }+ it { expect(subject).to be_kind_of(Hash) }it do- expect(subject.serializable_hash).to eq(+ expect(subject).to eq({data: {id: wishlist.id.to_s,@@ -35,4 +35,6 @@ describe Spree::V2::Storefront::WishlistSerializer do})end++ it_behaves_like 'an ActiveJob serializable hash'enddiff --git a/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb b/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rbindex b45b3b4b43..9797bff39b 100644--- a/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb+++ b/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb@@ -2,18 +2,33 @@ require 'spec_helper'describe Spree::Webhooks::Subscribers::HandleRequest dodescribe '#call' do- subject { described_class.new(body: body, event: event, subscriber: subscriber) }+ subject { described_class.new(body: body, event_name: event_name, subscriber: subscriber) }- let(:body) { { data: {} }.to_json }- let(:event) { 'order.canceled' }- let(:request_double) { instance_double(Spree::Webhooks::Subscribers::MakeRequest) }- let(:subscriber) { create(:subscriber, url: url) }+ let(:body) do+ Spree::Api::V2::Platform::AddressSerializer.new(resource).serializable_hash.merge(+ event_created_at: event.created_at,+ event_id: event.id,+ event_type: event.name+ ).to_json+ end+ let(:event_name) { 'order.canceled' }+ let(:event) { create(:event, :blank, name: event_name, subscriber_id: subscriber.id, url: url) }+ let(:make_request_double) { instance_double(Spree::Webhooks::Subscribers::MakeRequest) }+ let(:subscriber) { create(:subscriber, :active, subscriptions: [event_name], url: url) }let(:url) { 'http://google.com/' }+ let(:resource) { create(:address) }shared_examples 'logging and creating a webhooks event' do |with_log_level:|before do- allow(subject).to receive(:request).and_return(request_double)- allow(request_double).to(+ expect(Spree::Webhooks::Event).to(+ receive(:create).+ with(name: event_name, subscriber_id: subscriber.id, url: url).+ and_return(event)+ )+ expect(Spree::Webhooks::Subscribers::MakeRequest).to(+ receive(:new).with(body: body, url: url).and_return(make_request_double)+ )+ allow(make_request_double).to(receive_messages(execution_time: execution_time,failed_request?: failed_request,@@ -28,7 +43,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest doallow(Rails.logger).to receive(:debug)subject.callmessage_fst = "[SPREE WEBHOOKS] 'order.canceled' sending to 'http://google.com/'"- message_snd = "[SPREE WEBHOOKS] 'order.canceled' body: #{body}"+ message_snd = "[SPREE WEBHOOKS] 'order.canceled' body: #{JSON.parse(body)}"expect(Rails.logger).to have_received(:debug).with(message_fst)expect(Rails.logger).to have_received(:debug).with(message_snd)end@@ -39,10 +54,17 @@ describe Spree::Webhooks::Subscribers::HandleRequest doexpect(Rails.logger).to have_received(with_log_level).with(log_msg)end- it 'creates a webhooks event with the process info' do+ it 'updates the event record created previously with the missing data' doexpect { subject.call }.to change {- Spree::Webhooks::Event.all.as_json(except: %i[created_at id preferences updated_at]).map(&:values)- }.from([]).to([[execution_time, event, log_msg, response_code.to_s, subscriber.id, success, url]])+ Spree::Webhooks::Event.+ find(event.id).+ as_json(except: %i[created_at id preferences updated_at]).+ values+ }.from(+ [nil, event_name, nil, nil, subscriber.id, nil, url]+ ).to(+ [execution_time, event_name, log_msg, response_code.to_s, subscriber.id, success, url]+ )endit { expect(subject.call).to eq(nil) }@@ -84,5 +106,38 @@ describe Spree::Webhooks::Subscribers::HandleRequest doit_behaves_like 'logging and creating a webhooks event', with_log_level: :debugendend++ context 'full flow' do+ let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order.reload).serializable_hash }+ let(:body_with_event_metadata) { body.merge(event_created_at: event.created_at, event_id: event.id, event_type: event.name).to_json }+ let(:event) { Spree::Webhooks::Event.find_by(name: event_name, subscriber_id: subscriber.id) }+ let(:event_name) { 'order.placed' }+ let(:order) { create(:order, email: '[email protected]') }++ before do+ stub_request(:post, url)+ subscriber+ end++ it 'queues a job without event data on the webhook body right after the event is executed', :job do+ with_webhooks_enabled do+ order.finalize!+ expect(Spree::Webhooks::Subscribers::MakeRequestJob).to(+ have_been_enqueued.+ on_queue('spree_webhooks').+ with(body.to_json, event_name, subscriber).+ once+ )+ end+ end++ it 'adds the event data to the body after executing the job' do+ with_webhooks_enabled do+ allow(Spree::Webhooks::Subscribers::MakeRequest).to receive(:new).and_call_original+ order.finalize!+ expect(Spree::Webhooks::Subscribers::MakeRequest).to have_received(:new).with(body: body_with_event_metadata, url: url)+ end+ end+ endendenddiff --git a/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb b/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rbindex 5b36e2271a..70007817bf 100644--- a/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb+++ b/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb@@ -2,9 +2,9 @@ require 'spec_helper'describe Spree::Webhooks::Subscribers::QueueRequests, :job, :spree_webhooks dodescribe '#call' do- subject { described_class.call(event: event, body: body) }+ subject { described_class.call(body: body, event_name: event_name) }- let(:event) { 'order.finalize' }+ let(:event_name) { 'order.finalize' }let(:body) { {} }let(:queue) { 'spree_webhooks' }let(:make_request_job) { Spree::Webhooks::Subscribers::MakeRequestJob }@@ -16,7 +16,7 @@ describe Spree::Webhooks::Subscribers::QueueRequests, :job, :spree_webhooks doit doexpect { subject }.to(- have_enqueued_job(make_request_job).with(body, event, subscriber).on_queue(queue)+ have_enqueued_job(make_request_job).with(body, event_name, subscriber).on_queue(queue))endend@@ -39,14 +39,14 @@ describe Spree::Webhooks::Subscribers::QueueRequests, :job, :spree_webhooks doendcontext 'when subscriber subscriptions includes the specific event being used' do- let(:subscriptions) { [event] }+ let(:subscriptions) { [event_name] }include_examples 'queues a job to make a request', 'https://url2.com/'endcontext 'when subscriber subscriptions are not active' dolet!(:subscriber) do- create(:subscriber, url: 'https://url3.com/', subscriptions: [event])+ create(:subscriber, url: 'https://url3.com/', subscriptions: [event_name])endinclude_examples 'does not queue a job to make a request'diff --git a/api/spec/services/spree/webhooks_spec.rb b/api/spec/services/spree/webhooks_spec.rbindex 4623c78969..4aa3a6213b 100644--- a/api/spec/services/spree/webhooks_spec.rb+++ b/api/spec/services/spree/webhooks_spec.rb@@ -2,9 +2,10 @@ require 'spec_helper'describe Spree::Webhooks dodescribe '#disable_webhooks' do- let(:variant) { create(:variant) }- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash.to_json }+ let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }+ let(:event_name) { 'variant.discontinued' }let(:queue_requests) { instance_double(Spree::Webhooks::Subscribers::QueueRequests) }+ let(:variant) { create(:variant) }before doallow(Spree::Webhooks::Subscribers::QueueRequests).to receive(:new).and_return(queue_requests)@@ -39,24 +40,23 @@ describe Spree::Webhooks doit 'does not emit the event' dodescribed_class.disable_webhooks { variant.discontinue! }- expect(queue_requests).not_to have_received(:call).with(event: 'variant.discontinued', body: body)+ expect(queue_requests).not_to have_received(:call).with(event: event_name, body: body)endenddescribe 'when webhooks are enabled' do- before { ENV['DISABLE_SPREE_WEBHOOKS'] = nil }-describe 'when not using #disable_webhooks' doit 'emits the event' do- variant.discontinue!- expect(queue_requests).to have_received(:call).with(event: 'variant.discontinued', body: body).once+ expect do+ variant.discontinue!+ end.to emit_webhook_event(event_name)endenddescribe 'when using #disable_webhooks' doit 'does not emit the event' dodescribed_class.disable_webhooks { variant.discontinue! }- expect(queue_requests).not_to have_received(:call).with(event: 'variant.discontinued', body: body)+ expect(queue_requests).not_to have_received(:call).with(event: event_name, body: body)endendenddiff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rbindex b18d13bdd1..f664c020b1 100644--- a/api/spec/spec_helper.rb+++ b/api/spec/spec_helper.rb@@ -43,6 +43,7 @@ require 'spree/testing_support/rspec_retry_config'require 'spree/api/testing_support/caching'require 'spree/api/testing_support/jobs'require 'spree/api/testing_support/helpers'+require 'spree/api/testing_support/serializers'require 'spree/api/testing_support/setup'require 'spree/api/testing_support/spree_webhooks'require 'spree/api/testing_support/matchers/webhooks'diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rbindex d6c03f25bf..6ea5459776 100644--- a/core/lib/spree/testing_support/common_rake.rb+++ b/core/lib/spree/testing_support/common_rake.rb@@ -36,6 +36,7 @@ namespace :common do]puts 'Setting up dummy database...'+ system('bin/rails db:environment:set RAILS_ENV=test')system('bundle exec rake db:drop db:create')Spree::DummyModelGenerator.startsystem('bundle exec rake db:migrate')