From f9792103e1e46718873df268f9e8af04be48411a Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 31 Oct 2017 08:55:52 +1100 Subject: [PATCH] feat(matrix): add reason text to summary --- .../api/decorators/matrix_decorator.rb | 15 ++++++- .../api/decorators/matrix_decorator_spec.rb | 42 ++++++++++++++++--- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/lib/pact_broker/api/decorators/matrix_decorator.rb b/lib/pact_broker/api/decorators/matrix_decorator.rb index 0440fc0d6..e402f17df 100644 --- a/lib/pact_broker/api/decorators/matrix_decorator.rb +++ b/lib/pact_broker/api/decorators/matrix_decorator.rb @@ -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]) } @@ -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 diff --git a/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb index 2317b860d..5fad64dc6 100644 --- a/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb @@ -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", @@ -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 @@ -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 @@ -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 @@ -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