From 344d3e18bebef00c01a7631d94d0efa21a8fb365 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 14 May 2019 10:07:44 +1000 Subject: [PATCH] feat: add matrix URL to /integration _links --- .../api/decorators/integration_decorator.rb | 7 +++++++ lib/pact_broker/api/pact_broker_urls.rb | 6 +++++- .../api/decorators/integration_decorator_spec.rb | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) 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