Skip to content

Commit

Permalink
feat(can-i-deploy): support invocation with only one pacticipant/vers…
Browse files Browse the repository at this point in the history
…ion provided
  • Loading branch information
bethesque committed Nov 6, 2017
1 parent 9ecb006 commit 3d799cc
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 36 deletions.
4 changes: 3 additions & 1 deletion lib/pact_broker/client/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module PactBroker
module Client
class Matrix < BaseClient
def get selectors, options = {}
latestby = selectors.size == 1 ? 'cvp' : 'cvpv'
query = {
q: convert_selector_hashes_to_params(selectors)
q: convert_selector_hashes_to_params(selectors),
latestby: latestby
}.merge(query_options(options))
response = self.class.get("/matrix", query: query, headers: default_get_headers)
$stdout.puts("DEBUG: Response headers #{response.headers}") if verbose?
Expand Down
64 changes: 56 additions & 8 deletions spec/pacts/pact_broker_client-pact_broker.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6"
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6&latestby=cvpv"
},
"response": {
"status": 200,
Expand Down Expand Up @@ -240,7 +240,55 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo%20Thing&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6"
"query": "q[][pacticipant]=Foo%20Thing&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6&latestby=cvpv"
},
"response": {
"status": 200,
"headers": {
},
"body": {
"summary": {
"deployable": true,
"reason": "some text"
},
"matrix": [
{
"consumer": {
"name": "Foo",
"version": {
"number": "4"
}
},
"provider": {
"name": "Bar",
"version": {
"number": "5"
}
},
"verificationResult": {
"verifiedAt": "2017-10-10T12:49:04+11:00",
"success": true
},
"pact": {
"createdAt": "2017-10-10T12:49:04+11:00"
}
}
]
},
"matchingRules": {
"$.body": {
"match": "type"
}
}
}
},
{
"description": "a request for the compatibility matrix where only the version of Foo is specified",
"providerState": "the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6 and version 5.6.7",
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp"
},
"response": {
"status": 200,
Expand Down Expand Up @@ -288,7 +336,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9"
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9&latestby=cvpv"
},
"response": {
"status": 400,
Expand All @@ -314,7 +362,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Wiffle&q[][version]=1.2.3&q[][pacticipant]=Meep&q[][version]=9.9.9"
"query": "q[][pacticipant]=Wiffle&q[][version]=1.2.3&q[][pacticipant]=Meep&q[][version]=9.9.9&latestby=cvpv"
},
"response": {
"status": 400,
Expand All @@ -341,7 +389,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][pacticipant]=Bar"
"query": "q[][pacticipant]=Foo&q[][pacticipant]=Bar&latestby=cvpv"
},
"response": {
"status": 200,
Expand Down Expand Up @@ -409,7 +457,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][pacticipant]=Bar&success[]=true"
"query": "q[][pacticipant]=Foo&q[][pacticipant]=Bar&latestby=cvpv&success[]=true"
},
"response": {
"status": 200,
Expand Down Expand Up @@ -457,7 +505,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][latest]=true&q[][tag]=prod"
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][latest]=true&q[][tag]=prod&latestby=cvpv"
},
"response": {
"status": 200,
Expand Down Expand Up @@ -505,7 +553,7 @@
"request": {
"method": "get",
"path": "/matrix",
"query": "q[][pacticipant]=Foo&q[][version]=1.2.4&q[][pacticipant]=Bar&q[][latest]=true"
"query": "q[][pacticipant]=Foo&q[][version]=1.2.4&q[][pacticipant]=Bar&q[][latest]=true&latestby=cvpv"
},
"response": {
"status": 200,
Expand Down
59 changes: 32 additions & 27 deletions spec/service_providers/pact_broker_client_matrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6"
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6&latestby=cvpv"
).
will_respond_with(
status: 200,
Expand All @@ -42,7 +42,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo%20Thing&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6"
query: "q[][pacticipant]=Foo%20Thing&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6&latestby=cvpv"
).
will_respond_with(
status: 200,
Expand All @@ -59,25 +59,30 @@ module PactBroker::Client
end
end

# context "with only one version selector" do
# before do
# pact_broker.
# given("the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6").
# upon_receiving("a request for the compatibility matrix where only the version of Foo is specified").
# with(
# method: :get,
# path: "/matrix",
# query: {
# 'selectors[]' => ['Foo/version/1.2.3']
# }
# ).
# will_respond_with(
# status: 200,
# headers: pact_broker_response_headers,
# body: matrix_response_body
# )
# end
# end
context "with only one version selector" do
before do
pact_broker.
given("the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6 and version 5.6.7").
upon_receiving("a request for the compatibility matrix where only the version of Foo is specified").
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp"
).
will_respond_with(
status: 200,
headers: pact_broker_response_headers,
body: matrix_response_body
)
end

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

it 'returns the row with the lastest verification for version 1.2.3' do
matrix = pact_broker_client.matrix.get(selectors)
expect(matrix[:matrix].size).to eq 1
end
end

context "when one or more of the versions does not exist" do
before do
Expand All @@ -87,7 +92,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9"
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9&latestby=cvpv"
).
will_respond_with(
status: 400,
Expand All @@ -114,7 +119,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Wiffle&q[][version]=1.2.3&q[][pacticipant]=Meep&q[][version]=9.9.9"
query: "q[][pacticipant]=Wiffle&q[][version]=1.2.3&q[][pacticipant]=Meep&q[][version]=9.9.9&latestby=cvpv"
).
will_respond_with(
status: 400,
Expand Down Expand Up @@ -142,7 +147,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][pacticipant]=Bar"
query: "q[][pacticipant]=Foo&q[][pacticipant]=Bar&latestby=cvpv"
).
will_respond_with(
status: 200,
Expand All @@ -169,7 +174,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][pacticipant]=Bar&success[]=true"
query: "q[][pacticipant]=Foo&q[][pacticipant]=Bar&latestby=cvpv&success[]=true"
).
will_respond_with(
status: 200,
Expand All @@ -195,7 +200,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][latest]=true&q[][tag]=prod"
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][latest]=true&q[][tag]=prod&latestby=cvpv"
).
will_respond_with(
status: 200,
Expand All @@ -221,7 +226,7 @@ module PactBroker::Client
with(
method: :get,
path: "/matrix",
query: "q[][pacticipant]=Foo&q[][version]=1.2.4&q[][pacticipant]=Bar&q[][latest]=true"
query: "q[][pacticipant]=Foo&q[][version]=1.2.4&q[][pacticipant]=Bar&q[][latest]=true&latestby=cvpv"
).
will_respond_with(
status: 200,
Expand Down

0 comments on commit 3d799cc

Please sign in to comment.