diff --git a/lib/pact_broker/api/decorators/webhook_decorator.rb b/lib/pact_broker/api/decorators/webhook_decorator.rb index d4cb67812..dd520189d 100644 --- a/lib/pact_broker/api/decorators/webhook_decorator.rb +++ b/lib/pact_broker/api/decorators/webhook_decorator.rb @@ -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 @@ -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]) } @@ -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 diff --git a/lib/pact_broker/api/decorators/webhooks_decorator.rb b/lib/pact_broker/api/decorators/webhooks_decorator.rb index 3b5cb2ae0..8ea181c07 100644 --- a/lib/pact_broker/api/decorators/webhooks_decorator.rb +++ b/lib/pact_broker/api/decorators/webhooks_decorator.rb @@ -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 diff --git a/lib/pact_broker/domain/webhook.rb b/lib/pact_broker/domain/webhook.rb index 1653310fc..5ca53082e 100644 --- a/lib/pact_broker/domain/webhook.rb +++ b/lib/pact_broker/domain/webhook.rb @@ -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}" 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 8b2c533a0..1ae45a590 100644 --- a/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb @@ -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 diff --git a/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb index 927d29a16..37a19f71a 100644 --- a/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb @@ -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' } @@ -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