@@ -22,6 +22,8 @@ module Domain
22
22
let ( :options ) { { failure_log_message : 'oops' , show_response : show_response } }
23
23
let ( :show_response ) { true }
24
24
let ( :pact ) { instance_double ( 'PactBroker::Domain::Pact' ) }
25
+ let ( :verification ) { instance_double ( 'PactBroker::Domain::Verification' ) }
26
+ let ( :logs ) { execute . logs }
25
27
26
28
subject do
27
29
WebhookRequest . new (
@@ -33,7 +35,8 @@ module Domain
33
35
body : body )
34
36
end
35
37
36
- let ( :logs ) { subject . execute ( pact , options ) . logs }
38
+ let ( :execute ) { subject . execute ( pact , verification , options ) }
39
+
37
40
38
41
describe "description" do
39
42
it "returns a brief description of the HTTP request" do
@@ -65,20 +68,20 @@ module Domain
65
68
let ( :request_body ) { 'body' }
66
69
67
70
it "renders the url template" do
68
- expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( "http://example.org/hook" , pact ) do | content , pact , verification , &block |
71
+ expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( "http://example.org/hook" , pact , verification ) do | content , pact , verification , &block |
69
72
expect ( content ) . to eq "http://example.org/hook"
70
73
expect ( pact ) . to be pact
71
- expect ( verification ) . to be nil
74
+ expect ( verification ) . to be verification
72
75
expect ( block . call ( "foo bar" ) ) . to eq "foo+bar"
73
76
"http://example.org/hook"
74
77
end
75
- subject . execute ( pact , options )
78
+ execute
76
79
end
77
80
78
81
context "when the body is a string" do
79
82
it "renders the body template with the String" do
80
- expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( 'body' , pact )
81
- subject . execute ( pact , options )
83
+ expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( 'body' , pact , verification )
84
+ execute
82
85
end
83
86
end
84
87
@@ -87,20 +90,20 @@ module Domain
87
90
let ( :request_body ) { '{"foo":"bar"}' }
88
91
89
92
it "renders the body template with JSON" do
90
- expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( request_body , pact )
91
- subject . execute ( pact , options )
93
+ expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( request_body , pact , verification )
94
+ execute
92
95
end
93
96
end
94
97
95
98
it "executes the configured request" do
96
- subject . execute ( pact , options )
99
+ execute
97
100
expect ( http_request ) . to have_been_made
98
101
end
99
102
100
103
it "logs the request" do
101
104
allow ( PactBroker . logger ) . to receive ( :info )
102
105
expect ( PactBroker . logger ) . to receive ( :info ) . with ( /POST.*example.*text.*body/ )
103
- subject . execute ( pact , options )
106
+ execute
104
107
end
105
108
106
109
it "logs the response" do
@@ -109,7 +112,7 @@ module Domain
109
112
expect ( PactBroker . logger ) . to receive ( :info ) . with ( /response.*200/ )
110
113
expect ( PactBroker . logger ) . to receive ( :debug ) . with ( /content-type/ )
111
114
expect ( PactBroker . logger ) . to receive ( :debug ) . with ( /respbod/ )
112
- subject . execute ( pact , options )
115
+ execute
113
116
end
114
117
115
118
describe "execution logs" do
@@ -204,7 +207,7 @@ module Domain
204
207
let ( :password ) { "password" }
205
208
206
209
it "uses the credentials" do
207
- subject . execute ( pact , options )
210
+ execute
208
211
expect ( http_request_with_basic_auth ) . to have_been_made
209
212
end
210
213
end
@@ -214,7 +217,7 @@ module Domain
214
217
let ( :password ) { "p@$$w0rd!" }
215
218
216
219
it "uses the credentials" do
217
- subject . execute ( pact , options )
220
+ execute
218
221
expect ( http_request_with_basic_auth ) . to have_been_made
219
222
end
220
223
end
@@ -231,7 +234,7 @@ module Domain
231
234
end
232
235
233
236
it "uses SSL" do
234
- subject . execute ( pact , options )
237
+ execute
235
238
expect ( https_request ) . to have_been_made
236
239
end
237
240
end
@@ -246,18 +249,18 @@ module Domain
246
249
end
247
250
248
251
it "executes the request without a body" do
249
- subject . execute ( pact , options )
252
+ execute
250
253
expect ( http_request ) . to have_been_made
251
254
end
252
255
end
253
256
254
257
context "when the request is successful" do
255
258
it "returns a WebhookExecutionResult with success=true" do
256
- expect ( subject . execute ( pact , options ) . success? ) . to be true
259
+ expect ( execute . success? ) . to be true
257
260
end
258
261
259
262
it "sets the response on the result" do
260
- expect ( subject . execute ( pact , options ) . response ) . to be_instance_of ( Net ::HTTPOK )
263
+ expect ( execute . response ) . to be_instance_of ( Net ::HTTPOK )
261
264
end
262
265
end
263
266
@@ -270,11 +273,11 @@ module Domain
270
273
end
271
274
272
275
it "returns a WebhookExecutionResult with success=false" do
273
- expect ( subject . execute ( pact , options ) . success? ) . to be false
276
+ expect ( execute . success? ) . to be false
274
277
end
275
278
276
279
it "sets the response on the result" do
277
- expect ( subject . execute ( pact , options ) . response ) . to be_instance_of ( Net ::HTTPInternalServerError )
280
+ expect ( execute . response ) . to be_instance_of ( Net ::HTTPInternalServerError )
278
281
end
279
282
end
280
283
@@ -285,15 +288,15 @@ module Domain
285
288
end
286
289
287
290
it "removes the non UTF-8 characters before saving the logs so they don't blow up the database" do
288
- result = subject . execute ( pact , options )
291
+ result = execute
289
292
expect ( result . logs ) . to include "This has some invalid chars"
290
293
end
291
294
292
295
it "logs that it has cleaned the string to the execution logger" do
293
296
logger = double ( "logger" ) . as_null_object
294
297
allow ( Logger ) . to receive ( :new ) . and_return ( logger )
295
298
expect ( logger ) . to receive ( :debug ) . with ( /Note that invalid UTF-8 byte sequences were removed/ )
296
- subject . execute ( pact , options )
299
+ execute
297
300
end
298
301
end
299
302
@@ -308,15 +311,15 @@ class WebhookTestError < StandardError; end
308
311
309
312
it "logs the error" do
310
313
expect ( PactBroker . logger ) . to receive ( :error ) . with ( /Error.*WebhookTestError.*blah/ )
311
- subject . execute ( pact , options )
314
+ execute
312
315
end
313
316
314
317
it "returns a WebhookExecutionResult with success=false" do
315
- expect ( subject . execute ( pact , options ) . success? ) . to be false
318
+ expect ( execute . success? ) . to be false
316
319
end
317
320
318
321
it "returns a WebhookExecutionResult with an error" do
319
- expect ( subject . execute ( pact , options ) . error ) . to be_instance_of WebhookTestError
322
+ expect ( execute . error ) . to be_instance_of WebhookTestError
320
323
end
321
324
322
325
it "logs the failure_log_message" do
0 commit comments