Skip to content

Commit 8783ef8

Browse files
committed
feat(matrix): return failure and success lines in matrix response, and a summary indicating whether the specified versions are compatible or not
1 parent 52755fd commit 8783ef8

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

lib/pact_broker/api/decorators/matrix_decorator.rb

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def to_json(options)
1717

1818
def to_hash(options)
1919
{
20+
summary: {
21+
compatible: compatible?
22+
},
2023
matrix: matrix(lines, options[:user_options][:base_url])
2124
}
2225
end
@@ -25,6 +28,10 @@ def to_hash(options)
2528

2629
attr_reader :lines
2730

31+
def compatible?
32+
lines.any? && lines.all?{ |line| line[:success] }
33+
end
34+
2835
def matrix(lines, base_url)
2936
provider = nil
3037
consumer = nil

lib/pact_broker/api/resources/matrix.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def malformed_request?
2727

2828
def to_json
2929
criteria = selected_versions.each_with_object({}) { | version, hash | hash[version.pacticipant.name] = version.number }
30-
lines = matrix_service.find_compatible_pacticipant_versions(criteria)
30+
lines = matrix_service.find(criteria)
3131
PactBroker::Api::Decorators::MatrixPactDecorator.new(lines).to_json(user_options: { base_url: base_url })
3232
end
3333

lib/pact_broker/matrix/service.rb

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module Service
99
extend PactBroker::Repositories
1010
extend PactBroker::Services
1111

12+
def find criteria
13+
matrix_repository.find criteria
14+
end
15+
1216
def find_for_consumer_and_provider params
1317
matrix_repository.find_for_consumer_and_provider params[:consumer_name], params[:provider_name]
1418
end
@@ -43,6 +47,10 @@ def validate_selectors selectors
4347
end
4448
end
4549

50+
if selectors.size < 2
51+
error_messages << "Please provide 2 or more version selectors."
52+
end
53+
4654
error_messages
4755
end
4856
end

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

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ module Decorators
113113
expect(parsed_json[:matrix][0][:pact]).to eq pact_hash
114114
end
115115

116+
it "includes a summary" do
117+
expect(parsed_json[:summary][:compatible]).to eq false
118+
end
119+
116120
context "when the pact has not been verified" do
117121
let(:verification_hash) do
118122
nil

spec/lib/pact_broker/matrix/service_spec.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
module PactBroker
44
module Matrix
55
describe Service do
6+
let(:td) { TestDataBuilder.new }
7+
68
describe "validate_selectors" do
7-
let(:td) { TestDataBuilder.new }
89

910
subject { Service.validate_selectors(selectors) }
1011

@@ -16,6 +17,19 @@ module Matrix
1617
end
1718
end
1819

20+
context "when there is only one selector" do
21+
before do
22+
td.create_pacticipant("Foo")
23+
.create_version("1")
24+
end
25+
26+
let(:selectors) { ["Foo/version/1"] }
27+
28+
it "returns error messages" do
29+
expect(subject.first).to eq "Please provide 2 or more version selectors."
30+
end
31+
end
32+
1933
context "when one or more of the selectors does not match any known version" do
2034
before do
2135
td.create_pacticipant("Foo")

0 commit comments

Comments
 (0)