Skip to content

Commit

Permalink
feat: validate environment name in consumer version selector
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jul 12, 2021
1 parent 8ca449d commit f1ad8f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class VerifiablePactsJSONQuerySchema
optional(:deployed).filled(included_in?: [true])
optional(:released).filled(included_in?: [true])
optional(:deployedOrReleased).filled(included_in?: [true])
optional(:environment).filled(:str?)
optional(:environment).filled(:str?, :environment_with_name_exists?)

# rule(fallbackTagMustBeForLatest: [:fallbackTag, :latest]) do | fallback_tag, latest |
# fallback_tag.filled?.then(latest.eql?(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module PactBroker
module Api
module Contracts
describe VerifiablePactsJSONQuerySchema do
before do
allow(PactBroker::Deployments::EnvironmentService).to receive(:find_by_name).and_return(environment)
end
let(:environment) { double('environment') }

let(:params) do
{
providerVersionTags: provider_version_tags,
Expand Down Expand Up @@ -327,6 +332,16 @@ module Contracts

its([:consumerVersionSelectors, 0]) { is_expected.to eq "cannot specify a branch with latest=false (at index 0)" }
end

context "when the environment does not exist" do
let(:environment) { nil }

let(:consumer_version_selectors) do
[{ environment: "prod" }]
end

its([:consumerVersionSelectors, 0]) { is_expected.to eq "environment with name 'prod' does not exist at index 0" }
end
end
end
end
Expand Down

0 comments on commit f1ad8f6

Please sign in to comment.