Skip to content

Commit

Permalink
feat(matrix): add reason text to summary
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 30, 2017
1 parent d97b8ab commit f979210
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
15 changes: 13 additions & 2 deletions lib/pact_broker/api/decorators/matrix_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def to_json(options)
def to_hash(options)
{
summary: {
deployable: deployable?
deployable: deployable,
reason: reason
},
matrix: matrix(lines, options[:user_options][:base_url])
}
Expand All @@ -28,10 +29,20 @@ def to_hash(options)

attr_reader :lines

def deployable?
def deployable
return nil if lines.any?{ |line| line[:success].nil? }
lines.any? && lines.all?{ |line| line[:success] }
end

def reason
case deployable
when true then "All verification results are published and successful"
when false then "One or more verifications have failed"
else
"Missing one or more verification results"
end
end

def matrix(lines, base_url)
provider = nil
consumer = nil
Expand Down
42 changes: 36 additions & 6 deletions spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Decorators
describe "to_json" do
let(:verification_date) { DateTime.new(2017, 12, 31) }
let(:pact_created_at) { DateTime.new(2017, 1, 1) }
let(:line_1_success) { true }
let(:line_2_success) { true }
let(:line_1) do
{
consumer_name: "Consumer",
Expand All @@ -15,7 +17,7 @@ module Decorators
pact_created_at: pact_created_at,
provider_version_number: "4.5.6",
provider_name: "Provider",
success: true,
success: line_1_success,
number: 1,
build_url: nil,
verification_executed_at: verification_date
Expand All @@ -30,10 +32,10 @@ module Decorators
pact_created_at: pact_created_at,
provider_version_number: nil,
provider_name: "Provider",
success: nil,
success: line_2_success,
number: nil,
build_url: nil,
verification_executed_at: nil
verification_executed_at: verification_date
}
end

Expand Down Expand Up @@ -114,14 +116,18 @@ module Decorators
end

it "includes a summary" do
expect(parsed_json[:summary][:deployable]).to eq false
expect(parsed_json[:summary][:deployable]).to eq true
expect(parsed_json[:summary][:reason]).to match /All verification results are published/
end

context "when the pact has not been verified" do
let(:verification_hash) do
nil
before do
line_2[:success] = nil
line_2[:verification_executed_at] = nil
end

let(:verification_hash) { nil }

it "has empty provider details" do
expect(parsed_json[:matrix][1][:provider]).to eq provider_hash.merge(version: nil)
end
Expand All @@ -130,6 +136,30 @@ module Decorators
expect(parsed_json[:matrix][1][:verificationResult]).to eq verification_hash
end
end

context "when one or more successes are nil" do
let(:line_1_success) { nil }

it "has a deployable flag of nil" do
expect(parsed_json[:summary][:deployable]).to be nil
end

it "has an explanation" do
expect(parsed_json[:summary][:reason]).to match /Missing/
end
end

context "when one or more successes are false" do
let(:line_1_success) { false }

it "has a deployable flag of false" do
expect(parsed_json[:summary][:deployable]).to be false
end

it "has an explanation" do
expect(parsed_json[:summary][:reason]).to match /have failed/
end
end
end
end
end
Expand Down

0 comments on commit f979210

Please sign in to comment.