Skip to content

Commit 0fa33f1

Browse files
committed
feat(matrix): update validation of selectors to allow tag and latest flag to be specified
1 parent abcab9e commit 0fa33f1

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

lib/pact_broker/matrix/service.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ def validate_selectors selectors
2929
elsif s[:pacticipant_name].nil?
3030
error_messages << "Please specify the pacticipant name"
3131
else
32-
if s.key?(:pacticipant_version_number) && s.key?(:latest_tag)
33-
error_messages << "A version and a latest tag cannot both be specified for #{s[:pacticipant_name]}"
32+
if s.key?(:pacticipant_version_number) && s.key?(:latest)
33+
error_messages << "A version and latest flag cannot both be specified for #{s[:pacticipant_name]}"
34+
end
35+
36+
if s.key?(:tag) && !s.key?(:latest)
37+
error_messages << "Querying for all versions with a tag is not currently supported. The latest=true flag must be specified when a tag is given."
3438
end
3539
end
3640
end
@@ -46,9 +50,9 @@ def validate_selectors selectors
4650
if s[:pacticipant_version_number]
4751
version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: s[:pacticipant_name], pacticipant_version_number: s[:pacticipant_version_number])
4852
error_messages << "No pact or verification found for #{s[:pacticipant_name]} version #{s[:pacticipant_version_number]}" if version.nil?
49-
elsif s[:latest_tag]
50-
version = version_service.find_by_pacticpant_name_and_latest_tag(s[:pacticipant_name], s[:latest_tag])
51-
error_messages << "No version of #{s[:pacticipant_name]} found with tag #{s[:latest_tag]}" if version.nil?
53+
elsif s[:tag]
54+
version = version_service.find_by_pacticpant_name_and_latest_tag(s[:pacticipant_name], s[:tag])
55+
error_messages << "No version of #{s[:pacticipant_name]} found with tag #{s[:tag]}" if version.nil?
5256
end
5357
end
5458
end

spec/lib/pact_broker/matrix/service_spec.rb

+20-4
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ module Matrix
9090

9191
context "when there is not a version for the tag" do
9292

93-
let(:selectors) { [{ pacticipant_name: "Foo", latest_tag: "wiffle" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
93+
let(:selectors) { [{ pacticipant_name: "Foo", latest: true, tag: "wiffle" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
9494

9595
it "returns an error message" do
9696
expect(subject).to eq ["No version of Foo found with tag wiffle"]
9797
end
9898
end
9999
end
100100

101-
context "when the latest_tag is used as well as a version" do
101+
context "when the latest is used as well as a version" do
102102
before do
103103
td.create_pacticipant("Foo")
104104
.create_version("1")
@@ -107,10 +107,26 @@ module Matrix
107107
.create_version("2")
108108
end
109109

110-
let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1", latest_tag: "prod" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
110+
let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1", latest: true }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
111111

112112
it "returns an error message" do
113-
expect(subject).to eq ["A version and a latest tag cannot both be specified for Foo"]
113+
expect(subject).to eq ["A version and latest flag cannot both be specified for Foo"]
114+
end
115+
end
116+
117+
context "when a tag is specified without latest=true" do
118+
before do
119+
td.create_pacticipant("Foo")
120+
.create_version("1")
121+
.create_tag("prod")
122+
.create_pacticipant("Bar")
123+
.create_version("2")
124+
end
125+
126+
let(:selectors) { [{ pacticipant_name: "Foo", tag: "1"}] }
127+
128+
it "returns an error message" do
129+
expect(subject).to eq ["Querying for all versions with a tag is not currently supported. The latest=true flag must be specified when a tag is given."]
114130
end
115131
end
116132
end

0 commit comments

Comments
 (0)