diff --git a/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb b/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb index f075620b2..30bae2305 100644 --- a/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +++ b/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb @@ -28,6 +28,9 @@ def initialize(verifiable_pact) property :pending_reason, as: :pendingReason, exec_context: :decorator, if: ->(context) { context[:options][:user_options][:include_pending_status] } + property :notices, getter: -> (context) { context[:decorator].notices(context[:options][:user_options]) } + property :noteToDevelopers, getter: -> (_) { "Please print out the text from the 'notices' rather than using the inclusionReason and the pendingReason fields. These will be removed when this API moves out of beta."} + def inclusion_reason PactBroker::Pacts::VerifiablePactMessages.new(represented).inclusion_reason end @@ -35,6 +38,14 @@ def inclusion_reason def pending_reason PactBroker::Pacts::VerifiablePactMessages.new(represented).pending_reason end + + def notices(user_options) + mess = [{ + text: inclusion_reason + }] + mess << { text: pending_reason } if user_options[:include_pending_status] + mess + end end link :self do | context | diff --git a/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb index ee4f469f6..15b992769 100644 --- a/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb @@ -6,15 +6,23 @@ module Decorators describe VerifiablePactDecorator do before do allow(decorator).to receive(:pact_version_url).and_return('/pact-version-url') - allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:inclusion_reason).and_return("inclusion_reason") - allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:pending_reason).and_return("pending_reason") + allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:inclusion_reason).and_return("the inclusion reason") + allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:pending_reason).and_return(pending_reason) end + let(:pending_reason) { "the pending reason" } let(:expected_hash) do { "verificationProperties" => { "pending" => true, - "pendingReason" => "pending_reason", - "inclusionReason" => "inclusion_reason" + "notices" => [ + { + "text" => "the inclusion reason" + }, { + "text" => pending_reason + } + ], + "pendingReason" => pending_reason, + "inclusionReason" => "the inclusion reason" }, "_links" => { "self" => { @@ -55,6 +63,7 @@ module Decorators context "when include_pending_status is false" do let(:include_pending_status) { false } + let(:notices) { subject['verificationProperties']['notices'].collect{ | notice | notice['text'] } } it "does not include the pending flag" do expect(subject['verificationProperties']).to_not have_key('pending') @@ -62,6 +71,7 @@ module Decorators it "does not include the pending reason" do expect(subject['verificationProperties']).to_not have_key('pendingReason') + expect(notices).to_not include(pending_reason) end end