Skip to content

Commit 6d37545

Browse files
committed
feat(matrix): allow matrix rows to be returned for all versions of a pacticipant
1 parent a92f459 commit 6d37545

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

lib/pact_broker/matrix/service.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ def validate_selectors selectors
2828
error_messages << "Please specify the pacticipant name and version"
2929
elsif selector[:pacticipant_name].nil?
3030
error_messages << "Please specify the pacticipant name"
31-
elsif selector[:pacticipant_version_number].nil?
32-
error_messages << "Please specify the version for #{selector[:pacticipant_name]}"
3331
end
3432
end
3533

@@ -41,8 +39,10 @@ def validate_selectors selectors
4139

4240
if error_messages.empty?
4341
selectors.each do | selector |
44-
version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: selector[:pacticipant_name], pacticipant_version_number: selector[:pacticipant_version_number])
45-
error_messages << "No pact or verification found for #{selector[:pacticipant_name]} version #{selector[:pacticipant_version_number]}" if version.nil?
42+
if selector[:pacticipant_version_number]
43+
version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: selector[:pacticipant_name], pacticipant_version_number: selector[:pacticipant_version_number])
44+
error_messages << "No pact or verification found for #{selector[:pacticipant_name]} version #{selector[:pacticipant_version_number]}" if version.nil?
45+
end
4646
end
4747
end
4848

spec/lib/pact_broker/matrix/service_spec.rb

+10-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module Matrix
2929
.create_version("1")
3030
.create_pacticipant("Bar")
3131
.create_version("2")
32-
3332
end
3433

3534
let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1" }, { pacticipant_name: "Bar", pacticipant_version_number: "1" }] }
@@ -56,10 +55,17 @@ module Matrix
5655
end
5756

5857
context "when the pacticipant version is not specified" do
59-
let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: nil }] }
58+
before do
59+
td.create_pacticipant("Foo")
60+
.create_version("1")
61+
.create_pacticipant("Bar")
62+
.create_version("2")
63+
end
6064

61-
it "returns error messages" do
62-
expect(subject.first).to eq "Please specify the version for Foo"
65+
let(:selectors) { [ { pacticipant_name: "Foo", pacticipant_version_number: nil }, { pacticipant_name: "Bar", pacticipant_version_number: nil } ] }
66+
67+
it "returns no error messages" do
68+
expect(subject).to eq []
6369
end
6470
end
6571

spec/service_consumers/provider_states_for_pact_broker_client.rb

+22
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626
end
2727
end
2828

29+
provider_state "the pact for Foo version 1.2.3 and 1.2.4 has been verified by Bar version 4.5.6" do
30+
set_up do
31+
TestDataBuilder.new
32+
.create_pact_with_hierarchy("Foo", "1.2.3", "Bar")
33+
.create_verification(provider_version: "4.5.6")
34+
.create_consumer_version("1.2.4")
35+
.create_pact
36+
.create_verification(provider_version: "4.5.6")
37+
end
38+
end
39+
40+
provider_state "the pact for Foo version 1.2.3 has been successfully verified by Bar version 4.5.6, and 1.2.4 unsuccessfully by 9.9.9" do
41+
set_up do
42+
TestDataBuilder.new
43+
.create_pact_with_hierarchy("Foo", "1.2.3", "Bar")
44+
.create_verification(provider_version: "4.5.6")
45+
.create_consumer_version("1.2.4")
46+
.create_pact
47+
.create_verification(provider_version: "9.9.9", success: false)
48+
end
49+
end
50+
2951
provider_state "the 'Pricing Service' does not exist in the pact-broker" do
3052
no_op
3153
end

0 commit comments

Comments
 (0)