From f85b6ea2033a9cc90e62e2019ff31a5d5cb84c44 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 30 Mar 2020 08:43:40 +1100 Subject: [PATCH] fix: set consumer and provider to nil on the underlying webhook when they are not specified in the incoming webhook JSON Closes: https://github.com/pact-foundation/pact_broker/issues/334 --- .../api/decorators/webhook_decorator.rb | 5 ++--- .../api/decorators/webhook_decorator_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/pact_broker/api/decorators/webhook_decorator.rb b/lib/pact_broker/api/decorators/webhook_decorator.rb index f82c13e15..733e26803 100644 --- a/lib/pact_broker/api/decorators/webhook_decorator.rb +++ b/lib/pact_broker/api/decorators/webhook_decorator.rb @@ -11,18 +11,17 @@ module PactBroker module Api module Decorators class WebhookDecorator < BaseDecorator - class WebhookEventDecorator < BaseDecorator property :name end property :description, getter: lambda { |context| context[:represented].display_description } - property :consumer, :class => PactBroker::Domain::Pacticipant do + property :consumer, :class => PactBroker::Domain::Pacticipant, default: nil do property :name end - property :provider, :class => PactBroker::Domain::Pacticipant do + property :provider, :class => PactBroker::Domain::Pacticipant, default: nil do property :name end diff --git a/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb index 1ae45a590..510c4d15d 100644 --- a/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb @@ -189,6 +189,20 @@ module Decorators expect(parsed_object.events.first.name).to eq PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME end end + + context "when the decorated object has a consumer/provider but the incoming JSON does not" do + let(:webhook) do + Domain::Webhook.new( + consumer: Domain::Pacticipant.new(name: 'consumer'), + provider: Domain::Pacticipant.new(name: 'provider') + ) + end + + it "sets the consumer and provider to nil on the decorated object" do + expect(parsed_object.consumer).to be nil + expect(parsed_object.provider).to be nil + end + end end end end