Skip to content

Commit e173f5c

Browse files
committed
feat: remove use of 'stale' for dashboard resource
1 parent 6e67d3a commit e173f5c

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

lib/pact_broker/api/resources/dashboard.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
module PactBroker
66
module Api
77
module Resources
8-
98
class Dashboard < BaseResource
10-
119
def content_types_provided
1210
[
1311
["application/hal+json", :to_json],
@@ -30,7 +28,7 @@ def to_text
3028
private
3129

3230
def index_items
33-
index_service.find_index_items(identifier_from_path.merge(tags: true))
31+
index_service.find_index_items(identifier_from_path.merge(tags: true, dashboard: true))
3432
end
3533
end
3634
end

lib/pact_broker/index/service.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,29 @@ def self.find_index_items options = {}
3535
end
3636
rows = rows.all.group_by(&:pact_publication_id).values.collect{ | rows| Matrix::AggregatedRow.new(rows) }
3737

38+
39+
3840
rows.sort.collect do | row |
41+
# The concept of "stale" (the pact used to be verified but then it changed and we haven't got
42+
# a new verification result yet) only really make sense if we're trying to summarise
43+
# the latest state of an integration. Once we start showing multiple pacts for each
44+
# integration (ie. the latest for each tag) then each pact version is either verified,
45+
# or it's not verified.
46+
# For backwards compatiblity with the existing UI, don't change the 'stale' concept for the OSS
47+
# UI - just ensure we don't use it for the new dashboard endpoint with the consumer/provider specified.
48+
latest_verification = if options[:dashboard]
49+
row.latest_verification_for_pact_version
50+
else
51+
row.latest_verification_for_pseudo_branch
52+
end
53+
3954
# TODO simplify. Do we really need 3 layers of abstraction?
4055
PactBroker::Domain::IndexItem.create(
4156
row.consumer,
4257
row.provider,
4358
row.pact,
4459
row.overall_latest?,
45-
row.latest_verification_for_pseudo_branch,
60+
latest_verification,
4661
row.webhooks,
4762
row.latest_triggered_webhooks,
4863
options[:tags] ? row.consumer_head_tag_names : [],

lib/pact_broker/matrix/aggregated_row.rb

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def latest_verification_for_pseudo_branch
4343
end
4444
end
4545

46+
def latest_verification_for_pact_version
47+
@latest_verificaton_for_pact_version ||= begin
48+
matrix_rows.collect do | row|
49+
row.verification
50+
end.compact.sort{ |v1, v2| v1.id <=> v2.id }.last
51+
end
52+
end
53+
4654
# The list of tag names for which this pact publication is the most recent with that tag
4755
# There could, however, be a later consumer version that does't have a pact (perhaps because it was deleted)
4856
# that has the same tag.

spec/lib/pact_broker/index/service_spec.rb

+29-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,35 @@ module Index
233233

234234
let(:options) { { tags: true } }
235235

236-
it "returns the latest of the feat-x and feat-y verifications" do
237-
expect(rows.last.consumer_version_number).to eq "3"
238-
expect(rows.last.tag_names.sort).to eq ["feat-x", "feat-y"]
239-
expect(rows.last.provider_version_number).to eq "2"
236+
context "with tags=true" do
237+
it "returns the tags for the pacts" do
238+
expect(rows.last.tag_names.sort).to eq ["feat-x", "feat-y"]
239+
end
240+
end
241+
242+
context "with tags=false" do
243+
let(:options) { { tags: false } }
244+
245+
it "does not return the tags for the pacts" do
246+
expect(rows.last.tag_names.sort).to eq []
247+
end
248+
end
249+
250+
context "with dashboard=true" do
251+
let(:options) { { dashboard: true } }
252+
253+
it "returns the latest verification as nil as the pact version itself has not been verified" do
254+
expect(rows.last.provider_version_number).to be nil
255+
end
256+
end
257+
258+
context "with dashboard=false" do
259+
let(:options) { { } }
260+
261+
it "returns the latest of the feat-x and feat-y verifications because we are summarising the entire integration (backwards compat for OSS index)" do
262+
expect(rows.last.consumer_version_number).to eq "4"
263+
expect(rows.last.provider_version_number).to eq "2"
264+
end
240265
end
241266
end
242267
end

spec/lib/pact_broker/matrix/aggregated_row_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ module Matrix
7474
end
7575
end
7676
end
77+
78+
describe "latest_verification_for_pact_version" do
79+
let(:row_1) do
80+
instance_double('PactBroker::Matrix::HeadRow',
81+
verification: verification_1)
82+
end
83+
let(:row_2) do
84+
instance_double('PactBroker::Matrix::HeadRow',
85+
verification: verification_2)
86+
end
87+
let(:verification_1) { instance_double('PactBroker::Domain::Verification', id: 2) }
88+
let(:verification_2) { instance_double('PactBroker::Domain::Verification', id: 1) }
89+
let(:rows) { [row_1, row_2] }
90+
let(:aggregated_row) { AggregatedRow.new(rows) }
91+
92+
subject { aggregated_row.latest_verification_for_pact_version }
93+
94+
it "returns the verification with the largest id" do
95+
expect(subject.id).to eq 2
96+
end
97+
end
7798
end
7899
end
79100
end

0 commit comments

Comments
 (0)