Skip to content

Commit 2643d95

Browse files
committed
feat(webhook): show user specified description instead of generated one in collection resource
1 parent 302d70f commit 2643d95

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

lib/pact_broker/api/decorators/webhook_decorator.rb

+2-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WebhookEventDecorator < BaseDecorator
1616
property :name
1717
end
1818

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

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

3636
link :self do | options |
3737
{
38-
title: display_description,
38+
title: represented.display_description,
3939
href: webhook_url(represented.uuid, options[:base_url])
4040
}
4141

@@ -92,14 +92,6 @@ def from_json represented
9292
end
9393
end
9494
end
95-
96-
def display_description
97-
if represented.description && represented.description.strip.size > 0
98-
represented.description
99-
else
100-
represented.scope_description
101-
end
102-
end
10395
end
10496
end
10597
end

lib/pact_broker/api/decorators/webhooks_decorator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class WebhooksDecorator < BaseDecorator
2424
links :'pb:webhooks' do | context |
2525
represented.entries.collect do | webhook |
2626
{
27-
title: webhook.description,
28-
name: webhook.request_description,
27+
title: "Webhook",
28+
name: webhook.display_description,
2929
href: webhook_url(webhook.uuid, context[:base_url])
3030
}
3131
end

lib/pact_broker/domain/webhook.rb

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def initialize attributes = {}
2626
@updated_at = attributes[:updated_at]
2727
end
2828

29+
def display_description
30+
if description && description.strip.size > 0
31+
description
32+
else
33+
request_description
34+
end
35+
end
36+
2937
def scope_description
3038
if consumer && provider
3139
"A webhook for the pact between #{consumer.name} and #{provider.name}"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ module Decorators
147147
let(:description) { " " }
148148

149149
it 'uses the scope description' do
150-
expect(parsed_json[:description]).to match /A webhook/
150+
expect(parsed_json[:description]).to match /example.org/
151151
end
152152
end
153153
end

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ module Decorators
77
describe WebhooksDecorator do
88

99
let(:webhook) do
10-
instance_double(Domain::Webhook, uuid: 'some-uuid', description: 'description', request_description: 'request description')
10+
instance_double(Domain::Webhook,
11+
uuid: 'some-uuid',
12+
display_description: 'description'
13+
)
1114
end
1215
let(:base_url) { 'http://example.org' }
1316
let(:resource_url) { 'http://example.org/webhooks' }
@@ -31,15 +34,13 @@ module Decorators
3134

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

3740
it "includes curies" do
3841
expect(subject[:_links][:curies]).to eq [{:name=>"pb", :href=>"http://example.org/doc/webhooks-{rel}", templated: true}]
3942
end
40-
4143
end
42-
4344
end
4445
end
4546
end

0 commit comments

Comments
 (0)