Skip to content

Commit

Permalink
feat(webhook): show user specified description instead of generated o…
Browse files Browse the repository at this point in the history
…ne in collection resource
  • Loading branch information
bethesque committed May 23, 2019
1 parent 302d70f commit 2643d95
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
12 changes: 2 additions & 10 deletions lib/pact_broker/api/decorators/webhook_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WebhookEventDecorator < BaseDecorator
property :name
end

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

property :consumer, :class => PactBroker::Domain::Pacticipant do
property :name
Expand All @@ -35,7 +35,7 @@ class WebhookEventDecorator < BaseDecorator

link :self do | options |
{
title: display_description,
title: represented.display_description,
href: webhook_url(represented.uuid, options[:base_url])
}

Expand Down Expand Up @@ -92,14 +92,6 @@ def from_json represented
end
end
end

def display_description
if represented.description && represented.description.strip.size > 0
represented.description
else
represented.scope_description
end
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/api/decorators/webhooks_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class WebhooksDecorator < BaseDecorator
links :'pb:webhooks' do | context |
represented.entries.collect do | webhook |
{
title: webhook.description,
name: webhook.request_description,
title: "Webhook",
name: webhook.display_description,
href: webhook_url(webhook.uuid, context[:base_url])
}
end
Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/domain/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def initialize attributes = {}
@updated_at = attributes[:updated_at]
end

def display_description
if description && description.strip.size > 0
description
else
request_description
end
end

def scope_description
if consumer && provider
"A webhook for the pact between #{consumer.name} and #{provider.name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ module Decorators
let(:description) { " " }

it 'uses the scope description' do
expect(parsed_json[:description]).to match /A webhook/
expect(parsed_json[:description]).to match /example.org/
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module Decorators
describe WebhooksDecorator do

let(:webhook) do
instance_double(Domain::Webhook, uuid: 'some-uuid', description: 'description', request_description: 'request description')
instance_double(Domain::Webhook,
uuid: 'some-uuid',
display_description: 'description'
)
end
let(:base_url) { 'http://example.org' }
let(:resource_url) { 'http://example.org/webhooks' }
Expand All @@ -31,15 +34,13 @@ module Decorators

it "includes a list of links to the webhooks" do
expect(subject[:_links][:'pb:webhooks']).to be_instance_of(Array)
expect(subject[:_links][:'pb:webhooks'].first).to eq title: 'description', name: 'request description', href: 'http://example.org/webhooks/some-uuid'
expect(subject[:_links][:'pb:webhooks'].first).to eq title: 'Webhook', name: 'description', href: 'http://example.org/webhooks/some-uuid'
end

it "includes curies" do
expect(subject[:_links][:curies]).to eq [{:name=>"pb", :href=>"http://example.org/doc/webhooks-{rel}", templated: true}]
end

end

end
end
end
Expand Down

0 comments on commit 2643d95

Please sign in to comment.