Skip to content

Commit

Permalink
feat(pacts for verification): do not require environment variable fea…
Browse files Browse the repository at this point in the history
…ture toggle to enable feature

Removes support for the GET method on the pacts for verification resource.
  • Loading branch information
bethesque committed Sep 8, 2020
1 parent 2d52d17 commit 7d0fe1e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 203 deletions.
37 changes: 0 additions & 37 deletions lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb

This file was deleted.

15 changes: 8 additions & 7 deletions lib/pact_broker/api/resources/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ def links
}]
}

if PactBroker.feature_enabled?(:pacts_for_verification)
links_hash['beta:provider-pacts-for-verification'] = {
href: base_url + '/pacts/provider/{provider}/for-verification',
title: 'Pact versions to be verified for the specified provider',
templated: true
}
end

links_hash['pb:provider-pacts-for-verification'] = {
href: base_url + '/pacts/provider/{provider}/for-verification',
title: 'Pact versions to be verified for the specified provider',
templated: true
}

links_hash['beta:provider-pacts-for-verification'] = links_hash['pb:provider-pacts-for-verification']

links_hash
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'pact_broker/api/resources/provider_pacts'
require 'pact_broker/api/decorators/verifiable_pacts_decorator'
require 'pact_broker/api/contracts/verifiable_pacts_query_schema'
require 'pact_broker/api/decorators/verifiable_pacts_query_decorator'
require 'pact_broker/api/contracts/verifiable_pacts_json_query_schema'
require 'pact_broker/hash_refinements'
Expand All @@ -12,7 +11,7 @@ class ProviderPactsForVerification < ProviderPacts
using PactBroker::HashRefinements

def allowed_methods
["GET", "POST", "OPTIONS"]
["POST", "OPTIONS"]
end

def content_types_accepted
Expand Down Expand Up @@ -56,11 +55,7 @@ def to_json
end

def query_schema
if request.get?
PactBroker::Api::Contracts::VerifiablePactsQuerySchema
else
PactBroker::Api::Contracts::VerifiablePactsJSONQuerySchema
end
PactBroker::Api::Contracts::VerifiablePactsJSONQuerySchema
end

def parsed_query_params
Expand Down
80 changes: 80 additions & 0 deletions lib/pact_broker/doc/views/provider-pacts-for-verification.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Provider pacts for verification

Path: `/pacts/provider/{provider}/for-verification`

Allowed methods: `POST`

Content type: `application/hal+json`

Returns a deduplicated list of pacts to be verified by the specified provider.

### Body

Example: This data structure represents the way a user might specify "I want to verify the latest 'master' pact, all 'prod' pacts, and when I publish the verification results, I'm going to tag the provider version with 'master'"


```json
{
"consumerVersionSelectors": [
{
"tag": "master",
"latest": true
},{
"tag": "prod"
}
],
"providerVersionTags": ["master"],
"includePendingStatus": true,
"includeWipPactsSince": "2020-01-01"
}
```

`consumerVersionSelectors.tag`: the tag name(s) of the consumer versions to get the pacts for.

`consumerVersionSelectors.fallbackTag`: the name of the tag to fallback to if the specified `tag` does not exist. This is useful when the consumer and provider use matching branch names to coordinate the development of new features.

`consumerVersionSelectors.latest`: true. If the latest flag is omitted, *all* the pacts with the specified tag will be returned. (This might seem a bit weird, but it's done this way to match the syntax used for the matrix query params. See https://docs.pact.io/selectors)

`consumerVersionSelectors.consumer`: allows a selector to only be applied to a certain consumer. This is used when there is an API that has multiple consumers, one of which is a deployed service, and one of which is a mobile consumer. The deployed service only needs the latest production pact verified, where as the mobile consumer may want all the production pacts verified.

`providerVersionTags`: the tag name(s) for the provider application version that will be published with the verification results. This is used by the Broker to determine whether or not a particular pact is in pending state or not. This parameter can be specified multiple times.

`includePendingStatus`: true|false (default false). When true, a pending boolean will be added to the verificationProperties in the response, and an extra message will appear in the notices array to indicate why this pact is/is not in pending state. This will allow your code to handle the response based on only what is present in the response, and not have to do ifs based on the user's options together with the response. As requested in the "pacts for verification" issue, please print out these messages in the tests if possible. If not possible, perhaps create a separate task which will list the pact URLs and messages for debugging purposes.

`includeWipPactsSince`: Date string. The date from which to include the "work in progress" pacts. See https://docs.pact.io/wip for more information on work in progress pacts.

### Response body

`pending` flag and the "pending reason" notice will only be included if `includePendingStatus` is set to true.

```json
{
"_embedded": {
"pacts": [
{
"verificationProperties": {
"notices": [
{
"text": "This pact is being verified because it is the pact for the latest version of Foo tagged with 'dev'",
"when": "before_verification"
}
],
"pending": false
},
"_links": {
"self": {
"href": "http://localhost:9292/pacts/provider/Bar/consumer/Foo/pact-version/0e3369199f4008231946e0245474537443ccda2a",
"name": "Pact between Foo (v1.0.0) and Bar"
}
}
}
]
},
"_links": {
"self": {
"href": "http://localhost:9292/pacts/provider/Bar/for-verification",
"title": "Pacts to be verified"
}
}
}
```
18 changes: 0 additions & 18 deletions spec/features/get_provider_pacts_for_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@

let(:path) { "/pacts/provider/Provider/for-verification" }

context "when using GET" do
it "returns a 200 HAL JSON response" do
expect(subject).to be_a_hal_json_success_response
end

it "returns a list of links to the pacts" do
expect(pacts.size).to eq 1
end

context "when the provider does not exist" do
let(:path) { "/pacts/provider/ProviderThatDoesNotExist/for-verification" }

it "returns a 404 response" do
expect(subject).to be_a_404_response
end
end
end

context "when using POST" do
let(:request_body) do
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,7 @@ module Resources
}
end

subject { get(path, query) }

describe "GET" do
it "finds the pacts for verification by the provider" do
# Naughty not mocking out the query parsing...
expect(PactBroker::Pacts::Service).to receive(:find_for_verification).with(
"Bar",
["master"],
PactBroker::Pacts::Selectors.new([PactBroker::Pacts::Selector.latest_for_tag("dev")]),
{
include_wip_pacts_since: DateTime.parse('2018-01-01'),
include_pending_status: true
}
)
subject
end

context "when there are validation errors" do
let(:query) do
{
provider_version_tags: true,
}
end

it "returns the keys with the right case" do
expect(JSON.parse(subject.body)['errors']).to have_key('provider_version_tags')
end
end
end
subject { post(path, request_body.to_json, request_headers) }

describe "POST" do
let(:request_body) do
Expand All @@ -70,8 +42,6 @@ module Resources
}
end

subject { post(path, request_body.to_json, request_headers) }

it "finds the pacts for verification by the provider" do
# Naughty not mocking out the query parsing...
expect(PactBroker::Pacts::Service).to receive(:find_for_verification).with(
Expand All @@ -97,14 +67,14 @@ module Resources
expect(JSON.parse(subject.body)['errors']).to have_key('providerVersionTags')
end
end
end

it "uses the correct options for the decorator" do
expect(decorator).to receive(:to_json) do | options |
expect(options[:user_options][:title]).to eq "Pacts to be verified by provider Bar"
expect(options[:user_options][:include_pending_status]).to eq true
it "uses the correct options for the decorator" do
expect(decorator).to receive(:to_json) do | options |
expect(options[:user_options][:title]).to eq "Pacts to be verified by provider Bar"
expect(options[:user_options][:include_pending_status]).to eq true
end
subject
end
subject
end
end
end
Expand Down

0 comments on commit 7d0fe1e

Please sign in to comment.