-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add can-i-deploy endpoint for checking if the latest version fo…
…r a branch can be deployed to a particular environment
- Loading branch information
Showing
10 changed files
with
196 additions
and
23 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
50 changes: 50 additions & 0 deletions
50
lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment.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,50 @@ | ||
require "pact_broker/api/resources/matrix" | ||
require "pact_broker/matrix/can_i_deploy_query_schema" | ||
require "pact_broker/matrix/parse_can_i_deploy_query" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class CanIDeployPacticipantVersionByBranchToEnvironment < Matrix | ||
def resource_exists? | ||
!!(version && environment) | ||
end | ||
|
||
def malformed_request? | ||
false | ||
end | ||
|
||
def policy_name | ||
:'matrix::can_i_deploy' | ||
end | ||
|
||
private | ||
|
||
def selectors | ||
@selectors ||= [ | ||
PactBroker::Matrix::UnresolvedSelector.new( | ||
pacticipant_name: pacticipant_name, | ||
latest: true, | ||
branch: identifier_from_path[:branch_name] | ||
) | ||
] | ||
end | ||
|
||
def options | ||
@options ||= { | ||
latestby: "cvp", | ||
environment_name: identifier_from_path[:environment_name] | ||
} | ||
end | ||
|
||
def version | ||
@version ||= version_service.find_latest_by_pacticipant_name_and_branch_name(identifier_from_path[:pacticipant_name], identifier_from_path[:branch_name]) | ||
end | ||
|
||
def environment | ||
@environment ||= environment_service.find_by_name(identifier_from_path[:environment_name]) | ||
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
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
49 changes: 49 additions & 0 deletions
49
...ct_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_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,49 @@ | ||
require "pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag" | ||
require "pact_broker/matrix/service" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe CanIDeployPacticipantVersionByBranchToEnvironment do | ||
include_context "stubbed services" | ||
|
||
before do | ||
allow(PactBroker::Deployments::EnvironmentService).to receive(:find_by_name).and_return(environment) | ||
allow(PactBroker::Matrix::Service).to receive(:can_i_deploy).and_return([]) | ||
allow(pacticipant_service).to receive(:find_pacticipant_by_name).and_return(pacticipant) | ||
allow(PactBroker::Api::Decorators::MatrixDecorator).to receive(:new).and_return(decorator) | ||
allow(version_service).to receive(:find_latest_by_pacticipant_name_and_branch_name).and_return(version) | ||
end | ||
|
||
let(:pacticipant) { double("pacticipant") } | ||
let(:version) { double("version") } | ||
let(:json_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
let(:decorator) { double("decorator", to_json: "response_body") } | ||
let(:selectors) { double("selectors") } | ||
let(:options) { double("options") } | ||
let(:environment) { double("environment") } | ||
let(:path) { "/pacticipants/Foo/branches/main/latest-version/can-i-deploy/to-environment/dev" } | ||
|
||
subject { get(path, nil, "Content-Type" => "application/hal+json") } | ||
|
||
it "looks up the by branch" do | ||
expect(version_service).to receive(:find_latest_by_pacticipant_name_and_branch_name).with("Foo", "main") | ||
subject | ||
end | ||
|
||
it "checks if the version can be deployed to the environment" do | ||
expect(PactBroker::Matrix::Service).to receive(:can_i_deploy).with(anything, hash_including(environment_name: "dev")) | ||
subject | ||
end | ||
|
||
it { is_expected.to be_a_hal_json_success_response } | ||
|
||
context "when the environment does not exist" do | ||
let(:environment) { nil } | ||
|
||
its(:status) { is_expected.to eq 404 } | ||
end | ||
end | ||
end | ||
end | ||
end |
27 changes: 22 additions & 5 deletions
27
.../can_i_deploy_pacticipant_version_spec.rb → ...pacticipant_version_by_tag_to_tag_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
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