Skip to content

Commit eed0120

Browse files
committed
feat(pacts for verification): include list of notices to print rather than inclusionReason and pendingReason
1 parent 72ff965 commit eed0120

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/pact_broker/api/decorators/verifiable_pact_decorator.rb

+11
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ def initialize(verifiable_pact)
2828
property :pending_reason, as: :pendingReason, exec_context: :decorator,
2929
if: ->(context) { context[:options][:user_options][:include_pending_status] }
3030

31+
property :notices, getter: -> (context) { context[:decorator].notices(context[:options][:user_options]) }
32+
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."}
33+
3134
def inclusion_reason
3235
PactBroker::Pacts::VerifiablePactMessages.new(represented).inclusion_reason
3336
end
3437

3538
def pending_reason
3639
PactBroker::Pacts::VerifiablePactMessages.new(represented).pending_reason
3740
end
41+
42+
def notices(user_options)
43+
mess = [{
44+
text: inclusion_reason
45+
}]
46+
mess << { text: pending_reason } if user_options[:include_pending_status]
47+
mess
48+
end
3849
end
3950

4051
link :self do | context |

spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ module Decorators
66
describe VerifiablePactDecorator do
77
before do
88
allow(decorator).to receive(:pact_version_url).and_return('/pact-version-url')
9-
allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:inclusion_reason).and_return("inclusion_reason")
10-
allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:pending_reason).and_return("pending_reason")
9+
allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:inclusion_reason).and_return("the inclusion reason")
10+
allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:pending_reason).and_return(pending_reason)
1111
end
12+
let(:pending_reason) { "the pending reason" }
1213
let(:expected_hash) do
1314
{
1415
"verificationProperties" => {
1516
"pending" => true,
16-
"pendingReason" => "pending_reason",
17-
"inclusionReason" => "inclusion_reason"
17+
"notices" => [
18+
{
19+
"text" => "the inclusion reason"
20+
}, {
21+
"text" => pending_reason
22+
}
23+
],
24+
"pendingReason" => pending_reason,
25+
"inclusionReason" => "the inclusion reason"
1826
},
1927
"_links" => {
2028
"self" => {
@@ -55,13 +63,15 @@ module Decorators
5563

5664
context "when include_pending_status is false" do
5765
let(:include_pending_status) { false }
66+
let(:notices) { subject['verificationProperties']['notices'].collect{ | notice | notice['text'] } }
5867

5968
it "does not include the pending flag" do
6069
expect(subject['verificationProperties']).to_not have_key('pending')
6170
end
6271

6372
it "does not include the pending reason" do
6473
expect(subject['verificationProperties']).to_not have_key('pendingReason')
74+
expect(notices).to_not include(pending_reason)
6575
end
6676
end
6777

0 commit comments

Comments
 (0)