diff --git a/lib/pact_broker/api/decorators/matrix_decorator.rb b/lib/pact_broker/api/decorators/matrix_decorator.rb index 94b0f8aad..d53182d88 100644 --- a/lib/pact_broker/api/decorators/matrix_decorator.rb +++ b/lib/pact_broker/api/decorators/matrix_decorator.rb @@ -17,6 +17,9 @@ def to_json(options) def to_hash(options) { + summary: { + compatible: compatible? + }, matrix: matrix(lines, options[:user_options][:base_url]) } end @@ -25,6 +28,10 @@ def to_hash(options) attr_reader :lines + def compatible? + lines.any? && lines.all?{ |line| line[:success] } + end + def matrix(lines, base_url) provider = nil consumer = nil diff --git a/lib/pact_broker/api/resources/matrix.rb b/lib/pact_broker/api/resources/matrix.rb index 1f1956c0c..ca0c48c49 100644 --- a/lib/pact_broker/api/resources/matrix.rb +++ b/lib/pact_broker/api/resources/matrix.rb @@ -27,7 +27,7 @@ def malformed_request? def to_json criteria = selected_versions.each_with_object({}) { | version, hash | hash[version.pacticipant.name] = version.number } - lines = matrix_service.find_compatible_pacticipant_versions(criteria) + lines = matrix_service.find(criteria) PactBroker::Api::Decorators::MatrixPactDecorator.new(lines).to_json(user_options: { base_url: base_url }) end diff --git a/lib/pact_broker/matrix/service.rb b/lib/pact_broker/matrix/service.rb index f8a15597c..f95dab487 100644 --- a/lib/pact_broker/matrix/service.rb +++ b/lib/pact_broker/matrix/service.rb @@ -9,6 +9,10 @@ module Service extend PactBroker::Repositories extend PactBroker::Services + def find criteria + matrix_repository.find criteria + end + def find_for_consumer_and_provider params matrix_repository.find_for_consumer_and_provider params[:consumer_name], params[:provider_name] end @@ -43,6 +47,10 @@ def validate_selectors selectors end end + if selectors.size < 2 + error_messages << "Please provide 2 or more version selectors." + end + error_messages end end diff --git a/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb index 24e9d8621..9a8d9f1f3 100644 --- a/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb @@ -113,6 +113,10 @@ module Decorators expect(parsed_json[:matrix][0][:pact]).to eq pact_hash end + it "includes a summary" do + expect(parsed_json[:summary][:compatible]).to eq false + end + context "when the pact has not been verified" do let(:verification_hash) do nil diff --git a/spec/lib/pact_broker/matrix/service_spec.rb b/spec/lib/pact_broker/matrix/service_spec.rb index 3d9c0e4bf..23bfa220e 100644 --- a/spec/lib/pact_broker/matrix/service_spec.rb +++ b/spec/lib/pact_broker/matrix/service_spec.rb @@ -3,8 +3,9 @@ module PactBroker module Matrix describe Service do + let(:td) { TestDataBuilder.new } + describe "validate_selectors" do - let(:td) { TestDataBuilder.new } subject { Service.validate_selectors(selectors) } @@ -16,6 +17,19 @@ module Matrix end end + context "when there is only one selector" do + before do + td.create_pacticipant("Foo") + .create_version("1") + end + + let(:selectors) { ["Foo/version/1"] } + + it "returns error messages" do + expect(subject.first).to eq "Please provide 2 or more version selectors." + end + end + context "when one or more of the selectors does not match any known version" do before do td.create_pacticipant("Foo")