Skip to content

Commit

Permalink
feat(pacts for verification): include list of notices to print rather…
Browse files Browse the repository at this point in the history
… than inclusionReason and pendingReason
  • Loading branch information
bethesque committed Dec 5, 2019
1 parent 72ff965 commit eed0120
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions lib/pact_broker/api/decorators/verifiable_pact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ 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

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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down Expand Up @@ -55,13 +63,15 @@ 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')
end

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

Expand Down

0 comments on commit eed0120

Please sign in to comment.