-
-
Notifications
You must be signed in to change notification settings - Fork 180
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-branch-pact-version" => { href: base_url + "/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}/latest", title: "Latest version of a pact for a given consumer, provider and consumer version branch", templated: false }, "pb:branch-pact-versions" => { href: base_url + "/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}", title: "All versions of a pact for a given consumer, provider and consumer version branch", templated: false }, "pb:latest-provider-pacts-with-branch" => { href: base_url + "/pacts/provider/{provider}/branch/{branch}/latest", title: "Latest pacts for provider with the specified branch", templated: true }, "pb:provider-pacts-with-branch" => { href: base_url + "/pacts/provider/{provider}/branch/{branch}", title: "All pact versions for the provider with the specified consumer version branch", templated: true }
- Loading branch information
Showing
15 changed files
with
245 additions
and
2 deletions.
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
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
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_by_consumer_branch( | ||
provider_name, | ||
branch_name: identifier_from_path[:branch_name], | ||
main_branch: identifier_from_path[:branch_name] ? false : true | ||
) | ||
end | ||
|
||
def resource_title | ||
suffix = identifier_from_path[:branch_name] ? " with consumer version branch '#{identifier_from_path[:branch_name]}'" : "" | ||
"Latest pact versions for the provider #{identifier_from_path[:provider_name]}#{suffix}" | ||
end | ||
end | ||
end | ||
end | ||
end |
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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
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_pacts_for_provider_by_consumer_branch( | ||
provider_name, | ||
branch_name: identifier_from_path[:branch_name], | ||
main_branch: identifier_from_path[:branch_name] ? false : true | ||
) | ||
end | ||
|
||
def resource_title | ||
suffix = identifier_from_path[:branch_name] ? " with consumer version branch '#{identifier_from_path[:branch_name]}'" : "" | ||
"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/branch-pact-versions.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 @@ | ||
# Branch pact versions | ||
|
||
Allowed methods: `GET` | ||
|
||
Path: `/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}` | ||
|
||
Lists all the pact versions with the specified consumer, provider and consumer version branch. |
7 changes: 7 additions & 0 deletions
7
lib/pact_broker/doc/views/index/latest-branch-pact-version.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 Branch pact versions | ||
|
||
Allowed methods: `GET` | ||
|
||
Path: `/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}/latest` | ||
|
||
Returns the latest pact version with the specified consumer, provider and consumer version branch. |
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}/branch/{branch}/latest` | ||
|
||
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
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_by_consumer_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/branch/prod/latest" } | ||
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_by_consumer_branch).with("Bar", branch_name: "prod", main_branch: false) | ||
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 |