Skip to content

Commit f979210

Browse files
committed
feat(matrix): add reason text to summary
1 parent d97b8ab commit f979210

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

lib/pact_broker/api/decorators/matrix_decorator.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def to_json(options)
1818
def to_hash(options)
1919
{
2020
summary: {
21-
deployable: deployable?
21+
deployable: deployable,
22+
reason: reason
2223
},
2324
matrix: matrix(lines, options[:user_options][:base_url])
2425
}
@@ -28,10 +29,20 @@ def to_hash(options)
2829

2930
attr_reader :lines
3031

31-
def deployable?
32+
def deployable
33+
return nil if lines.any?{ |line| line[:success].nil? }
3234
lines.any? && lines.all?{ |line| line[:success] }
3335
end
3436

37+
def reason
38+
case deployable
39+
when true then "All verification results are published and successful"
40+
when false then "One or more verifications have failed"
41+
else
42+
"Missing one or more verification results"
43+
end
44+
end
45+
3546
def matrix(lines, base_url)
3647
provider = nil
3748
consumer = nil

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

+36-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Decorators
77
describe "to_json" do
88
let(:verification_date) { DateTime.new(2017, 12, 31) }
99
let(:pact_created_at) { DateTime.new(2017, 1, 1) }
10+
let(:line_1_success) { true }
11+
let(:line_2_success) { true }
1012
let(:line_1) do
1113
{
1214
consumer_name: "Consumer",
@@ -15,7 +17,7 @@ module Decorators
1517
pact_created_at: pact_created_at,
1618
provider_version_number: "4.5.6",
1719
provider_name: "Provider",
18-
success: true,
20+
success: line_1_success,
1921
number: 1,
2022
build_url: nil,
2123
verification_executed_at: verification_date
@@ -30,10 +32,10 @@ module Decorators
3032
pact_created_at: pact_created_at,
3133
provider_version_number: nil,
3234
provider_name: "Provider",
33-
success: nil,
35+
success: line_2_success,
3436
number: nil,
3537
build_url: nil,
36-
verification_executed_at: nil
38+
verification_executed_at: verification_date
3739
}
3840
end
3941

@@ -114,14 +116,18 @@ module Decorators
114116
end
115117

116118
it "includes a summary" do
117-
expect(parsed_json[:summary][:deployable]).to eq false
119+
expect(parsed_json[:summary][:deployable]).to eq true
120+
expect(parsed_json[:summary][:reason]).to match /All verification results are published/
118121
end
119122

120123
context "when the pact has not been verified" do
121-
let(:verification_hash) do
122-
nil
124+
before do
125+
line_2[:success] = nil
126+
line_2[:verification_executed_at] = nil
123127
end
124128

129+
let(:verification_hash) { nil }
130+
125131
it "has empty provider details" do
126132
expect(parsed_json[:matrix][1][:provider]).to eq provider_hash.merge(version: nil)
127133
end
@@ -130,6 +136,30 @@ module Decorators
130136
expect(parsed_json[:matrix][1][:verificationResult]).to eq verification_hash
131137
end
132138
end
139+
140+
context "when one or more successes are nil" do
141+
let(:line_1_success) { nil }
142+
143+
it "has a deployable flag of nil" do
144+
expect(parsed_json[:summary][:deployable]).to be nil
145+
end
146+
147+
it "has an explanation" do
148+
expect(parsed_json[:summary][:reason]).to match /Missing/
149+
end
150+
end
151+
152+
context "when one or more successes are false" do
153+
let(:line_1_success) { false }
154+
155+
it "has a deployable flag of false" do
156+
expect(parsed_json[:summary][:deployable]).to be false
157+
end
158+
159+
it "has an explanation" do
160+
expect(parsed_json[:summary][:reason]).to match /have failed/
161+
end
162+
end
133163
end
134164
end
135165
end

0 commit comments

Comments
 (0)