Skip to content

Commit 52755fd

Browse files
committed
feat(matrix): add method to find all matrix lines for a list of versions, regardless of verification status
1 parent f68ca21 commit 52755fd

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

lib/pact_broker/matrix/repository.rb

+19-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ class Repository
66
include PactBroker::Repositories::Helpers
77
include PactBroker::Repositories
88

9+
def find criteria
10+
version_ids = criteria.reject{ |key, value| !value }.collect do | key, value |
11+
version_repository.find_by_pacticipant_name_and_number(key, value).id
12+
end
13+
14+
pacticipant_names = criteria.reject{|key, value| value }.keys
15+
16+
# If there is a nil provider_version_number it is because there is no verification
17+
# but the row has been included because it is a left outer join.
18+
# All the unverified pacts will be grouped together in the group_by because of this,
19+
# so we include all of that group.
20+
find_for_version_ids(version_ids, pacticipant_names)
21+
.group_by{|line| [line[:consumer_version_number], line[:provider_version_number]]}
22+
.values
23+
.collect{ | lines | lines.first[:provider_version_number].nil? ? lines : lines.last }
24+
.flatten
25+
end
26+
927
def find_for_consumer_and_provider pacticipant_1_name, pacticipant_2_name
1028
find_for_version_ids([], [pacticipant_1_name, pacticipant_2_name])
1129
.sort{|l1, l2| l2[:consumer_version_order] <=> l1[:consumer_version_order]}
@@ -17,17 +35,7 @@ def find_for_consumer_and_provider pacticipant_1_name, pacticipant_2_name
1735
# Returns a list of matrix lines indicating the compatible versions
1836
#
1937
def find_compatible_pacticipant_versions criteria
20-
version_ids = criteria.reject{ |key, value| !value }.collect do | key, value |
21-
version_repository.find_by_pacticipant_name_and_number(key, value).id
22-
end
23-
24-
pacticipant_names = criteria.reject{|key, value| value }.keys
25-
26-
find_for_version_ids(version_ids, pacticipant_names)
27-
.group_by{|line| [line[:consumer_version_number], line[:provider_version_number]]}
28-
.values
29-
.collect(&:last)
30-
.select{ |line | line[:success] }
38+
find(criteria).select{ |line | line[:success] }
3139
end
3240

3341
def find_for_version_ids version_ids, pacticipant_names = []

spec/lib/pact_broker/matrix/repository_spec.rb

+33
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@
33
module PactBroker
44
module Matrix
55
describe Repository do
6+
let(:td) { TestDataBuilder.new}
7+
8+
describe "find" do
9+
context "when the provider version resource exists but there is no verification for that version" do
10+
before do
11+
td.create_pact_with_hierarchy("A", "1.2.3", "B")
12+
.use_provider("B")
13+
.create_version("2.0.0")
14+
.create_provider("C")
15+
.create_version("3.0.0")
16+
.create_pact
17+
end
18+
19+
subject { Repository.new.find "A" => "1.2.3", "B" => "2.0.0", "C" => "3.0.0" }
20+
21+
it "returns a row for each pact" do
22+
expect(subject.size).to eq 2
23+
end
24+
25+
it "returns an row with a blank provider_version_number" do
26+
expect(subject.first).to include consumer_name: "A",
27+
provider_name: "B",
28+
consumer_version_number: "1.2.3",
29+
provider_version_number: nil
30+
31+
expect(subject.last).to include consumer_name: "A",
32+
provider_name: "C",
33+
consumer_version_number: "1.2.3",
34+
provider_version_number: nil
35+
end
36+
end
37+
end
38+
639
describe "#find_for_consumer_and_provider" do
740
before do
841
TestDataBuilder.new

0 commit comments

Comments
 (0)