-
-
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 badge url for 'can I deploy latest version of branch to env…
…ionment' endpoint
- Loading branch information
Showing
13 changed files
with
232 additions
and
87 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
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
29 changes: 29 additions & 0 deletions
29
...t_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.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,29 @@ | ||
require "pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class CanIDeployPacticipantVersionByBranchToEnvironmentBadge < CanIDeployPacticipantVersionByBranchToEnvironment | ||
include BadgeMethods | ||
|
||
private | ||
|
||
def badge_url | ||
if pacticipant && version && environment | ||
badge_service.can_i_deploy_badge_url(identifier_from_path[:branch_name], identifier_from_path[:environment_name], label, results.deployable?) | ||
elsif pacticipant.nil? | ||
badge_service.error_badge_url("pacticipant", "not found") | ||
elsif version.nil? | ||
if branch_service.find_branch(identifier_from_path.slice(:pacticipant_name, :branch_name)).nil? | ||
badge_service.error_badge_url("branch", "not found") | ||
else | ||
badge_service.error_badge_url("version", "not found") | ||
end | ||
else | ||
badge_service.error_badge_url("environment", "not found") | ||
end | ||
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
80 changes: 80 additions & 0 deletions
80
...ker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge_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,80 @@ | ||
require "pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe CanIDeployPacticipantVersionByBranchToEnvironmentBadge do | ||
before do | ||
allow_any_instance_of(described_class).to receive(:branch_service).and_return(branch_service) | ||
allow_any_instance_of(described_class).to receive(:badge_service).and_return(badge_service) | ||
|
||
allow(branch_service).to receive(:find_branch).and_return(branch) | ||
allow(badge_service). to receive(:can_i_deploy_badge_url).and_return("http://badge_url") | ||
allow(badge_service). to receive(:error_badge_url).and_return("http://error_badge_url") | ||
|
||
allow_any_instance_of(CanIDeployPacticipantVersionByBranchToEnvironmentBadge).to receive(:pacticipant).and_return(pacticipant) | ||
allow_any_instance_of(CanIDeployPacticipantVersionByBranchToEnvironmentBadge).to receive(:version).and_return(version) | ||
allow_any_instance_of(CanIDeployPacticipantVersionByBranchToEnvironmentBadge).to receive(:environment).and_return(environment) | ||
allow_any_instance_of(CanIDeployPacticipantVersionByBranchToEnvironmentBadge).to receive(:results).and_return(results) | ||
end | ||
|
||
let(:branch_service) { class_double("PactBroker::Versions::BranchService").as_stubbed_const } | ||
let(:badge_service) { class_double("PactBroker::Badges::Service").as_stubbed_const } | ||
|
||
let(:pacticipant) { double("pacticipant") } | ||
let(:version) { double("version") } | ||
let(:environment) { double("environment") } | ||
let(:branch) { double("branch") } | ||
let(:results) { instance_double("PactBroker::Matrix::QueryResultsWithDeploymentStatusSummary", deployable?: true )} | ||
|
||
let(:path) { "/pacticipants/Foo/branches/main/latest-version/can-i-deploy/to-environment/dev/badge" } | ||
|
||
subject { get(path, { label: "custom-label" }) } | ||
|
||
context "when everything is found" do | ||
it "return the badge URL" do | ||
expect(badge_service). to receive(:can_i_deploy_badge_url).with("main", "dev", "custom-label", true) | ||
expect(subject.headers["Location"]).to eq "http://badge_url" | ||
end | ||
end | ||
|
||
context "when the pacticipant is not found" do | ||
let(:pacticipant) { nil } | ||
|
||
it "returns an error badge URL" do | ||
expect(badge_service).to receive(:error_badge_url).with("pacticipant", "not found") | ||
expect(subject.headers["Location"]).to eq "http://error_badge_url" | ||
end | ||
end | ||
|
||
context "when the version is not found and the branch is not found" do | ||
let(:version) { nil } | ||
let(:branch) { nil } | ||
|
||
it "returns an error badge URL" do | ||
expect(badge_service).to receive(:error_badge_url).with("branch", "not found") | ||
expect(subject.headers["Location"]).to eq "http://error_badge_url" | ||
end | ||
end | ||
|
||
context "when the version is not found and the branch is found" do | ||
let(:version) { nil } | ||
|
||
it "returns an error badge URL" do | ||
expect(badge_service).to receive(:error_badge_url).with("version", "not found") | ||
expect(subject.headers["Location"]).to eq "http://error_badge_url" | ||
end | ||
end | ||
|
||
context "when the environment is not found" do | ||
let(:environment) { nil } | ||
|
||
it "returns an error badge URL" do | ||
expect(badge_service).to receive(:error_badge_url).with("environment", "not found") | ||
expect(subject.headers["Location"]).to eq "http://error_badge_url" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.