Skip to content

Commit 5a85a5a

Browse files
committed
feat(pacts for verification): include URL of pact in inclusion message
1 parent 4a4d9da commit 5a85a5a

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

lib/pact_broker/api/decorators/verifiable_pact_decorator.rb

+15-11
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,40 @@ def initialize(verifiable_pact)
2121
end
2222

2323
property :verification_properties, as: :verificationProperties do
24+
include PactBroker::Api::PactBrokerUrls
25+
2426
property :pending,
2527
if: ->(context) { context[:options][:user_options][:include_pending_status] }
2628
property :wip, if: -> (context) { context[:represented].wip }
27-
property :inclusion_reason, as: :inclusionReason, exec_context: :decorator
28-
property :pending_reason, as: :pendingReason, exec_context: :decorator,
29-
if: ->(context) { context[:options][:user_options][:include_pending_status] }
3029

3130
property :notices, getter: -> (context) { context[:decorator].notices(context[:options][:user_options]) }
3231
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."}
3332

34-
def inclusion_reason
35-
PactBroker::Pacts::VerifiablePactMessages.new(represented).inclusion_reason
33+
def inclusion_reason(pact_url)
34+
PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).inclusion_reason
3635
end
3736

38-
def pending_reason
39-
PactBroker::Pacts::VerifiablePactMessages.new(represented).pending_reason
37+
def pending_reason(pact_url)
38+
PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).pending_reason
4039
end
4140

4241
def notices(user_options)
42+
pact_url = pact_version_url(represented, user_options[:base_url])
4343
mess = [{
44-
text: inclusion_reason
44+
timing: 'pre_verification',
45+
text: inclusion_reason(pact_url)
4546
}]
46-
mess << { text: pending_reason } if user_options[:include_pending_status]
47+
mess << {
48+
timing: 'pre_verification',
49+
text: pending_reason(pact_url)
50+
} if user_options[:include_pending_status]
4751
mess
4852
end
4953
end
5054

51-
link :self do | context |
55+
link :self do | user_options |
5256
{
53-
href: pact_version_url(represented, context[:base_url]),
57+
href: pact_version_url(represented, user_options[:base_url]),
5458
name: represented.name
5559
}
5660
end

lib/pact_broker/pacts/verifiable_pact_messages.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ class VerifiablePactMessages
88

99
delegate [:consumer_name, :provider_name, :head_consumer_tags, :pending_provider_tags, :non_pending_provider_tags, :pending?, :wip?] => :verifiable_pact
1010

11-
def initialize(verifiable_pact)
11+
def initialize(verifiable_pact, pact_version_url)
1212
@verifiable_pact = verifiable_pact
13+
@pact_version_url = pact_version_url
1314
end
1415

1516
def inclusion_reason
1617
version_text = head_consumer_tags.size == 1 ? "version" : "versions"
1718
if wip?
1819
# WIP pacts will always have tags, because it is part of the definition of being a WIP pact
19-
"This pact is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest #{version_text} of Foo tagged with #{joined_head_consumer_tags} and is still in pending state). #{READ_MORE_WIP}"
20+
"The pact at #{pact_version_url} is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest #{version_text} of Foo tagged with #{joined_head_consumer_tags} and is still in pending state). #{READ_MORE_WIP}"
2021
else
2122
if head_consumer_tags.any?
22-
"This pact is being verified because it is the pact for the latest #{version_text} of Foo tagged with #{joined_head_consumer_tags}"
23+
"The pact at #{pact_version_url} is being verified because it is the pact for the latest #{version_text} of Foo tagged with #{joined_head_consumer_tags}"
2324
else
24-
"This pact is being verified because it is the latest pact between #{consumer_name} and #{provider_name}."
25+
"The pact at #{pact_version_url} is being verified because it is the latest pact between #{consumer_name} and #{provider_name}."
2526
end
2627
end
2728
end
@@ -36,7 +37,7 @@ def pending_reason
3637

3738
private
3839

39-
attr_reader :verifiable_pact
40+
attr_reader :verifiable_pact, :pact_version_url
4041

4142
def join(list, last_joiner = " and ")
4243
quoted_list = list.collect { | tag | "'#{tag}'" }

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Api
55
module Decorators
66
describe VerifiablePactDecorator do
77
before do
8-
allow(decorator).to receive(:pact_version_url).and_return('/pact-version-url')
8+
allow_any_instance_of(PactBroker::Api::PactBrokerUrls).to receive(:pact_version_url).and_return('/pact-version-url')
99
allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:inclusion_reason).and_return("the inclusion reason")
1010
allow_any_instance_of(PactBroker::Pacts::VerifiablePactMessages).to receive(:pending_reason).and_return(pending_reason)
1111
end
@@ -20,9 +20,7 @@ module Decorators
2020
}, {
2121
"text" => pending_reason
2222
}
23-
],
24-
"pendingReason" => pending_reason,
25-
"inclusionReason" => "the inclusion reason"
23+
]
2624
},
2725
"_links" => {
2826
"self" => {
@@ -61,6 +59,11 @@ module Decorators
6159
subject
6260
end
6361

62+
it "creates the inclusion message" do
63+
expect(PactBroker::Pacts::VerifiablePactMessages).to receive(:new).twice.with(pact, '/pact-version-url').and_call_original
64+
subject
65+
end
66+
6467
context "when include_pending_status is false" do
6568
let(:include_pending_status) { false }
6669
let(:notices) { subject['verificationProperties']['notices'].collect{ | notice | notice['text'] } }

spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@ module Pacts
2020
wip?: wip
2121
)
2222
end
23+
let(:pact_version_url) { "http://pact" }
2324

24-
subject { VerifiablePactMessages.new(verifiable_pact) }
25+
subject { VerifiablePactMessages.new(verifiable_pact, pact_version_url) }
2526

2627
describe "#inclusion_reason" do
2728
context "when there are no head consumer tags" do
28-
its(:inclusion_reason) { is_expected.to include "This pact is being verified because it is the latest pact between Foo and Bar." }
29+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the latest pact between Foo and Bar." }
2930
end
3031

3132
context "when there is 1 head consumer tags" do
3233
let(:head_consumer_tags) { %w[dev] }
33-
its(:inclusion_reason) { is_expected.to include "This pact is being verified because it is the pact for the latest version of Foo tagged with 'dev'" }
34+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the pact for the latest version of Foo tagged with 'dev'" }
3435
end
3536

3637
context "when there are 2 head consumer tags" do
3738
let(:head_consumer_tags) { %w[dev prod] }
38-
its(:inclusion_reason) { is_expected.to include "This pact is being verified because it is the pact for the latest versions of Foo tagged with 'dev' and 'prod' (both have the same content)" }
39+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the pact for the latest versions of Foo tagged with 'dev' and 'prod' (both have the same content)" }
3940
end
4041

4142
context "when there are 3 head consumer tags" do
4243
let(:head_consumer_tags) { %w[dev prod feat-x] }
43-
its(:inclusion_reason) { is_expected.to include "This pact is being verified because it is the pact for the latest versions of Foo tagged with 'dev', 'prod' and 'feat-x' (all have the same content)" }
44+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the pact for the latest versions of Foo tagged with 'dev', 'prod' and 'feat-x' (all have the same content)" }
4445
end
4546

4647
context "when there are 4 head consumer tags" do
@@ -54,7 +55,7 @@ module Pacts
5455
let(:head_consumer_tags) { %w[feat-x] }
5556
let(:pending_provider_tags) { %w[dev] }
5657

57-
its(:inclusion_reason) { is_expected.to include "This pact is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest version of Foo tagged with 'feat-x' and is still in pending state)."}
58+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest version of Foo tagged with 'feat-x' and is still in pending state)."}
5859
end
5960
end
6061

0 commit comments

Comments
 (0)