Skip to content

Commit

Permalink
feat(what-can-i-deploy): add success param to matrix query
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 29, 2017
1 parent 739fead commit 40adb2e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/pact_broker/client/can_i_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'pact_broker/client/retry'
require 'pact_broker/client/matrix/formatter'


module PactBroker
module Client
class CanIDeploy
Expand Down
22 changes: 18 additions & 4 deletions lib/pact_broker/client/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
module PactBroker
module Client
class Matrix < BaseClient
def get selectors
query = convert_selector_hashes_to_params(selectors)
response = self.class.get("/matrix", query: {q: query}, headers: default_get_headers)
def get selectors, options = {}
query = {
q: convert_selector_hashes_to_params(selectors)
}.merge(query_options(options))
response = self.class.get("/matrix", query: query, headers: default_get_headers)
$stdout.puts("DEBUG: Response headers #{response.headers}") if verbose?
$stdout.puts("DEBUG: Response body #{response}") if verbose?
response = handle_response(response) do
Expand All @@ -31,8 +33,20 @@ def handle_response response
end
end

def query_options(options)
opts = {}
if options.key?(:success)
opts[:success] = [*options[:success]]
end
opts
end

def convert_selector_hashes_to_params(selectors)
selectors.collect{ |selector| {pacticipant: selector[:pacticipant], version: selector[:version]} }
selectors.collect do |selector|
{ pacticipant: selector[:pacticipant] }.tap do | hash |
hash[:version] = selector[:version] if selector[:version]
end
end
end
end
end
Expand Down
61 changes: 57 additions & 4 deletions spec/service_providers/pact_broker_client_matrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module PactBroker::Client
)
end

it 'a matrix of compatible versions' do
it 'returns the pact matrix' do
matrix = pact_broker_client.matrix.get(selectors)
expect(matrix[:matrix].size).to eq 1
end
Expand All @@ -53,7 +53,7 @@ module PactBroker::Client

let(:selectors) { [{ pacticipant: "Foo Thing", version: "1.2.3" }, { pacticipant: "Bar", version: "4.5.6" }] }

it 'a matrix of compatible versions' do
it 'incorrectly escapes the spaces but it still seems to work' do
matrix = pact_broker_client.matrix.get(selectors)
expect(matrix[:matrix].size).to eq 1
end
Expand Down Expand Up @@ -100,7 +100,7 @@ module PactBroker::Client

let(:selectors) { [{ pacticipant: "Foo", version: "1.2.3" }, { pacticipant: "Bar", version: "9.9.9" }] }

it 'returns a list of errors' do
it 'raises an error' do
expect {
pact_broker_client.matrix.get(selectors)
}.to raise_error PactBroker::Client::Error, "an error message"
Expand All @@ -127,12 +127,65 @@ module PactBroker::Client

let(:selectors) { [{ pacticipant: "Wiffle", version: "1.2.3" }, { pacticipant: "Meep", version: "9.9.9" }] }

it 'returns a list of errors' do
it 'raises an error' do
expect {
pact_broker_client.matrix.get(selectors)
}.to raise_error PactBroker::Client::Error, "an error message"
end
end

context "when no versions are specified" do
before do
pact_broker.
given("the pact for Foo version 1.2.3 and 1.2.4 has been verified by Bar version 4.5.6").
upon_receiving("a request for the compatibility matrix for all versions of Foo and Bar").
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][pacticipant]=Bar"
).
will_respond_with(
status: 200,
headers: pact_broker_response_headers,
body: {
matrix: Pact.each_like(matrix_row, min: 2)
}
)
end
let(:matrix_row) { JSON.parse(File.read('spec/support/matrix.json'))['matrix'].first }
let(:selectors) { [{ pacticipant: "Foo" }, { pacticipant: "Bar" }] }

it "returns multiple rows" do
matrix = pact_broker_client.matrix.get(selectors)
expect(matrix[:matrix].size).to eq 2
end
end

context "when the success option is true" do
before do
pact_broker.
given("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").
upon_receiving("a request for the successful rows of the compatibility matrix for all versions of Foo and Bar").
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][pacticipant]=Bar&success[]=true"
).
will_respond_with(
status: 200,
headers: pact_broker_response_headers,
body: matrix_response_body
)
end
let(:matrix_row) { JSON.parse(File.read('spec/support/matrix.json'))['matrix'].first }
let(:selectors) { [{ pacticipant: "Foo" }, { pacticipant: "Bar" }] }
let(:options) { {success: true} }

it "returns only the successful row" do
matrix = pact_broker_client.matrix.get(selectors, options)
expect(matrix[:matrix].size).to eq 1
end
end
end
end
end

0 comments on commit 40adb2e

Please sign in to comment.