Skip to content

Commit f85b6ea

Browse files
committed
fix: set consumer and provider to nil on the underlying webhook when they are not specified in the incoming webhook JSON
Closes: pact-foundation#334
1 parent 18c0073 commit f85b6ea

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/pact_broker/api/decorators/webhook_decorator.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ module PactBroker
1111
module Api
1212
module Decorators
1313
class WebhookDecorator < BaseDecorator
14-
1514
class WebhookEventDecorator < BaseDecorator
1615
property :name
1716
end
1817

1918
property :description, getter: lambda { |context| context[:represented].display_description }
2019

21-
property :consumer, :class => PactBroker::Domain::Pacticipant do
20+
property :consumer, :class => PactBroker::Domain::Pacticipant, default: nil do
2221
property :name
2322
end
2423

25-
property :provider, :class => PactBroker::Domain::Pacticipant do
24+
property :provider, :class => PactBroker::Domain::Pacticipant, default: nil do
2625
property :name
2726
end
2827

spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ module Decorators
189189
expect(parsed_object.events.first.name).to eq PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME
190190
end
191191
end
192+
193+
context "when the decorated object has a consumer/provider but the incoming JSON does not" do
194+
let(:webhook) do
195+
Domain::Webhook.new(
196+
consumer: Domain::Pacticipant.new(name: 'consumer'),
197+
provider: Domain::Pacticipant.new(name: 'provider')
198+
)
199+
end
200+
201+
it "sets the consumer and provider to nil on the decorated object" do
202+
expect(parsed_object.consumer).to be nil
203+
expect(parsed_object.provider).to be nil
204+
end
205+
end
192206
end
193207
end
194208
end

0 commit comments

Comments
 (0)