From 2db5616102b07720faf73c3c4ebba095e9f44f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Denquin?= Date: Fri, 3 Jun 2022 15:30:06 +0200 Subject: [PATCH] fix: #246 bug object type root object is missing on webhook (#247) * fix: #246 add object type root key in webhook payload * add spec to avoid regression --- app/services/webhooks/base_service.rb | 6 +++--- spec/services/webhooks/invoices_service_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/services/webhooks/base_service.rb b/app/services/webhooks/base_service.rb index 8e46c6129b6..d5c81e798b3 100644 --- a/app/services/webhooks/base_service.rb +++ b/app/services/webhooks/base_service.rb @@ -12,11 +12,11 @@ def initialize(object) def call return unless current_organization&.webhook_url? - payload = object_serializer.serialize - payload = payload.merge( + payload = { webhook_type: webhook_type, object_type: object_type, - ) + object_type => object_serializer.serialize, + } http_client = LagoHttpClient::Client.new(current_organization.webhook_url) headers = generate_headers(payload) diff --git a/spec/services/webhooks/invoices_service_spec.rb b/spec/services/webhooks/invoices_service_spec.rb index 11d93ff940c..8af4a12f429 100644 --- a/spec/services/webhooks/invoices_service_spec.rb +++ b/spec/services/webhooks/invoices_service_spec.rb @@ -44,6 +44,16 @@ end end + it 'builds payload with the object type root key' do + webhook_invoice_service.call + + expect(LagoHttpClient::Client).to have_received(:new) + .with(organization.webhook_url) + expect(lago_client).to have_received(:post) do |payload| + expect(payload['invoice']).to be_present + end + end + context 'without webhook_url' do let(:webhook_url) { nil }