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