-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add provider pacts by branch endpoints
"pb:latest-provider-pacts-with-branch": { "href": "http://localhost:9292/pacts/provider/{provider}/latest/branch/{branch}", "title": "Latest pacts for provider with the specified branch", "templated": true }, "pb:provider-pacts-with-branch": { "href": "http://localhost:9292/pacts/provider/{provider}/branch/{branch}", "title": "All pact versions for the provider with the specified consumer version branch", "templated": true },
- Loading branch information
Showing
10 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
lib/pact_broker/api/resources/latest_provider_pacts_for_branch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "pact_broker/api/resources/provider_pacts" | ||
require "pact_broker/configuration" | ||
require "pact_broker/api/decorators/provider_pacts_decorator" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class LatestProviderPactsForBranch < ProviderPacts | ||
private | ||
|
||
def pacts | ||
pact_service.find_latest_pacts_for_provider_for_branch(provider_name, branch: identifier_from_path[:branch]) | ||
end | ||
|
||
def resource_title | ||
suffix = identifier_from_path[:branch] ? " with consumer version branch '#{identifier_from_path[:branch]}'" : "" | ||
"Latest pact versions for the provider #{identifier_from_path[:provider_name]}#{suffix}" | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
lib/pact_broker/api/resources/provider_pacts_for_consumer_branch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "pact_broker/api/resources/base_resource" | ||
require "pact_broker/configuration" | ||
require "pact_broker/api/decorators/provider_pacts_decorator" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class ProviderPactsForConsumerBranch < BaseResource | ||
|
||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def allowed_methods | ||
["GET", "OPTIONS"] | ||
end | ||
|
||
def resource_exists? | ||
!!provider | ||
end | ||
|
||
def policy_name | ||
:'pacts::provider_pacts' | ||
end | ||
|
||
def to_json | ||
decorator_class(:provider_pacts_decorator).new(pacts).to_json(**decorator_options(identifier_from_path.merge(title: resource_title))) | ||
end | ||
|
||
private | ||
|
||
def pacts | ||
pact_service.find_pact_versions_for_provider provider_name, branch: identifier_from_path[:branch] | ||
end | ||
|
||
def resource_title | ||
suffix = identifier_from_path[:branch] ? " with consumer version branch '#{identifier_from_path[:branch]}'" : "" | ||
"All pact versions for the provider #{identifier_from_path[:provider_name]}#{suffix}" | ||
end | ||
end | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/pact_broker/doc/views/index/latest-provider-pacts-with-branch.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Latest pacts for provider with the specified consumer branch | ||
|
||
Allowed methods: `GET` | ||
|
||
Path: `/pacts/provider/{provider}/latest/branch/{branch}` | ||
|
||
Given a provider name and a consumer version branch name, this resource returns the latest pact for each consumer that has the specified branch. |
4 changes: 3 additions & 1 deletion
4
lib/pact_broker/doc/views/index/latest-provider-pacts-with-tag.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Latest pacts for provider with the specified tag | ||
# Latest pacts for provider with the specified consumer version tag | ||
|
||
Allowed methods: `GET` | ||
|
||
Path: `/pacts/provider/{provider}/latest/{tag}` | ||
|
||
Given a provider name and a consumer version tag name, this resource returns the latest pact for each consumer that has the specified tag. |
7 changes: 7 additions & 0 deletions
7
lib/pact_broker/doc/views/index/provider-pacts-with-branch.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Provider pacts with consumer branch | ||
|
||
Allowed methods: `GET` | ||
|
||
Path: `/pacts/provider/{provider}/branch/{branch}` | ||
|
||
Given a pacticipant name and a consumer branch, this resource returns all the pact versions for all consumers of this provider with the specified consumer branch. For most use cases, the `latest-provider-pacts-with-branch` relation will better serve consumer needs by only returning the latest pact version for specified consumer branches. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
spec/lib/pact_broker/api/resources/latest_provider_pacts_for_branch_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "pact_broker/api/resources/latest_provider_pacts_for_branch" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe LatestProviderPactsForBranch do | ||
before do | ||
allow(PactBroker::Pacts::Service).to receive(:find_latest_pacts_for_provider_for_branch).and_return(pacts) | ||
allow(PactBroker::Api::Decorators::ProviderPactsDecorator).to receive(:new).and_return(decorator) | ||
allow_any_instance_of(LatestProviderPactsForBranch).to receive(:resource_exists?).and_return(provider) | ||
end | ||
|
||
let(:provider) { double("provider") } | ||
let(:pacts) { double("pacts") } | ||
let(:path) { "/pacts/provider/Bar/latest/branch/prod" } | ||
let(:decorator) { instance_double("PactBroker::Api::Decorators::ProviderPactsDecorator") } | ||
|
||
subject { get path; last_response } | ||
|
||
context "with a branch" do | ||
it "finds the pacts with a branch" do | ||
expect(PactBroker::Pacts::Service).to receive(:find_latest_pacts_for_provider_for_branch).with("Bar", branch: "prod") | ||
subject | ||
end | ||
|
||
it "sets the correct resource title" do | ||
expect(decorator).to receive(:to_json) do | options | | ||
expect(options[:user_options][:title]).to eq "Latest pact versions for the provider Bar with consumer version branch 'prod'" | ||
end | ||
subject | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |