Skip to content

Commit

Permalink
fix: set consumer and provider to nil on the underlying webhook when …
Browse files Browse the repository at this point in the history
…they are not specified in the incoming webhook JSON

Closes: #334
  • Loading branch information
bethesque committed Mar 29, 2020
1 parent 18c0073 commit f85b6ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/pact_broker/api/decorators/webhook_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f85b6ea

Please sign in to comment.