Skip to content

Commit 13cb20b

Browse files
committed
feat(pact): add relation to view matrix rows for the consumer version
1 parent fac01e9 commit 13cb20b

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

lib/pact_broker/api/decorators/pact_decorator.rb

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def to_hash(options = {})
159159
}
160160
end
161161

162+
link :'pb:matrix-for-consumer-version' do | options |
163+
{
164+
title: "View matrix rows for the consumer version to which this pact belongs",
165+
href: matrix_for_pacticipant_version_url(represented.consumer_version, options.fetch(:base_url))
166+
}
167+
end
168+
162169
curies do | options |
163170
[{
164171
name: :pb,

lib/pact_broker/api/pact_broker_urls.rb

+8
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ def matrix_url consumer_name, provider_name, base_url = ''
250250
"/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
251251
end
252252

253+
def matrix_for_pacticipant_version_url(version, base_url = '')
254+
query = {
255+
q: [{ pacticipant: version.pacticipant.name, version: version.number }],
256+
latestby: 'cvpv'
257+
}
258+
"#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}"
259+
end
260+
253261
def matrix_url_from_params params, base_url = ''
254262
matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url)
255263
end

lib/pact_broker/api/renderers/html_pact_renderer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def pact_url
137137
end
138138

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

143143
def latest_pact_url

lib/pact_broker/doc/views/pact/all-pact-versions.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# All versions of a pact between a given consumer and provider
22

33
Allowed methods: `GET`, `DELETE`
4+
45
Path: `/pacts/provider/{provider}/consumer/{consumer}/versions`
56

67
This resource returns a history of all the versions of the given pact between a consumer and provider.

lib/pact_broker/doc/views/pact/latest-pact-version.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Latest pact version
22

3-
Allowed methods: GET
3+
Allowed methods: `GET`
44

55
The latest pact between this consumer and provider.
66

spec/lib/pact_broker/api/pact_broker_urls_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ module Api
2727
pact_version_sha: "1234",
2828
number: "1")
2929
end
30+
let(:version) do
31+
double('version',
32+
pacticipant: consumer,
33+
number: "2")
34+
end
3035

3136
matcher :match_route_in_api do |api|
3237
match do |url|
@@ -127,6 +132,12 @@ module Api
127132
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/verification-results/latest" }
128133
end
129134
end
135+
136+
describe "matrix_for_pacticipant_version_url" do
137+
subject { PactBrokerUrls.matrix_for_pacticipant_version_url(version, base_url) }
138+
139+
it { is_expected.to eq "http://example.org/matrix?q[][pacticipant]=Foo%2FFoo&q[][version]=2&latestby=cvpv" }
140+
end
130141
end
131142
end
132143
end

spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Renderers
1212
ENV['TZ'] = "Australia/Melbourne"
1313
PactBroker.configuration.enable_public_badge_access = true
1414
allow(PactBroker::Api::PactBrokerUrls).to receive(:pact_url).with('http://base', pact).and_return(pact_url)
15+
allow(PactBroker::Api::PactBrokerUrls).to receive(:matrix_for_pacticipant_version_url).with(consumer_version, 'http://base').and_return(matrix_url)
1516
allow_any_instance_of(HtmlPactRenderer).to receive(:logger).and_return(logger)
1617

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

2526
let(:consumer) { double('consumer', name: 'Consumer')}
2627
let(:provider) { double('provider', name: 'Provider')}
28+
let(:consumer_version) { double('consumer version') }
2729
let(:created_at) { DateTime.new(2014, 02, 27) }
2830
let(:json_content) { load_fixture('renderer_pact.json') }
29-
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)}
31+
let(:pact) do
32+
double('pact',
33+
json_content: json_content,
34+
consumer_version_number: '1.2.3',
35+
consumer: consumer,
36+
provider: provider,
37+
consumer_version_tag_names: ['prod', 'master'],
38+
created_at: created_at,
39+
consumer_version: consumer_version
40+
)
41+
end
3042
let(:pact_url) { '/pact/url' }
43+
let(:matrix_url) { '/matrix/url' }
3144
let(:options) do
3245
{
3346
base_url: 'http://base',
@@ -64,6 +77,10 @@ module Renderers
6477
expect(subject).to include "[![Consumer/Provider Pact Status](http://badge)](http://base)"
6578
end
6679

80+
it "includes the matrix URL" do
81+
expect(subject).to include matrix_url
82+
end
83+
6784
context "when enable_public_badge_access is false" do
6885
before do
6986
PactBroker.configuration.enable_public_badge_access = false
@@ -99,7 +116,6 @@ module Renderers
99116
end
100117
end
101118
end
102-
103119
end
104120
end
105121
end

0 commit comments

Comments
 (0)