Skip to content

Commit

Permalink
feat: add matrix URL to /integration _links
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 14, 2019
1 parent a240852 commit 344d3e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/pact_broker/api/decorators/integration_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
}
}
Expand All @@ -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
Expand Down

0 comments on commit 344d3e1

Please sign in to comment.