gocardless_pro 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,345 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::MandateImportEntriesService do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#create' do
13
+ subject(:post_create_response) { client.mandate_import_entries.create(params: new_resource) }
14
+ context 'with a valid request' do
15
+ let(:new_resource) do
16
+ {
17
+
18
+ 'created_at' => 'created_at-input',
19
+ 'links' => 'links-input',
20
+ 'record_identifier' => 'record_identifier-input',
21
+ }
22
+ end
23
+
24
+ before do
25
+ stub_request(:post, %r{.*api.gocardless.com/mandate_import_entries}).
26
+ with(
27
+ body: {
28
+ 'mandate_import_entries' => {
29
+
30
+ 'created_at' => 'created_at-input',
31
+ 'links' => 'links-input',
32
+ 'record_identifier' => 'record_identifier-input',
33
+ },
34
+ }
35
+ ).
36
+ to_return(
37
+ body: {
38
+ 'mandate_import_entries' =>
39
+
40
+ {
41
+
42
+ 'created_at' => 'created_at-input',
43
+ 'links' => 'links-input',
44
+ 'record_identifier' => 'record_identifier-input',
45
+ },
46
+
47
+ }.to_json,
48
+ headers: response_headers
49
+ )
50
+ end
51
+
52
+ it 'creates and returns the resource' do
53
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::MandateImportEntry)
54
+ end
55
+
56
+ describe 'retry behaviour' do
57
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
58
+
59
+ it 'retries timeouts' do
60
+ stub = stub_request(:post, %r{.*api.gocardless.com/mandate_import_entries}).
61
+ to_timeout.then.to_return(status: 200, headers: response_headers)
62
+
63
+ post_create_response
64
+ expect(stub).to have_been_requested.twice
65
+ end
66
+
67
+ it 'retries 5XX errors' do
68
+ stub = stub_request(:post, %r{.*api.gocardless.com/mandate_import_entries}).
69
+ to_return(status: 502,
70
+ headers: { 'Content-Type' => 'text/html' },
71
+ body: '<html><body>Response from Cloudflare</body></html>').
72
+ then.to_return(status: 200, headers: response_headers)
73
+
74
+ post_create_response
75
+ expect(stub).to have_been_requested.twice
76
+ end
77
+ end
78
+ end
79
+
80
+ context 'with a request that returns a validation error' do
81
+ let(:new_resource) { {} }
82
+
83
+ before do
84
+ stub_request(:post, %r{.*api.gocardless.com/mandate_import_entries}).to_return(
85
+ body: {
86
+ error: {
87
+ type: 'validation_failed',
88
+ code: 422,
89
+ errors: [
90
+ { message: 'test error message', field: 'test_field' },
91
+ ],
92
+ },
93
+ }.to_json,
94
+ headers: response_headers,
95
+ status: 422
96
+ )
97
+ end
98
+
99
+ it 'throws the correct error' do
100
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
101
+ end
102
+ end
103
+
104
+ context 'with a request that returns an idempotent creation conflict error' do
105
+ let(:id) { 'ID123' }
106
+
107
+ let(:new_resource) do
108
+ {
109
+
110
+ 'created_at' => 'created_at-input',
111
+ 'links' => 'links-input',
112
+ 'record_identifier' => 'record_identifier-input',
113
+ }
114
+ end
115
+
116
+ let!(:post_stub) do
117
+ stub_request(:post, %r{.*api.gocardless.com/mandate_import_entries}).to_return(
118
+ body: {
119
+ error: {
120
+ type: 'invalid_state',
121
+ code: 409,
122
+ errors: [
123
+ {
124
+ message: 'A resource has already been created with this idempotency key',
125
+ reason: 'idempotent_creation_conflict',
126
+ links: {
127
+ conflicting_resource_id: id,
128
+ },
129
+ },
130
+ ],
131
+ },
132
+ }.to_json,
133
+ headers: response_headers,
134
+ status: 409
135
+ )
136
+ end
137
+
138
+ it 'raises an InvalidStateError' do
139
+ expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
140
+ expect(post_stub).to have_been_requested
141
+ end
142
+ end
143
+ end
144
+
145
+ describe '#list' do
146
+ describe 'with no filters' do
147
+ subject(:get_list_response) { client.mandate_import_entries.list }
148
+
149
+ let(:body) do
150
+ {
151
+ 'mandate_import_entries' => [{
152
+
153
+ 'created_at' => 'created_at-input',
154
+ 'links' => 'links-input',
155
+ 'record_identifier' => 'record_identifier-input',
156
+ }],
157
+ meta: {
158
+ cursors: {
159
+ before: nil,
160
+ after: 'ABC123',
161
+ },
162
+ },
163
+ }.to_json
164
+ end
165
+
166
+ before do
167
+ stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries}).to_return(
168
+ body: body,
169
+ headers: response_headers
170
+ )
171
+ end
172
+
173
+ it 'wraps each item in the resource class' do
174
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::MandateImportEntry)
175
+
176
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
177
+
178
+ expect(get_list_response.records.first.record_identifier).to eq('record_identifier-input')
179
+ end
180
+
181
+ it 'exposes the cursors for before and after' do
182
+ expect(get_list_response.before).to eq(nil)
183
+ expect(get_list_response.after).to eq('ABC123')
184
+ end
185
+
186
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
187
+
188
+ describe 'retry behaviour' do
189
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
190
+
191
+ it 'retries timeouts' do
192
+ stub = stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries}).
193
+ to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
194
+
195
+ get_list_response
196
+ expect(stub).to have_been_requested.twice
197
+ end
198
+
199
+ it 'retries 5XX errors' do
200
+ stub = stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries}).
201
+ to_return(status: 502,
202
+ headers: { 'Content-Type' => 'text/html' },
203
+ body: '<html><body>Response from Cloudflare</body></html>').
204
+ then.to_return(status: 200, headers: response_headers, body: body)
205
+
206
+ get_list_response
207
+ expect(stub).to have_been_requested.twice
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ describe '#all' do
214
+ let!(:first_response_stub) do
215
+ stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries$}).to_return(
216
+ body: {
217
+ 'mandate_import_entries' => [{
218
+
219
+ 'created_at' => 'created_at-input',
220
+ 'links' => 'links-input',
221
+ 'record_identifier' => 'record_identifier-input',
222
+ }],
223
+ meta: {
224
+ cursors: { after: 'AB345' },
225
+ limit: 1,
226
+ },
227
+ }.to_json,
228
+ headers: response_headers
229
+ )
230
+ end
231
+
232
+ let!(:second_response_stub) do
233
+ stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries\?after=AB345}).to_return(
234
+ body: {
235
+ 'mandate_import_entries' => [{
236
+
237
+ 'created_at' => 'created_at-input',
238
+ 'links' => 'links-input',
239
+ 'record_identifier' => 'record_identifier-input',
240
+ }],
241
+ meta: {
242
+ limit: 2,
243
+ cursors: {},
244
+ },
245
+ }.to_json,
246
+ headers: response_headers
247
+ )
248
+ end
249
+
250
+ it 'automatically makes the extra requests' do
251
+ expect(client.mandate_import_entries.all.to_a.length).to eq(2)
252
+ expect(first_response_stub).to have_been_requested
253
+ expect(second_response_stub).to have_been_requested
254
+ end
255
+
256
+ describe 'retry behaviour' do
257
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
258
+
259
+ it 'retries timeouts' do
260
+ first_response_stub = stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries$}).to_return(
261
+ body: {
262
+ 'mandate_import_entries' => [{
263
+
264
+ 'created_at' => 'created_at-input',
265
+ 'links' => 'links-input',
266
+ 'record_identifier' => 'record_identifier-input',
267
+ }],
268
+ meta: {
269
+ cursors: { after: 'AB345' },
270
+ limit: 1,
271
+ },
272
+ }.to_json,
273
+ headers: response_headers
274
+ )
275
+
276
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries\?after=AB345}).
277
+ to_timeout.then.
278
+ to_return(
279
+ body: {
280
+ 'mandate_import_entries' => [{
281
+
282
+ 'created_at' => 'created_at-input',
283
+ 'links' => 'links-input',
284
+ 'record_identifier' => 'record_identifier-input',
285
+ }],
286
+ meta: {
287
+ limit: 2,
288
+ cursors: {},
289
+ },
290
+ }.to_json,
291
+ headers: response_headers
292
+ )
293
+
294
+ client.mandate_import_entries.all.to_a
295
+
296
+ expect(first_response_stub).to have_been_requested
297
+ expect(second_response_stub).to have_been_requested.twice
298
+ end
299
+
300
+ it 'retries 5XX errors' do
301
+ first_response_stub = stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries$}).to_return(
302
+ body: {
303
+ 'mandate_import_entries' => [{
304
+
305
+ 'created_at' => 'created_at-input',
306
+ 'links' => 'links-input',
307
+ 'record_identifier' => 'record_identifier-input',
308
+ }],
309
+ meta: {
310
+ cursors: { after: 'AB345' },
311
+ limit: 1,
312
+ },
313
+ }.to_json,
314
+ headers: response_headers
315
+ )
316
+
317
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/mandate_import_entries\?after=AB345}).
318
+ to_return(
319
+ status: 502,
320
+ body: '<html><body>Response from Cloudflare</body></html>',
321
+ headers: { 'Content-Type' => 'text/html' }
322
+ ).then.to_return(
323
+ body: {
324
+ 'mandate_import_entries' => [{
325
+
326
+ 'created_at' => 'created_at-input',
327
+ 'links' => 'links-input',
328
+ 'record_identifier' => 'record_identifier-input',
329
+ }],
330
+ meta: {
331
+ limit: 2,
332
+ cursors: {},
333
+ },
334
+ }.to_json,
335
+ headers: response_headers
336
+ )
337
+
338
+ client.mandate_import_entries.all.to_a
339
+
340
+ expect(first_response_stub).to have_been_requested
341
+ expect(second_response_stub).to have_been_requested.twice
342
+ end
343
+ end
344
+ end
345
+ end
@@ -0,0 +1,412 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::MandateImportsService do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#create' do
13
+ subject(:post_create_response) { client.mandate_imports.create(params: new_resource) }
14
+ context 'with a valid request' do
15
+ let(:new_resource) do
16
+ {
17
+
18
+ 'created_at' => 'created_at-input',
19
+ 'id' => 'id-input',
20
+ 'scheme' => 'scheme-input',
21
+ 'status' => 'status-input',
22
+ }
23
+ end
24
+
25
+ before do
26
+ stub_request(:post, %r{.*api.gocardless.com/mandate_imports}).
27
+ with(
28
+ body: {
29
+ 'mandate_imports' => {
30
+
31
+ 'created_at' => 'created_at-input',
32
+ 'id' => 'id-input',
33
+ 'scheme' => 'scheme-input',
34
+ 'status' => 'status-input',
35
+ },
36
+ }
37
+ ).
38
+ to_return(
39
+ body: {
40
+ 'mandate_imports' =>
41
+
42
+ {
43
+
44
+ 'created_at' => 'created_at-input',
45
+ 'id' => 'id-input',
46
+ 'scheme' => 'scheme-input',
47
+ 'status' => 'status-input',
48
+ },
49
+
50
+ }.to_json,
51
+ headers: response_headers
52
+ )
53
+ end
54
+
55
+ it 'creates and returns the resource' do
56
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::MandateImport)
57
+ end
58
+
59
+ describe 'retry behaviour' do
60
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
61
+
62
+ it 'retries timeouts' do
63
+ stub = stub_request(:post, %r{.*api.gocardless.com/mandate_imports}).
64
+ to_timeout.then.to_return(status: 200, headers: response_headers)
65
+
66
+ post_create_response
67
+ expect(stub).to have_been_requested.twice
68
+ end
69
+
70
+ it 'retries 5XX errors' do
71
+ stub = stub_request(:post, %r{.*api.gocardless.com/mandate_imports}).
72
+ to_return(status: 502,
73
+ headers: { 'Content-Type' => 'text/html' },
74
+ body: '<html><body>Response from Cloudflare</body></html>').
75
+ then.to_return(status: 200, headers: response_headers)
76
+
77
+ post_create_response
78
+ expect(stub).to have_been_requested.twice
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'with a request that returns a validation error' do
84
+ let(:new_resource) { {} }
85
+
86
+ before do
87
+ stub_request(:post, %r{.*api.gocardless.com/mandate_imports}).to_return(
88
+ body: {
89
+ error: {
90
+ type: 'validation_failed',
91
+ code: 422,
92
+ errors: [
93
+ { message: 'test error message', field: 'test_field' },
94
+ ],
95
+ },
96
+ }.to_json,
97
+ headers: response_headers,
98
+ status: 422
99
+ )
100
+ end
101
+
102
+ it 'throws the correct error' do
103
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
104
+ end
105
+ end
106
+
107
+ context 'with a request that returns an idempotent creation conflict error' do
108
+ let(:id) { 'ID123' }
109
+
110
+ let(:new_resource) do
111
+ {
112
+
113
+ 'created_at' => 'created_at-input',
114
+ 'id' => 'id-input',
115
+ 'scheme' => 'scheme-input',
116
+ 'status' => 'status-input',
117
+ }
118
+ end
119
+
120
+ let!(:post_stub) do
121
+ stub_request(:post, %r{.*api.gocardless.com/mandate_imports}).to_return(
122
+ body: {
123
+ error: {
124
+ type: 'invalid_state',
125
+ code: 409,
126
+ errors: [
127
+ {
128
+ message: 'A resource has already been created with this idempotency key',
129
+ reason: 'idempotent_creation_conflict',
130
+ links: {
131
+ conflicting_resource_id: id,
132
+ },
133
+ },
134
+ ],
135
+ },
136
+ }.to_json,
137
+ headers: response_headers,
138
+ status: 409
139
+ )
140
+ end
141
+
142
+ let!(:get_stub) do
143
+ stub_url = "/mandate_imports/#{id}"
144
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
145
+ to_return(
146
+ body: {
147
+ 'mandate_imports' => {
148
+
149
+ 'created_at' => 'created_at-input',
150
+ 'id' => 'id-input',
151
+ 'scheme' => 'scheme-input',
152
+ 'status' => 'status-input',
153
+ },
154
+ }.to_json,
155
+ headers: response_headers
156
+ )
157
+ end
158
+
159
+ it 'fetches the already-created resource' do
160
+ post_create_response
161
+ expect(post_stub).to have_been_requested
162
+ expect(get_stub).to have_been_requested
163
+ end
164
+ end
165
+ end
166
+
167
+ describe '#get' do
168
+ let(:id) { 'ID123' }
169
+
170
+ subject(:get_response) { client.mandate_imports.get(id) }
171
+
172
+ context 'passing in a custom header' do
173
+ let!(:stub) do
174
+ stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
175
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
176
+ with(headers: { 'Foo' => 'Bar' }).
177
+ to_return(
178
+ body: {
179
+ 'mandate_imports' => {
180
+
181
+ 'created_at' => 'created_at-input',
182
+ 'id' => 'id-input',
183
+ 'scheme' => 'scheme-input',
184
+ 'status' => 'status-input',
185
+ },
186
+ }.to_json,
187
+ headers: response_headers
188
+ )
189
+ end
190
+
191
+ subject(:get_response) do
192
+ client.mandate_imports.get(id, headers: {
193
+ 'Foo' => 'Bar',
194
+ })
195
+ end
196
+
197
+ it 'includes the header' do
198
+ get_response
199
+ expect(stub).to have_been_requested
200
+ end
201
+ end
202
+
203
+ context 'when there is a mandate_import to return' do
204
+ before do
205
+ stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
206
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
207
+ body: {
208
+ 'mandate_imports' => {
209
+
210
+ 'created_at' => 'created_at-input',
211
+ 'id' => 'id-input',
212
+ 'scheme' => 'scheme-input',
213
+ 'status' => 'status-input',
214
+ },
215
+ }.to_json,
216
+ headers: response_headers
217
+ )
218
+ end
219
+
220
+ it 'wraps the response in a resource' do
221
+ expect(get_response).to be_a(GoCardlessPro::Resources::MandateImport)
222
+ end
223
+ end
224
+
225
+ context 'when nothing is returned' do
226
+ before do
227
+ stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
228
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
229
+ body: '',
230
+ headers: response_headers
231
+ )
232
+ end
233
+
234
+ it 'returns nil' do
235
+ expect(get_response).to be_nil
236
+ end
237
+ end
238
+
239
+ context "when an ID is specified which can't be included in a valid URI" do
240
+ let(:id) { '`' }
241
+
242
+ it "doesn't raise an error" do
243
+ expect { get_response }.to_not raise_error(/bad URI/)
244
+ end
245
+ end
246
+
247
+ describe 'retry behaviour' do
248
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
249
+
250
+ it 'retries timeouts' do
251
+ stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
252
+
253
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
254
+ to_timeout.then.to_return(status: 200, headers: response_headers)
255
+
256
+ get_response
257
+ expect(stub).to have_been_requested.twice
258
+ end
259
+
260
+ it 'retries 5XX errors' do
261
+ stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
262
+
263
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
264
+ to_return(status: 502,
265
+ headers: { 'Content-Type' => 'text/html' },
266
+ body: '<html><body>Response from Cloudflare</body></html>').
267
+ then.to_return(status: 200, headers: response_headers)
268
+
269
+ get_response
270
+ expect(stub).to have_been_requested.twice
271
+ end
272
+ end
273
+ end
274
+
275
+ describe '#submit' do
276
+ subject(:post_response) { client.mandate_imports.submit(resource_id) }
277
+
278
+ let(:resource_id) { 'ABC123' }
279
+
280
+ let!(:stub) do
281
+ # /mandate_imports/%v/actions/submit
282
+ stub_url = '/mandate_imports/:identity/actions/submit'.gsub(':identity', resource_id)
283
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
284
+ body: {
285
+ 'mandate_imports' => {
286
+
287
+ 'created_at' => 'created_at-input',
288
+ 'id' => 'id-input',
289
+ 'scheme' => 'scheme-input',
290
+ 'status' => 'status-input',
291
+ },
292
+ }.to_json,
293
+ headers: response_headers
294
+ )
295
+ end
296
+
297
+ it 'wraps the response and calls the right endpoint' do
298
+ expect(post_response).to be_a(GoCardlessPro::Resources::MandateImport)
299
+
300
+ expect(stub).to have_been_requested
301
+ end
302
+
303
+ describe 'retry behaviour' do
304
+ it "doesn't retry errors" do
305
+ stub_url = '/mandate_imports/:identity/actions/submit'.gsub(':identity', resource_id)
306
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
307
+ to_timeout
308
+
309
+ expect { post_response }.to raise_error(Faraday::TimeoutError)
310
+ expect(stub).to have_been_requested
311
+ end
312
+ end
313
+
314
+ context 'when the request needs a body and custom header' do
315
+ let(:body) { { foo: 'bar' } }
316
+ let(:headers) { { 'Foo' => 'Bar' } }
317
+ subject(:post_response) { client.mandate_imports.submit(resource_id, body, headers) }
318
+
319
+ let(:resource_id) { 'ABC123' }
320
+
321
+ let!(:stub) do
322
+ # /mandate_imports/%v/actions/submit
323
+ stub_url = '/mandate_imports/:identity/actions/submit'.gsub(':identity', resource_id)
324
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
325
+ with(
326
+ body: { foo: 'bar' },
327
+ headers: { 'Foo' => 'Bar' }
328
+ ).to_return(
329
+ body: {
330
+ 'mandate_imports' => {
331
+
332
+ 'created_at' => 'created_at-input',
333
+ 'id' => 'id-input',
334
+ 'scheme' => 'scheme-input',
335
+ 'status' => 'status-input',
336
+ },
337
+ }.to_json,
338
+ headers: response_headers
339
+ )
340
+ end
341
+ end
342
+ end
343
+
344
+ describe '#cancel' do
345
+ subject(:post_response) { client.mandate_imports.cancel(resource_id) }
346
+
347
+ let(:resource_id) { 'ABC123' }
348
+
349
+ let!(:stub) do
350
+ # /mandate_imports/%v/actions/cancel
351
+ stub_url = '/mandate_imports/:identity/actions/cancel'.gsub(':identity', resource_id)
352
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
353
+ body: {
354
+ 'mandate_imports' => {
355
+
356
+ 'created_at' => 'created_at-input',
357
+ 'id' => 'id-input',
358
+ 'scheme' => 'scheme-input',
359
+ 'status' => 'status-input',
360
+ },
361
+ }.to_json,
362
+ headers: response_headers
363
+ )
364
+ end
365
+
366
+ it 'wraps the response and calls the right endpoint' do
367
+ expect(post_response).to be_a(GoCardlessPro::Resources::MandateImport)
368
+
369
+ expect(stub).to have_been_requested
370
+ end
371
+
372
+ describe 'retry behaviour' do
373
+ it "doesn't retry errors" do
374
+ stub_url = '/mandate_imports/:identity/actions/cancel'.gsub(':identity', resource_id)
375
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
376
+ to_timeout
377
+
378
+ expect { post_response }.to raise_error(Faraday::TimeoutError)
379
+ expect(stub).to have_been_requested
380
+ end
381
+ end
382
+
383
+ context 'when the request needs a body and custom header' do
384
+ let(:body) { { foo: 'bar' } }
385
+ let(:headers) { { 'Foo' => 'Bar' } }
386
+ subject(:post_response) { client.mandate_imports.cancel(resource_id, body, headers) }
387
+
388
+ let(:resource_id) { 'ABC123' }
389
+
390
+ let!(:stub) do
391
+ # /mandate_imports/%v/actions/cancel
392
+ stub_url = '/mandate_imports/:identity/actions/cancel'.gsub(':identity', resource_id)
393
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
394
+ with(
395
+ body: { foo: 'bar' },
396
+ headers: { 'Foo' => 'Bar' }
397
+ ).to_return(
398
+ body: {
399
+ 'mandate_imports' => {
400
+
401
+ 'created_at' => 'created_at-input',
402
+ 'id' => 'id-input',
403
+ 'scheme' => 'scheme-input',
404
+ 'status' => 'status-input',
405
+ },
406
+ }.to_json,
407
+ headers: response_headers
408
+ )
409
+ end
410
+ end
411
+ end
412
+ end