From db7dee3a9c1d5d25cdd17cca1be864a57c48f75f Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 13 Jul 2023 09:54:27 +1000 Subject: [PATCH] fix: fix error occuring when can-i-deploy badge is requested and no version is found PACT-1145 --- ...pacticipant_version_by_branch_to_environment_badge.rb | 2 +- ...cipant_version_by_branch_to_environment_badge_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.rb b/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.rb index 89c77da55..f8084e87c 100644 --- a/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.rb +++ b/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.rb @@ -14,7 +14,7 @@ def badge_url 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? + 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") diff --git a/spec/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge_spec.rb b/spec/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge_spec.rb index 43294ea32..7ffcd0235 100644 --- a/spec/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge_spec.rb +++ b/spec/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge_spec.rb @@ -47,6 +47,15 @@ module Resources end end + context "when the version is not found" do + let(:version) { nil } + + it "attempts to find the branch" do + expect(branch_service).to receive(:find_branch).with(pacticipant_name: "Foo", branch_name: "main") + subject + end + end + context "when the version is not found and the branch is not found" do let(:version) { nil } let(:branch) { nil }