Skip to content

Commit

Permalink
feat(pact): add relation to view matrix rows for the consumer version
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 20, 2020
1 parent fac01e9 commit 13cb20b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/pact_broker/api/decorators/pact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ def to_hash(options = {})
}
end

link :'pb:matrix-for-consumer-version' do | options |
{
title: "View matrix rows for the consumer version to which this pact belongs",
href: matrix_for_pacticipant_version_url(represented.consumer_version, options.fetch(:base_url))
}
end

curies do | options |
[{
name: :pb,
Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ def matrix_url consumer_name, provider_name, base_url = ''
"/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
end

def matrix_for_pacticipant_version_url(version, base_url = '')
query = {
q: [{ pacticipant: version.pacticipant.name, version: version.number }],
latestby: 'cvpv'
}
"#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}"
end

def matrix_url_from_params params, base_url = ''
matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/renderers/html_pact_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def pact_url
end

def matrix_url
PactBroker::Api::PactBrokerUrls.matrix_url_from_params({ consumer_name: @pact.consumer.name, provider_name: @pact.provider.name }, base_url)
PactBroker::Api::PactBrokerUrls.matrix_for_pacticipant_version_url(@pact.consumer_version, base_url)
end

def latest_pact_url
Expand Down
1 change: 1 addition & 0 deletions lib/pact_broker/doc/views/pact/all-pact-versions.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# All versions of a pact between a given consumer and provider

Allowed methods: `GET`, `DELETE`

Path: `/pacts/provider/{provider}/consumer/{consumer}/versions`

This resource returns a history of all the versions of the given pact between a consumer and provider.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Latest pact version

Allowed methods: GET
Allowed methods: `GET`

The latest pact between this consumer and provider.

Expand Down
11 changes: 11 additions & 0 deletions spec/lib/pact_broker/api/pact_broker_urls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module Api
pact_version_sha: "1234",
number: "1")
end
let(:version) do
double('version',
pacticipant: consumer,
number: "2")
end

matcher :match_route_in_api do |api|
match do |url|
Expand Down Expand Up @@ -127,6 +132,12 @@ module Api
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/verification-results/latest" }
end
end

describe "matrix_for_pacticipant_version_url" do
subject { PactBrokerUrls.matrix_for_pacticipant_version_url(version, base_url) }

it { is_expected.to eq "http://example.org/matrix?q[][pacticipant]=Foo%2FFoo&q[][version]=2&latestby=cvpv" }
end
end
end
end
20 changes: 18 additions & 2 deletions spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Renderers
ENV['TZ'] = "Australia/Melbourne"
PactBroker.configuration.enable_public_badge_access = true
allow(PactBroker::Api::PactBrokerUrls).to receive(:pact_url).with('http://base', pact).and_return(pact_url)
allow(PactBroker::Api::PactBrokerUrls).to receive(:matrix_for_pacticipant_version_url).with(consumer_version, 'http://base').and_return(matrix_url)
allow_any_instance_of(HtmlPactRenderer).to receive(:logger).and_return(logger)

Timecop.freeze(created_at + 3)
Expand All @@ -24,10 +25,22 @@ module Renderers

let(:consumer) { double('consumer', name: 'Consumer')}
let(:provider) { double('provider', name: 'Provider')}
let(:consumer_version) { double('consumer version') }
let(:created_at) { DateTime.new(2014, 02, 27) }
let(:json_content) { load_fixture('renderer_pact.json') }
let(:pact) { double('pact', json_content: json_content, consumer_version_number: '1.2.3', consumer: consumer, provider: provider, consumer_version_tag_names: ['prod', 'master'], created_at: created_at)}
let(:pact) do
double('pact',
json_content: json_content,
consumer_version_number: '1.2.3',
consumer: consumer,
provider: provider,
consumer_version_tag_names: ['prod', 'master'],
created_at: created_at,
consumer_version: consumer_version
)
end
let(:pact_url) { '/pact/url' }
let(:matrix_url) { '/matrix/url' }
let(:options) do
{
base_url: 'http://base',
Expand Down Expand Up @@ -64,6 +77,10 @@ module Renderers
expect(subject).to include "[![Consumer/Provider Pact Status](http://badge)](http://base)"
end

it "includes the matrix URL" do
expect(subject).to include matrix_url
end

context "when enable_public_badge_access is false" do
before do
PactBroker.configuration.enable_public_badge_access = false
Expand Down Expand Up @@ -99,7 +116,6 @@ module Renderers
end
end
end

end
end
end
Expand Down

0 comments on commit 13cb20b

Please sign in to comment.