@@ -11,6 +11,9 @@ module Domain
11
11
allow ( PactBroker . logger ) . to receive ( :info ) . and_call_original
12
12
allow ( PactBroker . logger ) . to receive ( :debug ) . and_call_original
13
13
allow ( PactBroker . logger ) . to receive ( :warn ) . and_call_original
14
+ allow ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) do | content , pact , verification , &block |
15
+ content
16
+ end
14
17
end
15
18
16
19
let ( :username ) { nil }
@@ -57,51 +60,37 @@ module Domain
57
60
describe "execute" do
58
61
let! ( :http_request ) do
59
62
stub_request ( :post , "http://example.org/hook" ) .
60
- with ( :headers => { 'Content-Type' => 'text/plain' } , :body => 'body' ) .
63
+ with ( :headers => { 'Content-Type' => 'text/plain' } , :body => request_body ) .
61
64
to_return ( :status => 200 , :body => "respbod" , :headers => { 'Content-Type' => 'text/foo, blah' } )
62
65
end
63
66
64
- describe "when the String body contains a ${pactbroker.pactUrl} parameter" do
65
- let! ( :http_request ) do
66
- stub_request ( :post , "http://example.org/hook" ) .
67
- with ( :headers => { 'Content-Type' => 'text/plain' } , :body => "<xml><url>http://example.org/pact-url</url></xml>" ) .
68
- to_return ( :status => 200 )
69
- end
70
-
71
- let ( :body ) { "<xml><url>${pactbroker.pactUrl}</url></xml>" }
67
+ let ( :request_body ) { 'body' }
72
68
73
- it "replaces the token with the live value" do
74
- subject . execute ( pact , options )
75
- expect ( http_request ) . to have_been_made
69
+ it "renders the url template" do
70
+ expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( "http://example.org/hook" , pact ) do | content , pact , verification , &block |
71
+ expect ( content ) . to eq "http://example.org/hook"
72
+ expect ( pact ) . to be pact
73
+ expect ( verification ) . to be nil
74
+ expect ( block . call ( "foo bar" ) ) . to eq "foo+bar"
75
+ "http://example.org/hook"
76
76
end
77
+ subject . execute ( pact , options )
77
78
end
78
79
79
- describe "when the JSON body contains a ${pactbroker.pactUrl} parameter" do
80
- let! ( :http_request ) do
81
- stub_request ( :post , "http://example.org/hook" ) .
82
- with ( :headers => { 'Content-Type' => 'text/plain' } , :body => '{"url":"http://example.org/pact-url"}' ) .
83
- to_return ( :status => 200 )
84
- end
85
-
86
- let ( :body ) { { url : '${pactbroker.pactUrl}' } }
87
-
88
- it "replaces the token with the live value" do
80
+ context "when the body is a string" do
81
+ it "renders the body template with the String" do
82
+ expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( 'body' , pact )
89
83
subject . execute ( pact , options )
90
- expect ( http_request ) . to have_been_made
91
84
end
92
85
end
93
86
94
- describe "when the URL contains a ${pactbroker.pactUrl} parameter" do
95
- let! ( :http_request ) do
96
- stub_request ( :post , "http://example.org/hook?url=http%3A%2F%2Fexample.org%2Fpact-url" ) .
97
- to_return ( :status => 200 )
98
- end
99
-
100
- let ( :url ) { 'http://example.org/hook?url=${pactbroker.pactUrl}' }
87
+ context "when the body is an object" do
88
+ let ( :body ) { { "foo" => "bar" } }
89
+ let ( :request_body ) { '{"foo":"bar"}' }
101
90
102
- it "replaces the token with the live value" do
91
+ it "renders the body template with JSON" do
92
+ expect ( PactBroker ::Webhooks ::Render ) . to receive ( :call ) . with ( request_body , pact )
103
93
subject . execute ( pact , options )
104
- expect ( http_request ) . to have_been_made
105
94
end
106
95
end
107
96
@@ -234,21 +223,6 @@ module Domain
234
223
end
235
224
end
236
225
237
- context "when the request has a JSONable body" do
238
- let ( :body ) { [ { "some" : "json" } ] }
239
-
240
- let! ( :http_request ) do
241
- stub_request ( :post , "http://example.org/hook" ) .
242
- with ( :headers => { 'Content-Type' => 'text/plain' } , :body => body . to_json ) .
243
- to_return ( :status => 200 , :body => "respbod" , :headers => { 'Content-Type' => 'text/foo, blah' } )
244
- end
245
-
246
- it "converts the body to JSON before submitting the request" do
247
- subject . execute ( pact , options )
248
- expect ( http_request ) . to have_been_made
249
- end
250
- end
251
-
252
226
context "when the request has a nil body" do
253
227
let ( :body ) { nil }
254
228
@@ -275,7 +249,6 @@ module Domain
275
249
end
276
250
277
251
context "when the request is not successful" do
278
-
279
252
let! ( :http_request ) do
280
253
stub_request ( :post , "http://example.org/hook" ) .
281
254
with ( :headers => { 'Content-Type' => 'text/plain' } , :body => 'body' ) .
0 commit comments