diff --git a/lib/pact_broker/api/decorators/integration_decorator.rb b/lib/pact_broker/api/decorators/integration_decorator.rb index 0a6f18247..446c9884c 100644 --- a/lib/pact_broker/api/decorators/integration_decorator.rb +++ b/lib/pact_broker/api/decorators/integration_decorator.rb @@ -21,6 +21,13 @@ class IntegrationDecorator < BaseDecorator href: dashboard_url_for_integration(represented.consumer.name, represented.provider.name, options.fetch(:base_url)) } end + + link "pb:matrix" do | options | + { + title: "Matrix of pacts/verification results for #{represented.consumer.name} and #{represented.provider.name}", + href: matrix_url(represented.consumer.name, represented.provider.name, options.fetch(:base_url)) + } + end end end end diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 9de20b5c3..cbdfc9014 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -204,8 +204,12 @@ def badge_url_for_latest_pact pact, base_url = '' "#{latest_pact_url(base_url, pact)}/badge.svg" end + def matrix_url consumer_name, provider_name, base_url = '' + "/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}" + end + def matrix_url_from_params params, base_url = '' - "#{base_url}/matrix/provider/#{url_encode(params.fetch(:provider_name))}/consumer/#{url_encode(params.fetch(:consumer_name))}" + matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url) end def hal_browser_url target_url diff --git a/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb index 4a10d4018..6564b42c0 100644 --- a/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb @@ -7,6 +7,7 @@ module Decorators describe IntegrationDecorator do before do allow(integration_decorator).to receive(:dashboard_url_for_integration).and_return("/dashboard") + allow(integration_decorator).to receive(:matrix_url).and_return("/matrix") end let(:integration) do @@ -29,6 +30,10 @@ module Decorators "_links" => { "pb:dashboard" => { "href" => "/dashboard" + }, + "pb:matrix" => { + "title" => "Matrix of pacts/verification results for the consumer and the provider", + "href" => "/matrix" } } } @@ -50,6 +55,15 @@ module Decorators ) subject end + + it "generates the correct link for the matrix" do + expect(integration_decorator).to receive(:matrix_url).with( + "the consumer", + "the provider", + "http://example.org" + ) + subject + end end end end