Skip to content

Commit

Permalink
feat(matrix): return failure and success lines in matrix response, an…
Browse files Browse the repository at this point in the history
…d a summary indicating whether the specified versions are compatible or not
  • Loading branch information
bethesque committed Oct 16, 2017
1 parent 52755fd commit 8783ef8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/pact_broker/api/decorators/matrix_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def to_json(options)

def to_hash(options)
{
summary: {
compatible: compatible?
},
matrix: matrix(lines, options[:user_options][:base_url])
}
end
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/matrix/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion spec/lib/pact_broker/matrix/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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")
Expand Down

0 comments on commit 8783ef8

Please sign in to comment.