@@ -14,6 +14,7 @@ module Domain
14
14
let ( :body ) { 'body' }
15
15
let ( :logs ) { StringIO . new }
16
16
let ( :execution_logger ) { Logger . new ( logs ) }
17
+ let ( :options ) { { failure_log_message : 'oops' } }
17
18
18
19
subject do
19
20
WebhookRequest . new (
@@ -25,6 +26,8 @@ module Domain
25
26
body : body )
26
27
end
27
28
29
+ let ( :logs ) { subject . execute ( options ) . logs }
30
+
28
31
describe "description" do
29
32
it "returns a brief description of the HTTP request" do
30
33
expect ( subject . description ) . to eq 'POST example.org'
@@ -54,28 +57,26 @@ module Domain
54
57
end
55
58
56
59
it "executes the configured request" do
57
- subject . execute
60
+ subject . execute ( options )
58
61
expect ( http_request ) . to have_been_made
59
62
end
60
63
61
64
it "logs the request" do
62
65
allow ( PactBroker . logger ) . to receive ( :info )
63
66
expect ( PactBroker . logger ) . to receive ( :info ) . with ( /POST.*example.*text.*body/ )
64
- subject . execute
67
+ subject . execute ( options )
65
68
end
66
69
67
70
it "logs the response" do
68
71
allow ( PactBroker . logger ) . to receive ( :info )
69
72
allow ( PactBroker . logger ) . to receive ( :debug )
70
73
expect ( PactBroker . logger ) . to receive ( :info ) . with ( /response.*302/ )
71
74
expect ( PactBroker . logger ) . to receive ( :debug ) . with ( /respbod/ )
72
- subject . execute
75
+ subject . execute ( options )
73
76
end
74
77
75
78
describe "execution logs" do
76
79
77
- let ( :logs ) { subject . execute . logs }
78
-
79
80
it "logs the request method and path" do
80
81
expect ( logs ) . to include "POST http://example.org/hook"
81
82
end
@@ -104,6 +105,20 @@ module Domain
104
105
expect ( logs ) . to include "respbod"
105
106
end
106
107
108
+ context "when the response code is a success" do
109
+ it "does not log the failure_log_message" do
110
+ allow_any_instance_of ( WebhookExecutionResult ) . to receive ( :success? ) . and_return ( true )
111
+ expect ( logs ) . to_not include "oops"
112
+ end
113
+ end
114
+
115
+ context "when the response code is not successful" do
116
+ it "logs the failure_log_message" do
117
+ allow_any_instance_of ( WebhookExecutionResult ) . to receive ( :success? ) . and_return ( false )
118
+ expect ( logs ) . to include "oops"
119
+ end
120
+ end
121
+
107
122
context "with basic auth" do
108
123
let ( :username ) { 'username' }
109
124
let ( :password ) { 'password' }
@@ -129,7 +144,7 @@ module Domain
129
144
end
130
145
131
146
it "uses the credentials" do
132
- subject . execute
147
+ subject . execute ( options )
133
148
expect ( http_request_with_basic_auth ) . to have_been_made
134
149
end
135
150
end
@@ -145,7 +160,7 @@ module Domain
145
160
end
146
161
147
162
it "uses SSL" do
148
- subject . execute
163
+ subject . execute ( options )
149
164
expect ( https_request ) . to have_been_made
150
165
end
151
166
end
@@ -160,7 +175,7 @@ module Domain
160
175
end
161
176
162
177
it "converts the body to JSON before submitting the request" do
163
- subject . execute
178
+ subject . execute ( options )
164
179
expect ( http_request ) . to have_been_made
165
180
end
166
181
end
@@ -175,18 +190,18 @@ module Domain
175
190
end
176
191
177
192
it "executes the request without a body" do
178
- subject . execute
193
+ subject . execute ( options )
179
194
expect ( http_request ) . to have_been_made
180
195
end
181
196
end
182
197
183
198
context "when the request is successful" do
184
199
it "returns a WebhookExecutionResult with success=true" do
185
- expect ( subject . execute . success? ) . to be true
200
+ expect ( subject . execute ( options ) . success? ) . to be true
186
201
end
187
202
188
203
it "sets the response on the result" do
189
- expect ( subject . execute . response ) . to be_instance_of ( Net ::HTTPFound )
204
+ expect ( subject . execute ( options ) . response ) . to be_instance_of ( Net ::HTTPFound )
190
205
end
191
206
end
192
207
@@ -199,11 +214,11 @@ module Domain
199
214
end
200
215
201
216
it "returns a WebhookExecutionResult with success=false" do
202
- expect ( subject . execute . success? ) . to be false
217
+ expect ( subject . execute ( options ) . success? ) . to be false
203
218
end
204
219
205
220
it "sets the response on the result" do
206
- expect ( subject . execute . response ) . to be_instance_of ( Net ::HTTPInternalServerError )
221
+ expect ( subject . execute ( options ) . response ) . to be_instance_of ( Net ::HTTPInternalServerError )
207
222
end
208
223
end
209
224
@@ -218,22 +233,22 @@ class WebhookTestError < StandardError; end
218
233
it "logs the error" do
219
234
allow ( PactBroker . logger ) . to receive ( :error )
220
235
expect ( PactBroker . logger ) . to receive ( :error ) . with ( /Error.*WebhookTestError.*blah/ )
221
- subject . execute
236
+ subject . execute ( options )
222
237
end
223
238
224
239
it "returns a WebhookExecutionResult with success=false" do
225
- expect ( subject . execute . success? ) . to be false
240
+ expect ( subject . execute ( options ) . success? ) . to be false
226
241
end
227
242
228
243
it "returns a WebhookExecutionResult with an error" do
229
- expect ( subject . execute . error ) . to be_instance_of WebhookTestError
244
+ expect ( subject . execute ( options ) . error ) . to be_instance_of WebhookTestError
230
245
end
231
- end
232
246
247
+ it "logs the failure_log_message" do
248
+ expect ( logs ) . to include "oops"
249
+ end
250
+ end
233
251
end
234
-
235
252
end
236
-
237
253
end
238
-
239
254
end
0 commit comments