Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Rename all occurrences of webhooks "body" to "webhook_payload_body". (#11528)

sebffc865ad7b7f
diff --git a/api/app/jobs/spree/webhooks/subscribers/make_request_job.rb b/api/app/jobs/spree/webhooks/subscribers/make_request_job.rb
index d141146eda..cfa8a15416 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,11 @@ module Spree
class MakeRequestJob < Spree::BaseJob
queue_as :spree_webhooks
- def perform(body, event_name, subscriber)
+ def perform(webhook_payload_body, event_name, subscriber)
Spree::Webhooks::Subscribers::HandleRequest.new(
- body: body, event_name: event_name, subscriber: subscriber
+ event_name: event_name,
+ subscriber: subscriber,
+ webhook_payload_body: webhook_payload_body
).call
end
end
diff --git a/api/app/models/concerns/spree/webhooks/has_webhooks.rb b/api/app/models/concerns/spree/webhooks/has_webhooks.rb
index 22457c43a3..a97ecc715e 100644
--- a/api/app/models/concerns/spree/webhooks/has_webhooks.rb
+++ b/api/app/models/concerns/spree/webhooks/has_webhooks.rb
@@ -9,10 +9,10 @@ module Spree
after_update_commit(proc { queue_webhooks_requests!(inferred_event_name(:update)) })
def queue_webhooks_requests!(event_name)
- return if disable_spree_webhooks? || body.blank?
+ return if disable_spree_webhooks? || webhook_payload_body.blank?
return if update_event?(event_name) && updating_only_timestamps?
- Spree::Webhooks::Subscribers::QueueRequests.call(body: body, event_name: event_name)
+ Spree::Webhooks::Subscribers::QueueRequests.call(event_name: event_name, webhook_payload_body: webhook_payload_body)
end
def self.default_webhook_events
@@ -29,7 +29,7 @@ module Spree
private
- def body
+ def webhook_payload_body
resource_serializer.new(self).serializable_hash.to_json
end
diff --git a/api/app/services/spree/webhooks/subscribers/handle_request.rb b/api/app/services/spree/webhooks/subscribers/handle_request.rb
index d3063c75da..59a7a58c9f 100644
--- a/api/app/services/spree/webhooks/subscribers/handle_request.rb
+++ b/api/app/services/spree/webhooks/subscribers/handle_request.rb
@@ -4,18 +4,18 @@ module Spree
module Webhooks
module Subscribers
class HandleRequest
- def initialize(body:, event_name:, subscriber:)
- @body = JSON.parse(body)
+ def initialize(event_name:, subscriber:, webhook_payload_body:)
@event_name = event_name
@subscriber = subscriber
+ @webhook_payload_body = JSON.parse(webhook_payload_body)
end
def call
Rails.logger.debug(msg("sending to '#{url}'"))
- Rails.logger.debug(msg("body: #{body_with_event_metadata}"))
+ Rails.logger.debug(msg("webhook_payload_body: #{body_with_event_metadata}"))
if request.unprocessable_uri?
- return process(:warn, msg("can not make a request to '#{url}'"))
+ return process(:warn, msg("can not make a request to '#{url}'"))
end
return process(:warn, msg("failed for '#{url}'")) if request.failed_request?
@@ -24,9 +24,11 @@ module Spree
private
- attr_reader :body, :event_name, :subscriber
+ attr_reader :webhook_payload_body, :event_name, :subscriber
- delegate :url, to: :subscriber
+ delegate :execution_time, :failed_request?, :response_code, :success?, :unprocessable_uri?, to: :request
+ delegate :id, :url, to: :subscriber
+ delegate :created_at, :id, to: :event, prefix: true
def process(log_level, msg)
Rails.logger.public_send(log_level, msg)
@@ -37,13 +39,13 @@ module Spree
def request
@request ||=
- Spree::Webhooks::Subscribers::MakeRequest.new(body: body_with_event_metadata, url: url)
+ Spree::Webhooks::Subscribers::MakeRequest.new(webhook_payload_body: body_with_event_metadata, url: url)
end
alias make_request request
def body_with_event_metadata
- body.
- merge(event_created_at: event.created_at, event_id: event.id, event_type: event.name).
+ webhook_payload_body.
+ merge(event_created_at: event_created_at, event_id: event_id, event_type: event.name).
to_json
end
@@ -55,10 +57,10 @@ module Spree
def update_event(msg)
event.update(
- execution_time: request.execution_time,
+ execution_time: execution_time,
request_errors: msg,
- response_code: request.response_code,
- success: request.success?
+ response_code: response_code,
+ success: success?
)
end
diff --git a/api/app/services/spree/webhooks/subscribers/make_request.rb b/api/app/services/spree/webhooks/subscribers/make_request.rb
index a954856335..eb673bdeb9 100644
--- a/api/app/services/spree/webhooks/subscribers/make_request.rb
+++ b/api/app/services/spree/webhooks/subscribers/make_request.rb
@@ -4,10 +4,10 @@ module Spree
module Webhooks
module Subscribers
class MakeRequest
- def initialize(body:, url:)
- @body = body
+ def initialize(url:, webhook_payload_body:)
@execution_time_in_milliseconds = 0
@url = url
+ @webhook_payload_body = webhook_payload_body
@webhooks_timeout = ENV['SPREE_WEBHOOKS_TIMEOUT']
end
@@ -34,7 +34,7 @@ module Spree
private
- attr_reader :body, :execution_time_in_milliseconds, :url, :webhooks_timeout
+ attr_reader :execution_time_in_milliseconds, :url, :webhook_payload_body, :webhooks_timeout
HEADERS = { 'Content-Type' => 'application/json' }.freeze
private_constant :HEADERS
@@ -50,7 +50,7 @@ module Spree
def request
req = Net::HTTP::Post.new(uri_path, HEADERS)
- req.body = body
+ req.body = webhook_payload_body
@request ||= begin
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
request_result = http.request(req)
diff --git a/api/app/services/spree/webhooks/subscribers/queue_requests.rb b/api/app/services/spree/webhooks/subscribers/queue_requests.rb
index 6db2a943ee..ccdecfac1c 100644
--- a/api/app/services/spree/webhooks/subscribers/queue_requests.rb
+++ b/api/app/services/spree/webhooks/subscribers/queue_requests.rb
@@ -4,9 +4,11 @@ module Spree
class QueueRequests
prepend Spree::ServiceModule::Base
- def call(body:, event_name:)
+ def call(event_name:, webhook_payload_body:)
Spree::Webhooks::Subscriber.active.with_urls_for(event_name).each do |subscriber|
- Spree::Webhooks::Subscribers::MakeRequestJob.perform_later(body, event_name, subscriber)
+ Spree::Webhooks::Subscribers::MakeRequestJob.perform_later(
+ webhook_payload_body, event_name, subscriber
+ )
end
end
end
diff --git a/api/lib/spree/api/testing_support/matchers/webhooks.rb b/api/lib/spree/api/testing_support/matchers/webhooks.rb
index 29d451aa14..b1ddb266ac 100644
--- a/api/lib/spree/api/testing_support/matchers/webhooks.rb
+++ b/api/lib/spree/api/testing_support/matchers/webhooks.rb
@@ -1,6 +1,6 @@
# Passes if executing the code in the block there is a
# `Spree::Webhooks::Subscribers::QueueRequests.call` method
-# call with the given `event` and `body` arguments just once.
+# call with the given `event` and `webhook_payload_body` arguments just once.
#
# @example
# expect { order.complete }.to emit_webhook_event('order.paid')
@@ -11,7 +11,7 @@
#
# It can also be negated, resulting in the expectation
# waiting to not receive a `call` method call with the
-# given `event` and `body` (`once` isn't taken into consideration).
+# given `event` and `webhook_payload_body` (`once` isn't taken into consideration).
#
# @example
# expect { order.complete }.not_to emit_webhook_event('order.paid')
@@ -22,7 +22,7 @@
#
# == Notes
#
-# The matcher relies on a `body` method previously defined which
+# The matcher relies on a `webhook_payload_body` method previously defined which
# isn't added to the matcher definition, because it acts in a different
# way depending on what's the resource being tested.
#
@@ -36,25 +36,25 @@ RSpec::Matchers.define :emit_webhook_event do |event_to_emit|
with_webhooks_enabled { Timecop.freeze { block.call } }
expect(queue_requests).to(
- have_received(:call).with(body: body.to_json, event_name: event_to_emit).once
+ have_received(:call).with(event_name: event_to_emit, webhook_payload_body: webhook_payload_body.to_json).once
)
end
- def block_body_definition(obj_method)
+ def block_definition(obj_method)
# positive look-behinds must have a fixed length, using a straightforward match instead
obj_method.source.squish[/(expect *({|do) *)(.*?)( *(}|end).(not_)*to)/, 3]
end
failure_message do |obj_method|
- block_body_def = block_body_definition(obj_method)
- "Expected that executing `#{block_body_def}` emits the `#{event_to_emit}` Webhook event.\n" \
- "Check that `#{block_body_def}` does implement `queue_webhooks_requests!` for " \
- "`#{event_to_emit}` with the following body: \n\n#{body}."
+ block_def = block_definition(obj_method)
+ "Expected that executing `#{block_def}` emits the `#{event_to_emit}` Webhook event.\n" \
+ "Check that `#{block_def}` does implement `queue_webhooks_requests!` for " \
+ "`#{event_to_emit}` with the following webhook_payload_body: \n\n#{webhook_payload_body}."
end
failure_message_when_negated do |obj_method|
- "Expected that executing `#{block_body_definition(obj_method)}` does not " \
- "emit the `#{event_to_emit}` Webhook event with the following body: #{body}."
+ "Expected that executing `#{block_definition(obj_method)}` does not " \
+ "emit the `#{event_to_emit}` Webhook event with the following webhook_payload_body: #{webhook_payload_body}."
end
supports_block_expectations
diff --git a/api/spec/jobs/spree/webhooks/endpoints/make_request_job_spec.rb b/api/spec/jobs/spree/webhooks/endpoints/make_request_job_spec.rb
index ae3def774d..3a180d2080 100644
--- a/api/spec/jobs/spree/webhooks/endpoints/make_request_job_spec.rb
+++ b/api/spec/jobs/spree/webhooks/endpoints/make_request_job_spec.rb
@@ -1,17 +1,17 @@
require 'spec_helper'
describe Spree::Webhooks::Subscribers::MakeRequestJob do
- let(:body) { {} }
let(:event) { 'order.cancel' }
let(:queue) { 'spree_webhooks' }
let(:subscriber) { create(:subscriber, :active) }
+ let(:webhook_payload_body) { {} }
it 'enqueues a HTTP request using Spree::Webhooks::Subscribers::HandleRequest', :job do
- expect { described_class.perform_later(body, event, subscriber, 1) }.to have_enqueued_job.on_queue(queue)
+ expect { described_class.perform_later(webhook_payload_body, event, subscriber, 1) }.to have_enqueued_job.on_queue(queue)
end
it 'does not raise if used with the expected arguments', :job do
allow(Spree::Webhooks::Subscribers::HandleRequest).to receive_message_chain(:new, :call)
- expect { described_class.perform_now(body, event, subscriber) }.not_to raise_error
+ expect { described_class.perform_now(webhook_payload_body, event, subscriber) }.not_to raise_error
end
end
diff --git a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb
index 26f5f77bb5..fb6b1ecbe3 100644
--- a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb
+++ b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb
@@ -45,9 +45,10 @@ describe Spree::Webhooks::HasWebhooks do
end
context 'without DISABLE_SPREE_WEBHOOKS' do
- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }
context 'after_create_commit' do
+ let(:event_name) { 'product.create' }
it { expect { product.save }.to emit_webhook_event('product.create') }
end
@@ -64,7 +65,7 @@ describe Spree::Webhooks::HasWebhooks do
end
context 'with a class name with multiple words' do
- let(:body) { Spree::Api::V2::Platform::CmsPageSerializer.new(cms_page).serializable_hash }
+ let(:webhook_payload_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' }
diff --git a/api/spec/models/spree/api/webhooks/order_decorator_spec.rb b/api/spec/models/spree/api/webhooks/order_decorator_spec.rb
index 102fd5b07a..70a602d5a9 100644
--- a/api/spec/models/spree/api/webhooks/order_decorator_spec.rb
+++ b/api/spec/models/spree/api/webhooks/order_decorator_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Spree::Api::Webhooks::OrderDecorator do
let(:store) { create(:store, default: true) }
- let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash }
describe 'order.canceled' do
describe 'completed -> canceled' do
diff --git a/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb b/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb
index 2126a1f170..c271ced7fd 100644
--- a/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb
+++ b/api/spec/models/spree/api/webhooks/payment_decorator_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Spree::Api::Webhooks::PaymentDecorator do
- let(:body) { Spree::Api::V2::Platform::PaymentSerializer.new(payment).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::PaymentSerializer.new(payment).serializable_hash }
let(:payment) { create(:payment) }
before { allow(payment).to receive_message_chain(:state_changes, :create!) }
@@ -55,7 +55,7 @@ describe Spree::Api::Webhooks::PaymentDecorator do
describe 'order.paid' do
subject { Timecop.freeze { another_payment.complete } }
- let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order).serializable_hash }
+ let(:webhook_payload_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) }
diff --git a/api/spec/models/spree/api/webhooks/product_decorator_spec.rb b/api/spec/models/spree/api/webhooks/product_decorator_spec.rb
index ae05c9b907..249f73ce73 100644
--- a/api/spec/models/spree/api/webhooks/product_decorator_spec.rb
+++ b/api/spec/models/spree/api/webhooks/product_decorator_spec.rb
@@ -4,7 +4,7 @@ describe Spree::Api::Webhooks::ProductDecorator do
let(:product) { create(:product) }
context 'emitting product.discontinued' do
- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }
let(:event_name) { 'product.discontinued' }
context 'when product discontinued_on changes' do
diff --git a/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rb b/api/spec/models/spree/api/webhooks/shipment_decorator_spec.rb
index d2b2aff161..356e81ffbc 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,7 @@ describe Spree::Api::Webhooks::ShipmentDecorator do
end
context 'emitting shipment.shipped' do
- let(:body) { Spree::Api::V2::Platform::ShipmentSerializer.new(shipment).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::ShipmentSerializer.new(shipment).serializable_hash }
let(:event_name) { 'shipment.shipped' }
context 'ready -> ship' do
@@ -36,7 +36,7 @@ describe Spree::Api::Webhooks::ShipmentDecorator do
end
context 'emitting order.shipped' do
- let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order.reload).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::OrderSerializer.new(order.reload).serializable_hash }
let(:event_name) { 'order.shipped' }
let!(:shipments) do
create_list(
diff --git a/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb b/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb
index 2565e77aea..9fb66f862d 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,7 +1,7 @@
require 'spec_helper'
describe Spree::Api::Webhooks::StockItemDecorator do
- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }
+ let(:webhook_payload_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 }
@@ -9,7 +9,7 @@ describe Spree::Api::Webhooks::StockItemDecorator do
describe 'emitting product.backorderable' do
subject { stock_item.update(backorderable: backorderable) }
- let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }
+ let(:webhook_payload_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) }
diff --git a/api/spec/models/spree/api/webhooks/stock_movement_decorator_spec.rb b/api/spec/models/spree/api/webhooks/stock_movement_decorator_spec.rb
index 892bbf3156..9eaa622bd3 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,7 +1,7 @@
require 'spec_helper'
describe Spree::Api::Webhooks::StockMovementDecorator do
- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant.reload).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::VariantSerializer.new(variant.reload).serializable_hash }
let(:stock_item) { create(:stock_item) }
let(:stock_location) { variant.stock_locations.first }
@@ -10,7 +10,7 @@ describe Spree::Api::Webhooks::StockMovementDecorator do
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 }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }
describe 'emitting product.out_of_stock' do
let(:event_name) { 'product.out_of_stock' }
diff --git a/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb b/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb
index d647b79e1c..b262d635c4 100644
--- a/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb
+++ b/api/spec/models/spree/api/webhooks/variant_decorator_spec.rb
@@ -4,7 +4,7 @@ describe Spree::Api::Webhooks::VariantDecorator do
let(:variant) { create(:variant) }
context 'emitting variant.discontinued' do
- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }
let(:event_name) { 'variant.discontinued' }
context 'when variant discontinued_on changes' do
diff --git a/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb b/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb
index daef918a56..03ae8f5f4d 100644
--- a/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb
+++ b/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb
@@ -2,9 +2,15 @@ require 'spec_helper'
describe Spree::Webhooks::Subscribers::HandleRequest do
describe '#call' do
- subject { described_class.new(body: body, event_name: event_name, subscriber: subscriber) }
+ subject do
+ described_class.new(
+ event_name: event_name,
+ subscriber: subscriber,
+ webhook_payload_body: webhook_payload_body
+ )
+ end
- let(:body) do
+ let(:webhook_payload_body) do
Spree::Api::V2::Platform::AddressSerializer.new(resource).serializable_hash.to_json
end
let(:event_name) { 'order.canceled' }
@@ -19,7 +25,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
context 'before making the request' do
let(:body_with_event_metadata) do
- JSON.parse(body).merge(
+ JSON.parse(webhook_payload_body).merge(
event_created_at: event.created_at,
event_id: event.id,
event_type: event.name
@@ -31,11 +37,11 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
allow(Spree::Webhooks::Subscribers::MakeRequest).to receive(:new).and_call_original
subject.call
message_fst = "[SPREE WEBHOOKS] 'order.canceled' sending to 'http://google.com/'"
- message_snd = "[SPREE WEBHOOKS] 'order.canceled' body: #{body_with_event_metadata}"
+ message_snd = "[SPREE WEBHOOKS] 'order.canceled' webhook_payload_body: #{body_with_event_metadata}"
expect(Rails.logger).to have_received(:debug).with(message_fst)
expect(Rails.logger).to have_received(:debug).with(message_snd)
expect(Spree::Webhooks::Subscribers::MakeRequest).to(
- have_received(:new).with(body: body_with_event_metadata, url: url)
+ have_received(:new).with(webhook_payload_body: body_with_event_metadata, url: url)
)
end
@@ -128,7 +134,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
end
context 'full flow' do
- let(:body) { Spree::Api::V2::Platform::OrderSerializer.new(order.reload).serializable_hash }
+ let(:webhook_payload_body) { Spree::Api::V2::Platform::OrderSerializer.new(order.reload).serializable_hash }
let(:event) { Spree::Webhooks::Event.find_by(name: event_name, subscriber_id: subscriber.id, url: url) }
let(:event_name) { 'order.placed' }
let(:order) { create(:order, email: '[email protected]') }
@@ -144,7 +150,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
expect(Spree::Webhooks::Subscribers::MakeRequestJob).to(
have_been_enqueued.
on_queue('spree_webhooks').
- with(body.to_json, event_name, subscriber).
+ with(webhook_payload_body.to_json, event_name, subscriber).
once
)
end
@@ -152,7 +158,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
context 'after executing the job' do
let(:body_with_event_metadata) do
- body.merge(
+ webhook_payload_body.merge(
event_created_at: event.created_at, event_id: event.id, event_type: event.name
).to_json
end
@@ -162,7 +168,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest 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)
+ have_received(:new).with(webhook_payload_body: body_with_event_metadata, url: url)
)
end
end
@@ -174,7 +180,7 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
with_webhooks_enabled do
expect do
described_class.new(
- body: body,
+ webhook_payload_body: webhook_payload_body,
event_name: nil, # forces a validation error
subscriber: subscriber
).call
diff --git a/api/spec/services/spree/webhooks/subscribers/make_request_spec.rb b/api/spec/services/spree/webhooks/subscribers/make_request_spec.rb
index e93af7ec5e..e761ea995b 100644
--- a/api/spec/services/spree/webhooks/subscribers/make_request_spec.rb
+++ b/api/spec/services/spree/webhooks/subscribers/make_request_spec.rb
@@ -1,12 +1,12 @@
require 'spec_helper'
describe Spree::Webhooks::Subscribers::MakeRequest do
- let(:body) { { data: [{}] }.to_json }
let(:http_double) { instance_double(Net::HTTP) }
let(:url) { 'http://google.com/' }
+ let(:webhook_payload_body) { { data: [{}] }.to_json }
describe '#execution_time' do
- subject { described_class.new(body: body, url: url).execution_time }
+ subject { described_class.new(webhook_payload_body: webhook_payload_body, url: url).execution_time }
before do
stub_request(:post, url)
@@ -36,7 +36,7 @@ describe Spree::Webhooks::Subscribers::MakeRequest do
end
describe '#failed_request?' do
- subject { described_class.new(body: body, url: url).failed_request? }
+ subject { described_class.new(webhook_payload_body: webhook_payload_body, url: url).failed_request? }
before { stub_request(:post, url) }
@@ -52,9 +52,9 @@ describe Spree::Webhooks::Subscribers::MakeRequest do
subject
end
- it 'makes a post HTTP request to the given url and body' do
+ it 'makes a post HTTP request to the given url and webhook_payload_body' do
subject
- expect(WebMock).to have_requested(:post, url).with(body: body, headers: headers).once
+ expect(WebMock).to have_requested(:post, url).with(body: webhook_payload_body, headers: headers).once
end
end
@@ -82,11 +82,11 @@ describe Spree::Webhooks::Subscribers::MakeRequest do
subject
end
- it 'makes a post HTTP request to the given url and body' do
+ it 'makes a post HTTP request to the given url and webhook_payload_body' do
allow(Net::HTTP).to receive(:new).and_return(http)
allow(http).to receive(:use_ssl=).with(true)
subject
- expect(WebMock).to have_requested(:post, url).with(body: body, headers: headers).once
+ expect(WebMock).to have_requested(:post, url).with(body: webhook_payload_body, headers: headers).once
end
end
end
@@ -153,7 +153,7 @@ describe Spree::Webhooks::Subscribers::MakeRequest do
end
describe '#response_code' do
- subject { described_class.new(body: body, url: url).response_code }
+ subject { described_class.new(webhook_payload_body: webhook_payload_body, url: url).response_code }
context 'when request raises an Errno::ECONNREFUSED exception' do
before do
@@ -190,7 +190,7 @@ describe Spree::Webhooks::Subscribers::MakeRequest do
end
describe '#success?' do
- subject { described_class.new(body: body, url: url) }
+ subject { described_class.new(webhook_payload_body: webhook_payload_body, url: url) }
context 'when unprocessable_uri? equals true' do
before { allow(subject).to receive(:unprocessable_uri?).and_return(true) }
@@ -218,7 +218,7 @@ describe Spree::Webhooks::Subscribers::MakeRequest do
end
describe '#unprocessable_uri?' do
- subject { described_class.new(body: body, url: url) }
+ subject { described_class.new(webhook_payload_body: webhook_payload_body, url: url) }
before { allow(subject).to receive(:URI).with(url).and_return(uri) }
diff --git a/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb b/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb
index 70007817bf..0d7b41e5f2 100644
--- a/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb
+++ b/api/spec/services/spree/webhooks/subscribers/queue_requests_spec.rb
@@ -2,10 +2,10 @@ require 'spec_helper'
describe Spree::Webhooks::Subscribers::QueueRequests, :job, :spree_webhooks do
describe '#call' do
- subject { described_class.call(body: body, event_name: event_name) }
+ subject { described_class.call(event_name: event_name, webhook_payload_body: webhook_payload_body) }
let(:event_name) { 'order.finalize' }
- let(:body) { {} }
+ let(:webhook_payload_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 do
it do
expect { subject }.to(
- have_enqueued_job(make_request_job).with(body, event_name, subscriber).on_queue(queue)
+ have_enqueued_job(make_request_job).with(webhook_payload_body, event_name, subscriber).on_queue(queue)
)
end
end
diff --git a/api/spec/services/spree/webhooks_spec.rb b/api/spec/services/spree/webhooks_spec.rb
index 4aa3a6213b..a6d8efdb12 100644
--- a/api/spec/services/spree/webhooks_spec.rb
+++ b/api/spec/services/spree/webhooks_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Spree::Webhooks do
describe '#disable_webhooks' do
- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }
+ let(:webhook_payload_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) }
@@ -40,7 +40,7 @@ describe Spree::Webhooks do
it 'does not emit the event' do
described_class.disable_webhooks { variant.discontinue! }
- expect(queue_requests).not_to have_received(:call).with(event: event_name, body: body)
+ expect(queue_requests).not_to have_received(:call).with(event: event_name, webhook_payload_body: webhook_payload_body)
end
end
@@ -56,7 +56,7 @@ describe Spree::Webhooks do
describe 'when using #disable_webhooks' do
it 'does not emit the event' do
described_class.disable_webhooks { variant.discontinue! }
- expect(queue_requests).not_to have_received(:call).with(event: event_name, body: body)
+ expect(queue_requests).not_to have_received(:call).with(event: event_name, webhook_payload_body: webhook_payload_body)
end
end
end