Skip to content

Commit

Permalink
fix: add validation to ensure an environment or to tag is specified f…
Browse files Browse the repository at this point in the history
…or the /can-i-deploy endpoint
  • Loading branch information
bethesque committed Oct 18, 2022
1 parent a8829ae commit e9d772e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pact_broker/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ en:
invalid_webhook_uuid: The UUID can only contain the characters A-Z, a-z, 0-9, _ and -, and must be 16 or more characters.
pacticipant_not_found: No pacticipant with name '%{name}' found
environment_name_must_be_unique: Another environment with name '%{name}' already exists.
must_specify_environment_or_tag: Must specify either an environment or a 'to' tag.
cannot_specify_tag_and_environment: Cannot specify both a 'to' tag and an environment.
cannot_specify_latest_and_environment: Cannot specify both latest=true and an environment.
cannot_specify_more_than_one_destination_identifier: Cannot specify more than one of tag, environment and mainBranch.
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/matrix/can_i_deploy_query_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
require "pact_broker/messages"
require "pact_broker/api/contracts/dry_validation_predicates"
require "pact_broker/project_root"
require "pact_broker/string_refinements"

module PactBroker
module Api
module Contracts
class CanIDeployQuerySchema
extend PactBroker::Messages
using PactBroker::StringRefinements

SCHEMA = Dry::Validation.Schema do
configure do
Expand All @@ -26,6 +28,10 @@ def self.call(params)
result[:to] ||= []
result[:to] << message("errors.validation.cannot_specify_tag_and_environment")
end
if params[:to].blank? && params[:environment].blank?
result[:environment] ||= []
result[:environment] << message("errors.validation.must_specify_environment_or_tag")
end
result
end

Expand Down
15 changes: 15 additions & 0 deletions spec/lib/pact_broker/matrix/can_i_deploy_query_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ module Contracts
it { is_expected.to_not be_empty }
end

context "with neither a to tag or an environment specified" do
before do
allow(PactBroker::Deployments::EnvironmentService).to receive(:find_by_name).and_return(double("environment"))
end

let(:params) do
{
pacticipant: "foo",
version: "1"
}
end

it { is_expected.to_not be_empty }
end

context "when the environment does exist" do
before do
allow(PactBroker::Deployments::EnvironmentService).to receive(:find_by_name).and_return(double("environment"))
Expand Down

0 comments on commit e9d772e

Please sign in to comment.