From 3d799cc94627d6987daf475dcc37ce813b1689d2 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 6 Nov 2017 19:10:43 +1100 Subject: [PATCH] feat(can-i-deploy): support invocation with only one pacticipant/version provided --- lib/pact_broker/client/matrix.rb | 4 +- .../pacts/pact_broker_client-pact_broker.json | 64 ++++++++++++++++--- .../pact_broker_client_matrix_spec.rb | 59 +++++++++-------- 3 files changed, 91 insertions(+), 36 deletions(-) diff --git a/lib/pact_broker/client/matrix.rb b/lib/pact_broker/client/matrix.rb index 0d57215d..8c11e53c 100644 --- a/lib/pact_broker/client/matrix.rb +++ b/lib/pact_broker/client/matrix.rb @@ -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? diff --git a/spec/pacts/pact_broker_client-pact_broker.json b/spec/pacts/pact_broker_client-pact_broker.json index a1b084c8..51de0590 100644 --- a/spec/pacts/pact_broker_client-pact_broker.json +++ b/spec/pacts/pact_broker_client-pact_broker.json @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/spec/service_providers/pact_broker_client_matrix_spec.rb b/spec/service_providers/pact_broker_client_matrix_spec.rb index d89e0c46..888da23f 100644 --- a/spec/service_providers/pact_broker_client_matrix_spec.rb +++ b/spec/service_providers/pact_broker_client_matrix_spec.rb @@ -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, @@ -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, @@ -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 @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,