diff --git a/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb b/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb index e61caab8b..a532e593b 100644 --- a/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +++ b/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb @@ -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)) diff --git a/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb b/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb index e8bcbabcb..7d5edbc49 100644 --- a/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +++ b/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb @@ -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, @@ -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