Skip to content

Commit

Permalink
feat(pacts for verification): add pre and post verification messages …
Browse files Browse the repository at this point in the history
…that can be displayed to the user based on whether or not the verification has passed or failed
  • Loading branch information
bethesque committed Jan 30, 2020
1 parent e16feef commit bb07985
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/pact_broker/api/decorators/verifiable_pact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,33 @@ def initialize(verifiable_pact)
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(pact_url)
PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).inclusion_reason
end

def pending_reason(pact_url)
PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).pending_reason
end

def notices(user_options)
# TODO move this out of the decorator
pact_url = pact_version_url(represented, user_options[:base_url])
mess = [{
timing: 'pre_verification',
text: inclusion_reason(pact_url)
messages = PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url)

the_notices = [{
when: 'before_verification',
text: messages.inclusion_reason
}]
mess << {
timing: 'pre_verification',
text: pending_reason(pact_url)
} if user_options[:include_pending_status]
mess

if user_options[:include_pending_status]
append_notice(the_notices, 'before_verification', messages.pending_reason)
append_notice(the_notices, 'after_verification:success_true_published_false', messages.verification_success_true_published_false)
append_notice(the_notices, 'after_verification:success_false_published_false', messages.verification_success_false_published_false)
append_notice(the_notices, 'after_verification:success_true_published_true', messages.verification_success_true_published_true)
append_notice(the_notices, 'after_verification:success_false_published_true', messages.verification_success_false_published_true)
end
the_notices
end

def append_notice the_notices, the_when, text
if text
the_notices << {
when: the_when,
text: text
}
end
end
end

Expand Down
30 changes: 30 additions & 0 deletions lib/pact_broker/pacts/verifiable_pact_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ def pending_reason
end
end

def verification_success_true_published_false
if pending?
"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."
end
end

def verification_success_true_published_true
if pending?
"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}"
end
end

def verification_success_false_published_false
if pending?
"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"
end
end

def verification_success_false_published_true
verification_success_false_published_false
end

private

attr_reader :verifiable_pact, :pact_version_url
Expand Down Expand Up @@ -77,6 +99,14 @@ def non_pending_provider_tags_description
else "a version of #{provider_name} with tag #{join(non_pending_provider_tags)}"
end
end

def with_these_tags
case pending_provider_tags.size
when 0 then ""
when 1 then "with this tag "
else "with these tags "
end
end
end
end
end

0 comments on commit bb07985

Please sign in to comment.