diff --git a/lib/pact_broker/matrix/service.rb b/lib/pact_broker/matrix/service.rb index 2fc95e579..425208af2 100644 --- a/lib/pact_broker/matrix/service.rb +++ b/lib/pact_broker/matrix/service.rb @@ -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 @@ -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 diff --git a/spec/lib/pact_broker/matrix/service_spec.rb b/spec/lib/pact_broker/matrix/service_spec.rb index 88d4f5f1d..ae1026ca7 100644 --- a/spec/lib/pact_broker/matrix/service_spec.rb +++ b/spec/lib/pact_broker/matrix/service_spec.rb @@ -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" }] } @@ -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 diff --git a/spec/service_consumers/provider_states_for_pact_broker_client.rb b/spec/service_consumers/provider_states_for_pact_broker_client.rb index b09fd0a58..89cef1874 100644 --- a/spec/service_consumers/provider_states_for_pact_broker_client.rb +++ b/spec/service_consumers/provider_states_for_pact_broker_client.rb @@ -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