File tree 5 files changed +75
-8
lines changed
5 files changed +75
-8
lines changed Original file line number Diff line number Diff line change 5
5
module PactBroker
6
6
module Api
7
7
module Resources
8
-
9
8
class Dashboard < BaseResource
10
-
11
9
def content_types_provided
12
10
[
13
11
[ "application/hal+json" , :to_json ] ,
@@ -30,7 +28,7 @@ def to_text
30
28
private
31
29
32
30
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 ) )
34
32
end
35
33
end
36
34
end
Original file line number Diff line number Diff line change @@ -35,14 +35,29 @@ def self.find_index_items options = {}
35
35
end
36
36
rows = rows . all . group_by ( &:pact_publication_id ) . values . collect { | rows | Matrix ::AggregatedRow . new ( rows ) }
37
37
38
+
39
+
38
40
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
+
39
54
# TODO simplify. Do we really need 3 layers of abstraction?
40
55
PactBroker ::Domain ::IndexItem . create (
41
56
row . consumer ,
42
57
row . provider ,
43
58
row . pact ,
44
59
row . overall_latest? ,
45
- row . latest_verification_for_pseudo_branch ,
60
+ latest_verification ,
46
61
row . webhooks ,
47
62
row . latest_triggered_webhooks ,
48
63
options [ :tags ] ? row . consumer_head_tag_names : [ ] ,
Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ def latest_verification_for_pseudo_branch
43
43
end
44
44
end
45
45
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
+
46
54
# The list of tag names for which this pact publication is the most recent with that tag
47
55
# There could, however, be a later consumer version that does't have a pact (perhaps because it was deleted)
48
56
# that has the same tag.
Original file line number Diff line number Diff line change @@ -233,10 +233,35 @@ module Index
233
233
234
234
let ( :options ) { { tags : true } }
235
235
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
240
265
end
241
266
end
242
267
end
Original file line number Diff line number Diff line change @@ -74,6 +74,27 @@ module Matrix
74
74
end
75
75
end
76
76
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
77
98
end
78
99
end
79
100
end
You can’t perform that action at this time.
0 commit comments