Skip to content

Commit

Permalink
feat(matrix): allow matrix rows to be returned for all versions of a …
Browse files Browse the repository at this point in the history
…pacticipant
  • Loading branch information
bethesque committed Oct 29, 2017
1 parent a92f459 commit 6d37545
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/pact_broker/matrix/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def validate_selectors selectors
error_messages << "Please specify the pacticipant name and version"
elsif selector[:pacticipant_name].nil?
error_messages << "Please specify the pacticipant name"
elsif selector[:pacticipant_version_number].nil?
error_messages << "Please specify the version for #{selector[:pacticipant_name]}"
end
end

Expand All @@ -41,8 +39,10 @@ def validate_selectors selectors

if error_messages.empty?
selectors.each do | selector |
version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: selector[:pacticipant_name], pacticipant_version_number: selector[:pacticipant_version_number])
error_messages << "No pact or verification found for #{selector[:pacticipant_name]} version #{selector[:pacticipant_version_number]}" if version.nil?
if selector[:pacticipant_version_number]
version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: selector[:pacticipant_name], pacticipant_version_number: selector[:pacticipant_version_number])
error_messages << "No pact or verification found for #{selector[:pacticipant_name]} version #{selector[:pacticipant_version_number]}" if version.nil?
end
end
end

Expand Down
14 changes: 10 additions & 4 deletions spec/lib/pact_broker/matrix/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module Matrix
.create_version("1")
.create_pacticipant("Bar")
.create_version("2")

end

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

context "when the pacticipant version is not specified" do
let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: nil }] }
before do
td.create_pacticipant("Foo")
.create_version("1")
.create_pacticipant("Bar")
.create_version("2")
end

it "returns error messages" do
expect(subject.first).to eq "Please specify the version for Foo"
let(:selectors) { [ { pacticipant_name: "Foo", pacticipant_version_number: nil }, { pacticipant_name: "Bar", pacticipant_version_number: nil } ] }

it "returns no error messages" do
expect(subject).to eq []
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/service_consumers/provider_states_for_pact_broker_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@
end
end

provider_state "the pact for Foo version 1.2.3 and 1.2.4 has been verified by Bar version 4.5.6" do
set_up do
TestDataBuilder.new
.create_pact_with_hierarchy("Foo", "1.2.3", "Bar")
.create_verification(provider_version: "4.5.6")
.create_consumer_version("1.2.4")
.create_pact
.create_verification(provider_version: "4.5.6")
end
end

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
set_up do
TestDataBuilder.new
.create_pact_with_hierarchy("Foo", "1.2.3", "Bar")
.create_verification(provider_version: "4.5.6")
.create_consumer_version("1.2.4")
.create_pact
.create_verification(provider_version: "9.9.9", success: false)
end
end

provider_state "the 'Pricing Service' does not exist in the pact-broker" do
no_op
end
Expand Down

0 comments on commit 6d37545

Please sign in to comment.