@@ -16,10 +16,10 @@ module Resources
16
16
allow ( PactBroker ::Verifications ::Status ) . to receive ( :new ) . and_return ( verification_status )
17
17
end
18
18
19
- let ( :pact ) { instance_double ( "PactBroker::Domain::Pact" , consumer : consumer , provider : provider ) }
19
+ let ( :pact ) { instance_double ( "PactBroker::Domain::Pact" , consumer : consumer , provider : provider , consumer_version_number : "2" ) }
20
20
let ( :consumer ) { double ( 'consumer' ) }
21
21
let ( :provider ) { double ( 'provider' ) }
22
- let ( :verification ) { double ( "verification" ) }
22
+ let ( :verification ) { double ( "verification" , provider_version_number : "3" ) }
23
23
let ( :verification_status ) { instance_double ( "PactBroker::Verifications::Status" , to_sym : :verified ) }
24
24
25
25
@@ -82,7 +82,11 @@ module Resources
82
82
end
83
83
84
84
it "returns the badge" do
85
- expect ( subject . body ) . to eq "badge"
85
+ expect ( subject . body ) . to end_with "badge"
86
+ end
87
+
88
+ it "returns a comment with the consumer and provider numbers" do
89
+ expect ( subject . body ) . to include "<!-- consumer version 2 provider version 3 -->"
86
90
end
87
91
88
92
context "when the label param is specified" do
@@ -127,55 +131,35 @@ module Resources
127
131
end
128
132
129
133
let ( :path ) { "/matrix/provider/provider/latest/master/consumer/consumer/latest/prod/badge" }
130
- let ( :row ) { { verification_id : 1 } }
134
+ let ( :row ) { { consumer_name : 'consumer' , provider_name : 'provider' } }
131
135
132
-
133
- it "looks up the matrix row" do
134
- expect ( PactBroker ::Matrix ::Service ) . to receive ( :find_for_consumer_and_provider_with_tags ) . with (
135
- hash_including ( consumer_name : 'consumer' ,
136
- provider_name : 'provider' ,
137
- tag : 'prod' ,
138
- provider_tag : 'master'
139
- ) )
136
+ it "looks up the verification" do
137
+ expect ( PactBroker ::Verifications ::Service ) . to receive ( :find_latest_verification_for_tags ) do | consumer , provider , tag |
138
+ expect ( consumer . name ) . to eq 'consumer'
139
+ expect ( provider . name ) . to eq 'provider'
140
+ expect ( tag ) . to eq 'prod'
141
+ end
140
142
subject
141
143
end
142
144
143
- context "when a matrix row is found" do
144
- context "when there is a verification_id" do
145
- it "looks up the verification" do
146
- expect ( PactBroker ::Verifications ::Service ) . to receive ( :find_by_id ) . with ( 1 )
147
- subject
148
- end
149
145
150
- it "returns the badge " do
151
- expect ( subject . body ) . to eq "badge"
152
- end
146
+ context "when a verification is found " do
147
+ before do
148
+ allow ( PactBroker :: Verifications :: Service ) . to receive ( :find_latest_verification_for_tags ) . and_return ( verification )
153
149
end
154
150
155
- context "when there is not a verification_id" do
156
- let ( :row ) { { } }
157
-
158
- it "does not look up the verification" do
159
- expect ( PactBroker ::Verifications ::Service ) . to_not receive ( :find_by_id )
160
- subject
161
- end
162
-
163
- it "returns the badge" do
164
- expect ( subject . body ) . to eq "badge"
165
- end
151
+ it "returns the badge" do
152
+ expect ( subject . body ) . to end_with "badge"
166
153
end
167
154
end
168
155
169
- context "when a matrix row is not found" do
170
- let ( :row ) { nil }
171
-
172
- it "does not look up the verification" do
173
- expect ( PactBroker ::Verifications ::Service ) . to_not receive ( :find_by_id )
174
- subject
156
+ context "when a verification is not found" do
157
+ before do
158
+ allow ( PactBroker ::Verifications ::Service ) . to receive ( :find_latest_verification_for_tags ) . and_return ( nil )
175
159
end
176
160
177
161
it "returns the badge" do
178
- expect ( subject . body ) . to eq "badge"
162
+ expect ( subject . body ) . to end_with "badge"
179
163
end
180
164
end
181
165
end
0 commit comments