Skip to content

Commit 344d3e1

Browse files
committed
feat: add matrix URL to /integration _links
1 parent a240852 commit 344d3e1

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/pact_broker/api/decorators/integration_decorator.rb

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class IntegrationDecorator < BaseDecorator
2121
href: dashboard_url_for_integration(represented.consumer.name, represented.provider.name, options.fetch(:base_url))
2222
}
2323
end
24+
25+
link "pb:matrix" do | options |
26+
{
27+
title: "Matrix of pacts/verification results for #{represented.consumer.name} and #{represented.provider.name}",
28+
href: matrix_url(represented.consumer.name, represented.provider.name, options.fetch(:base_url))
29+
}
30+
end
2431
end
2532
end
2633
end

lib/pact_broker/api/pact_broker_urls.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,12 @@ def badge_url_for_latest_pact pact, base_url = ''
204204
"#{latest_pact_url(base_url, pact)}/badge.svg"
205205
end
206206

207+
def matrix_url consumer_name, provider_name, base_url = ''
208+
"/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
209+
end
210+
207211
def matrix_url_from_params params, base_url = ''
208-
"#{base_url}/matrix/provider/#{url_encode(params.fetch(:provider_name))}/consumer/#{url_encode(params.fetch(:consumer_name))}"
212+
matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url)
209213
end
210214

211215
def hal_browser_url target_url

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

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Decorators
77
describe IntegrationDecorator do
88
before do
99
allow(integration_decorator).to receive(:dashboard_url_for_integration).and_return("/dashboard")
10+
allow(integration_decorator).to receive(:matrix_url).and_return("/matrix")
1011
end
1112

1213
let(:integration) do
@@ -29,6 +30,10 @@ module Decorators
2930
"_links" => {
3031
"pb:dashboard" => {
3132
"href" => "/dashboard"
33+
},
34+
"pb:matrix" => {
35+
"title" => "Matrix of pacts/verification results for the consumer and the provider",
36+
"href" => "/matrix"
3237
}
3338
}
3439
}
@@ -50,6 +55,15 @@ module Decorators
5055
)
5156
subject
5257
end
58+
59+
it "generates the correct link for the matrix" do
60+
expect(integration_decorator).to receive(:matrix_url).with(
61+
"the consumer",
62+
"the provider",
63+
"http://example.org"
64+
)
65+
subject
66+
end
5367
end
5468
end
5569
end

0 commit comments

Comments
 (0)