Skip to content

Commit bb07985

Browse files
committed
feat(pacts for verification): add pre and post verification messages that can be displayed to the user based on whether or not the verification has passed or failed
1 parent e16feef commit bb07985

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

lib/pact_broker/api/decorators/verifiable_pact_decorator.rb

+24-16
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,33 @@ def initialize(verifiable_pact)
3030
property :notices, getter: -> (context) { context[:decorator].notices(context[:options][:user_options]) }
3131
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."}
3232

33-
def inclusion_reason(pact_url)
34-
PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).inclusion_reason
35-
end
36-
37-
def pending_reason(pact_url)
38-
PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).pending_reason
39-
end
40-
4133
def notices(user_options)
34+
# TODO move this out of the decorator
4235
pact_url = pact_version_url(represented, user_options[:base_url])
43-
mess = [{
44-
timing: 'pre_verification',
45-
text: inclusion_reason(pact_url)
36+
messages = PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url)
37+
38+
the_notices = [{
39+
when: 'before_verification',
40+
text: messages.inclusion_reason
4641
}]
47-
mess << {
48-
timing: 'pre_verification',
49-
text: pending_reason(pact_url)
50-
} if user_options[:include_pending_status]
51-
mess
42+
43+
if user_options[:include_pending_status]
44+
append_notice(the_notices, 'before_verification', messages.pending_reason)
45+
append_notice(the_notices, 'after_verification:success_true_published_false', messages.verification_success_true_published_false)
46+
append_notice(the_notices, 'after_verification:success_false_published_false', messages.verification_success_false_published_false)
47+
append_notice(the_notices, 'after_verification:success_true_published_true', messages.verification_success_true_published_true)
48+
append_notice(the_notices, 'after_verification:success_false_published_true', messages.verification_success_false_published_true)
49+
end
50+
the_notices
51+
end
52+
53+
def append_notice the_notices, the_when, text
54+
if text
55+
the_notices << {
56+
when: the_when,
57+
text: text
58+
}
59+
end
5260
end
5361
end
5462

lib/pact_broker/pacts/verifiable_pact_messages.rb

+30
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ def pending_reason
3535
end
3636
end
3737

38+
def verification_success_true_published_false
39+
if pending?
40+
"This pact is still in pending state for #{pending_provider_tags_description} as the successful verification results #{with_these_tags}have not yet been published."
41+
end
42+
end
43+
44+
def verification_success_true_published_true
45+
if pending?
46+
"This pact is no longer in pending state for #{pending_provider_tags_description}, as a successful verification result #{with_these_tags}has been published. If a verification for a version with fails in the future, it will fail the build. #{READ_MORE_PENDING}"
47+
end
48+
end
49+
50+
def verification_success_false_published_false
51+
if pending?
52+
"This pact is still in pending state for #{pending_provider_tags_description} as a successful verification result #{with_these_tags}has not yet been published"
53+
end
54+
end
55+
56+
def verification_success_false_published_true
57+
verification_success_false_published_false
58+
end
59+
3860
private
3961

4062
attr_reader :verifiable_pact, :pact_version_url
@@ -77,6 +99,14 @@ def non_pending_provider_tags_description
7799
else "a version of #{provider_name} with tag #{join(non_pending_provider_tags)}"
78100
end
79101
end
102+
103+
def with_these_tags
104+
case pending_provider_tags.size
105+
when 0 then ""
106+
when 1 then "with this tag "
107+
else "with these tags "
108+
end
109+
end
80110
end
81111
end
82112
end

0 commit comments

Comments
 (0)