gocardless_pro 2.27.0 → 2.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -1
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +11 -1
  5. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  6. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  7. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  8. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  9. data/lib/gocardless_pro/resources/bank_authorisation.rb +3 -9
  10. data/lib/gocardless_pro/resources/billing_request.rb +31 -7
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +14 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +76 -0
  14. data/lib/gocardless_pro/resources/event.rb +20 -0
  15. data/lib/gocardless_pro/resources/institution.rb +7 -1
  16. data/lib/gocardless_pro/resources/payer_authorisation.rb +9 -0
  17. data/lib/gocardless_pro/resources/redirect_flow.rb +6 -0
  18. data/lib/gocardless_pro/services/bank_authorisations_service.rb +0 -2
  19. data/lib/gocardless_pro/services/billing_request_flows_service.rb +23 -0
  20. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  21. data/lib/gocardless_pro/services/billing_requests_service.rb +89 -24
  22. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  23. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  24. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  25. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  26. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  27. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  28. data/lib/gocardless_pro/services/events_service.rb +1 -1
  29. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  30. data/lib/gocardless_pro/services/institutions_service.rb +2 -2
  31. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  32. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  33. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  34. data/lib/gocardless_pro/services/payer_authorisations_service.rb +0 -6
  35. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  36. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  37. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  38. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  39. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  40. data/lib/gocardless_pro/services/scenario_simulators_service.rb +28 -6
  41. data/lib/gocardless_pro/services/subscriptions_service.rb +3 -11
  42. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  43. data/lib/gocardless_pro/services/webhooks_service.rb +1 -3
  44. data/lib/gocardless_pro/version.rb +1 -1
  45. data/lib/gocardless_pro.rb +9 -0
  46. data/spec/api_service_spec.rb +12 -1
  47. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  48. data/spec/resources/bank_authorisation_spec.rb +7 -7
  49. data/spec/resources/billing_request_flow_spec.rb +104 -0
  50. data/spec/resources/billing_request_spec.rb +183 -29
  51. data/spec/resources/billing_request_template_spec.rb +502 -0
  52. data/spec/resources/block_spec.rb +577 -0
  53. data/spec/resources/creditor_bank_account_spec.rb +2 -0
  54. data/spec/resources/customer_bank_account_spec.rb +2 -0
  55. data/spec/resources/customer_notification_spec.rb +2 -0
  56. data/spec/resources/customer_spec.rb +2 -0
  57. data/spec/resources/instalment_schedule_spec.rb +2 -0
  58. data/spec/resources/institution_spec.rb +5 -0
  59. data/spec/resources/mandate_import_spec.rb +4 -0
  60. data/spec/resources/mandate_spec.rb +4 -0
  61. data/spec/resources/payer_authorisation_spec.rb +4 -0
  62. data/spec/resources/payment_spec.rb +4 -0
  63. data/spec/resources/redirect_flow_spec.rb +11 -0
  64. data/spec/resources/scenario_simulator_spec.rb +2 -0
  65. data/spec/resources/subscription_spec.rb +6 -0
  66. data/spec/resources/webhook_spec.rb +2 -0
  67. data/spec/services/bank_authorisations_service_spec.rb +7 -20
  68. data/spec/services/billing_request_flows_service_spec.rb +115 -0
  69. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  70. data/spec/services/billing_requests_service_spec.rb +210 -47
  71. data/spec/services/blocks_service_spec.rb +840 -0
  72. data/spec/services/creditor_bank_accounts_service_spec.rb +2 -13
  73. data/spec/services/creditors_service_spec.rb +0 -13
  74. data/spec/services/customer_bank_accounts_service_spec.rb +2 -13
  75. data/spec/services/customer_notifications_service_spec.rb +2 -0
  76. data/spec/services/customers_service_spec.rb +2 -13
  77. data/spec/services/instalment_schedules_service_spec.rb +2 -26
  78. data/spec/services/institutions_service_spec.rb +9 -0
  79. data/spec/services/mandate_imports_service_spec.rb +4 -13
  80. data/spec/services/mandates_service_spec.rb +4 -13
  81. data/spec/services/payer_authorisations_service_spec.rb +4 -13
  82. data/spec/services/payments_service_spec.rb +4 -13
  83. data/spec/services/redirect_flows_service_spec.rb +11 -13
  84. data/spec/services/refunds_service_spec.rb +0 -13
  85. data/spec/services/scenario_simulators_service_spec.rb +2 -0
  86. data/spec/services/subscriptions_service_spec.rb +6 -13
  87. data/spec/services/webhooks_service_spec.rb +2 -0
  88. metadata +18 -3
@@ -0,0 +1,577 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::Block 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.blocks.create(params: new_resource) }
14
+ context 'with a valid request' do
15
+ let(:new_resource) do
16
+ {
17
+
18
+ 'active' => 'active-input',
19
+ 'block_type' => 'block_type-input',
20
+ 'created_at' => 'created_at-input',
21
+ 'id' => 'id-input',
22
+ 'reason_description' => 'reason_description-input',
23
+ 'reason_type' => 'reason_type-input',
24
+ 'resource_reference' => 'resource_reference-input',
25
+ 'updated_at' => 'updated_at-input',
26
+ }
27
+ end
28
+
29
+ before do
30
+ stub_request(:post, %r{.*api.gocardless.com/blocks}).
31
+ with(
32
+ body: {
33
+ 'blocks' => {
34
+
35
+ 'active' => 'active-input',
36
+ 'block_type' => 'block_type-input',
37
+ 'created_at' => 'created_at-input',
38
+ 'id' => 'id-input',
39
+ 'reason_description' => 'reason_description-input',
40
+ 'reason_type' => 'reason_type-input',
41
+ 'resource_reference' => 'resource_reference-input',
42
+ 'updated_at' => 'updated_at-input',
43
+ },
44
+ }
45
+ ).
46
+ to_return(
47
+ body: {
48
+ 'blocks' =>
49
+
50
+ {
51
+
52
+ 'active' => 'active-input',
53
+ 'block_type' => 'block_type-input',
54
+ 'created_at' => 'created_at-input',
55
+ 'id' => 'id-input',
56
+ 'reason_description' => 'reason_description-input',
57
+ 'reason_type' => 'reason_type-input',
58
+ 'resource_reference' => 'resource_reference-input',
59
+ 'updated_at' => 'updated_at-input',
60
+ },
61
+
62
+ }.to_json,
63
+ headers: response_headers
64
+ )
65
+ end
66
+
67
+ it 'creates and returns the resource' do
68
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::Block)
69
+ end
70
+ end
71
+
72
+ context 'with a request that returns a validation error' do
73
+ let(:new_resource) { {} }
74
+
75
+ before do
76
+ stub_request(:post, %r{.*api.gocardless.com/blocks}).to_return(
77
+ body: {
78
+ error: {
79
+ type: 'validation_failed',
80
+ code: 422,
81
+ errors: [
82
+ { message: 'test error message', field: 'test_field' },
83
+ ],
84
+ },
85
+ }.to_json,
86
+ headers: response_headers,
87
+ status: 422
88
+ )
89
+ end
90
+
91
+ it 'throws the correct error' do
92
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
93
+ end
94
+ end
95
+
96
+ context 'with a request that returns an idempotent creation conflict error' do
97
+ let(:id) { 'ID123' }
98
+
99
+ let(:new_resource) do
100
+ {
101
+
102
+ 'active' => 'active-input',
103
+ 'block_type' => 'block_type-input',
104
+ 'created_at' => 'created_at-input',
105
+ 'id' => 'id-input',
106
+ 'reason_description' => 'reason_description-input',
107
+ 'reason_type' => 'reason_type-input',
108
+ 'resource_reference' => 'resource_reference-input',
109
+ 'updated_at' => 'updated_at-input',
110
+ }
111
+ end
112
+
113
+ let!(:post_stub) do
114
+ stub_request(:post, %r{.*api.gocardless.com/blocks}).to_return(
115
+ body: {
116
+ error: {
117
+ type: 'invalid_state',
118
+ code: 409,
119
+ errors: [
120
+ {
121
+ message: 'A resource has already been created with this idempotency key',
122
+ reason: 'idempotent_creation_conflict',
123
+ links: {
124
+ conflicting_resource_id: id,
125
+ },
126
+ },
127
+ ],
128
+ },
129
+ }.to_json,
130
+ headers: response_headers,
131
+ status: 409
132
+ )
133
+ end
134
+
135
+ let!(:get_stub) do
136
+ stub_url = "/blocks/#{id}"
137
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
138
+ to_return(
139
+ body: {
140
+ 'blocks' => {
141
+
142
+ 'active' => 'active-input',
143
+ 'block_type' => 'block_type-input',
144
+ 'created_at' => 'created_at-input',
145
+ 'id' => 'id-input',
146
+ 'reason_description' => 'reason_description-input',
147
+ 'reason_type' => 'reason_type-input',
148
+ 'resource_reference' => 'resource_reference-input',
149
+ 'updated_at' => 'updated_at-input',
150
+ },
151
+ }.to_json,
152
+ headers: response_headers
153
+ )
154
+ end
155
+
156
+ it 'fetches the already-created resource' do
157
+ post_create_response
158
+ expect(post_stub).to have_been_requested
159
+ expect(get_stub).to have_been_requested
160
+ end
161
+ end
162
+ end
163
+
164
+ describe '#get' do
165
+ let(:id) { 'ID123' }
166
+
167
+ subject(:get_response) { client.blocks.get(id) }
168
+
169
+ context 'passing in a custom header' do
170
+ let!(:stub) do
171
+ stub_url = '/blocks/:identity'.gsub(':identity', id)
172
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
173
+ with(headers: { 'Foo' => 'Bar' }).
174
+ to_return(
175
+ body: {
176
+ 'blocks' => {
177
+
178
+ 'active' => 'active-input',
179
+ 'block_type' => 'block_type-input',
180
+ 'created_at' => 'created_at-input',
181
+ 'id' => 'id-input',
182
+ 'reason_description' => 'reason_description-input',
183
+ 'reason_type' => 'reason_type-input',
184
+ 'resource_reference' => 'resource_reference-input',
185
+ 'updated_at' => 'updated_at-input',
186
+ },
187
+ }.to_json,
188
+ headers: response_headers
189
+ )
190
+ end
191
+
192
+ subject(:get_response) do
193
+ client.blocks.get(id, headers: {
194
+ 'Foo' => 'Bar',
195
+ })
196
+ end
197
+
198
+ it 'includes the header' do
199
+ get_response
200
+ expect(stub).to have_been_requested
201
+ end
202
+ end
203
+
204
+ context 'when there is a block to return' do
205
+ before do
206
+ stub_url = '/blocks/:identity'.gsub(':identity', id)
207
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
208
+ body: {
209
+ 'blocks' => {
210
+
211
+ 'active' => 'active-input',
212
+ 'block_type' => 'block_type-input',
213
+ 'created_at' => 'created_at-input',
214
+ 'id' => 'id-input',
215
+ 'reason_description' => 'reason_description-input',
216
+ 'reason_type' => 'reason_type-input',
217
+ 'resource_reference' => 'resource_reference-input',
218
+ 'updated_at' => 'updated_at-input',
219
+ },
220
+ }.to_json,
221
+ headers: response_headers
222
+ )
223
+ end
224
+
225
+ it 'wraps the response in a resource' do
226
+ expect(get_response).to be_a(GoCardlessPro::Resources::Block)
227
+ end
228
+ end
229
+
230
+ context 'when nothing is returned' do
231
+ before do
232
+ stub_url = '/blocks/:identity'.gsub(':identity', id)
233
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
234
+ body: '',
235
+ headers: response_headers
236
+ )
237
+ end
238
+
239
+ it 'returns nil' do
240
+ expect(get_response).to be_nil
241
+ end
242
+ end
243
+
244
+ context "when an ID is specified which can't be included in a valid URI" do
245
+ let(:id) { '`' }
246
+
247
+ it "doesn't raise an error" do
248
+ expect { get_response }.to_not raise_error(/bad URI/)
249
+ end
250
+ end
251
+ end
252
+
253
+ describe '#list' do
254
+ describe 'with no filters' do
255
+ subject(:get_list_response) { client.blocks.list }
256
+
257
+ before do
258
+ stub_request(:get, %r{.*api.gocardless.com/blocks}).to_return(
259
+ body: {
260
+ 'blocks' => [{
261
+
262
+ 'active' => 'active-input',
263
+ 'block_type' => 'block_type-input',
264
+ 'created_at' => 'created_at-input',
265
+ 'id' => 'id-input',
266
+ 'reason_description' => 'reason_description-input',
267
+ 'reason_type' => 'reason_type-input',
268
+ 'resource_reference' => 'resource_reference-input',
269
+ 'updated_at' => 'updated_at-input',
270
+ }],
271
+ meta: {
272
+ cursors: {
273
+ before: nil,
274
+ after: 'ABC123',
275
+ },
276
+ },
277
+ }.to_json,
278
+ headers: response_headers
279
+ )
280
+ end
281
+
282
+ it 'wraps each item in the resource class' do
283
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Block)
284
+
285
+ expect(get_list_response.records.first.active).to eq('active-input')
286
+
287
+ expect(get_list_response.records.first.block_type).to eq('block_type-input')
288
+
289
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
290
+
291
+ expect(get_list_response.records.first.id).to eq('id-input')
292
+
293
+ expect(get_list_response.records.first.reason_description).to eq('reason_description-input')
294
+
295
+ expect(get_list_response.records.first.reason_type).to eq('reason_type-input')
296
+
297
+ expect(get_list_response.records.first.resource_reference).to eq('resource_reference-input')
298
+
299
+ expect(get_list_response.records.first.updated_at).to eq('updated_at-input')
300
+ end
301
+
302
+ it 'exposes the cursors for before and after' do
303
+ expect(get_list_response.before).to eq(nil)
304
+ expect(get_list_response.after).to eq('ABC123')
305
+ end
306
+
307
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
308
+ end
309
+ end
310
+
311
+ describe '#all' do
312
+ let!(:first_response_stub) do
313
+ stub_request(:get, %r{.*api.gocardless.com/blocks$}).to_return(
314
+ body: {
315
+ 'blocks' => [{
316
+
317
+ 'active' => 'active-input',
318
+ 'block_type' => 'block_type-input',
319
+ 'created_at' => 'created_at-input',
320
+ 'id' => 'id-input',
321
+ 'reason_description' => 'reason_description-input',
322
+ 'reason_type' => 'reason_type-input',
323
+ 'resource_reference' => 'resource_reference-input',
324
+ 'updated_at' => 'updated_at-input',
325
+ }],
326
+ meta: {
327
+ cursors: { after: 'AB345' },
328
+ limit: 1,
329
+ },
330
+ }.to_json,
331
+ headers: response_headers
332
+ )
333
+ end
334
+
335
+ let!(:second_response_stub) do
336
+ stub_request(:get, %r{.*api.gocardless.com/blocks\?after=AB345}).to_return(
337
+ body: {
338
+ 'blocks' => [{
339
+
340
+ 'active' => 'active-input',
341
+ 'block_type' => 'block_type-input',
342
+ 'created_at' => 'created_at-input',
343
+ 'id' => 'id-input',
344
+ 'reason_description' => 'reason_description-input',
345
+ 'reason_type' => 'reason_type-input',
346
+ 'resource_reference' => 'resource_reference-input',
347
+ 'updated_at' => 'updated_at-input',
348
+ }],
349
+ meta: {
350
+ limit: 2,
351
+ cursors: {},
352
+ },
353
+ }.to_json,
354
+ headers: response_headers
355
+ )
356
+ end
357
+
358
+ it 'automatically makes the extra requests' do
359
+ expect(client.blocks.all.to_a.length).to eq(2)
360
+ expect(first_response_stub).to have_been_requested
361
+ expect(second_response_stub).to have_been_requested
362
+ end
363
+ end
364
+
365
+ describe '#disable' do
366
+ subject(:post_response) { client.blocks.disable(resource_id) }
367
+
368
+ let(:resource_id) { 'ABC123' }
369
+
370
+ let!(:stub) do
371
+ # /blocks/%v/actions/disable
372
+ stub_url = '/blocks/:identity/actions/disable'.gsub(':identity', resource_id)
373
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
374
+
375
+ body: {
376
+ 'blocks' => {
377
+
378
+ 'active' => 'active-input',
379
+ 'block_type' => 'block_type-input',
380
+ 'created_at' => 'created_at-input',
381
+ 'id' => 'id-input',
382
+ 'reason_description' => 'reason_description-input',
383
+ 'reason_type' => 'reason_type-input',
384
+ 'resource_reference' => 'resource_reference-input',
385
+ 'updated_at' => 'updated_at-input',
386
+ },
387
+ }.to_json,
388
+
389
+ headers: response_headers
390
+ )
391
+ end
392
+
393
+ it 'wraps the response and calls the right endpoint' do
394
+ expect(post_response).to be_a(GoCardlessPro::Resources::Block)
395
+
396
+ expect(stub).to have_been_requested
397
+ end
398
+
399
+ context 'when the request needs a body and custom header' do
400
+ let(:body) { { foo: 'bar' } }
401
+ let(:headers) { { 'Foo' => 'Bar' } }
402
+ subject(:post_response) { client.blocks.disable(resource_id, body, headers) }
403
+
404
+ let(:resource_id) { 'ABC123' }
405
+
406
+ let!(:stub) do
407
+ # /blocks/%v/actions/disable
408
+ stub_url = '/blocks/:identity/actions/disable'.gsub(':identity', resource_id)
409
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
410
+ with(
411
+ body: { foo: 'bar' },
412
+ headers: { 'Foo' => 'Bar' }
413
+ ).to_return(
414
+ body: {
415
+ 'blocks' => {
416
+
417
+ 'active' => 'active-input',
418
+ 'block_type' => 'block_type-input',
419
+ 'created_at' => 'created_at-input',
420
+ 'id' => 'id-input',
421
+ 'reason_description' => 'reason_description-input',
422
+ 'reason_type' => 'reason_type-input',
423
+ 'resource_reference' => 'resource_reference-input',
424
+ 'updated_at' => 'updated_at-input',
425
+ },
426
+ }.to_json,
427
+ headers: response_headers
428
+ )
429
+ end
430
+ end
431
+ end
432
+
433
+ describe '#enable' do
434
+ subject(:post_response) { client.blocks.enable(resource_id) }
435
+
436
+ let(:resource_id) { 'ABC123' }
437
+
438
+ let!(:stub) do
439
+ # /blocks/%v/actions/enable
440
+ stub_url = '/blocks/:identity/actions/enable'.gsub(':identity', resource_id)
441
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
442
+
443
+ body: {
444
+ 'blocks' => {
445
+
446
+ 'active' => 'active-input',
447
+ 'block_type' => 'block_type-input',
448
+ 'created_at' => 'created_at-input',
449
+ 'id' => 'id-input',
450
+ 'reason_description' => 'reason_description-input',
451
+ 'reason_type' => 'reason_type-input',
452
+ 'resource_reference' => 'resource_reference-input',
453
+ 'updated_at' => 'updated_at-input',
454
+ },
455
+ }.to_json,
456
+
457
+ headers: response_headers
458
+ )
459
+ end
460
+
461
+ it 'wraps the response and calls the right endpoint' do
462
+ expect(post_response).to be_a(GoCardlessPro::Resources::Block)
463
+
464
+ expect(stub).to have_been_requested
465
+ end
466
+
467
+ context 'when the request needs a body and custom header' do
468
+ let(:body) { { foo: 'bar' } }
469
+ let(:headers) { { 'Foo' => 'Bar' } }
470
+ subject(:post_response) { client.blocks.enable(resource_id, body, headers) }
471
+
472
+ let(:resource_id) { 'ABC123' }
473
+
474
+ let!(:stub) do
475
+ # /blocks/%v/actions/enable
476
+ stub_url = '/blocks/:identity/actions/enable'.gsub(':identity', resource_id)
477
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
478
+ with(
479
+ body: { foo: 'bar' },
480
+ headers: { 'Foo' => 'Bar' }
481
+ ).to_return(
482
+ body: {
483
+ 'blocks' => {
484
+
485
+ 'active' => 'active-input',
486
+ 'block_type' => 'block_type-input',
487
+ 'created_at' => 'created_at-input',
488
+ 'id' => 'id-input',
489
+ 'reason_description' => 'reason_description-input',
490
+ 'reason_type' => 'reason_type-input',
491
+ 'resource_reference' => 'resource_reference-input',
492
+ 'updated_at' => 'updated_at-input',
493
+ },
494
+ }.to_json,
495
+ headers: response_headers
496
+ )
497
+ end
498
+ end
499
+ end
500
+
501
+ describe '#block_by_ref' do
502
+ subject(:post_response) { client.blocks.block_by_ref }
503
+
504
+ let(:resource_id) { 'ABC123' }
505
+
506
+ let!(:stub) do
507
+ # /block_by_ref
508
+ stub_url = '/block_by_ref'.gsub(':identity', resource_id)
509
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
510
+
511
+ body: {
512
+ 'blocks' => [{
513
+
514
+ 'active' => 'active-input',
515
+ 'block_type' => 'block_type-input',
516
+ 'created_at' => 'created_at-input',
517
+ 'id' => 'id-input',
518
+ 'reason_description' => 'reason_description-input',
519
+ 'reason_type' => 'reason_type-input',
520
+ 'resource_reference' => 'resource_reference-input',
521
+ 'updated_at' => 'updated_at-input',
522
+ }],
523
+ meta: {
524
+ cursors: {
525
+ before: nil,
526
+ after: 'ABC123',
527
+ },
528
+ },
529
+ }.to_json,
530
+
531
+ headers: response_headers
532
+ )
533
+ end
534
+
535
+ it 'wraps the response and calls the right endpoint' do
536
+ expect(post_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Block)
537
+
538
+ expect(stub).to have_been_requested
539
+ end
540
+
541
+ it 'exposes the cursors for before and after' do
542
+ expect(post_response.before).to eq(nil)
543
+ expect(post_response.after).to eq('ABC123')
544
+ end
545
+
546
+ context 'when the request needs a body and custom header' do
547
+ subject(:post_response) { client.blocks.block_by_ref(body, headers) }
548
+
549
+ let(:resource_id) { 'ABC123' }
550
+
551
+ let!(:stub) do
552
+ # /block_by_ref
553
+ stub_url = '/block_by_ref'.gsub(':identity', resource_id)
554
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
555
+ with(
556
+ body: { foo: 'bar' },
557
+ headers: { 'Foo' => 'Bar' }
558
+ ).to_return(
559
+ body: {
560
+ 'blocks' => {
561
+
562
+ 'active' => 'active-input',
563
+ 'block_type' => 'block_type-input',
564
+ 'created_at' => 'created_at-input',
565
+ 'id' => 'id-input',
566
+ 'reason_description' => 'reason_description-input',
567
+ 'reason_type' => 'reason_type-input',
568
+ 'resource_reference' => 'resource_reference-input',
569
+ 'updated_at' => 'updated_at-input',
570
+ },
571
+ }.to_json,
572
+ headers: response_headers
573
+ )
574
+ end
575
+ end
576
+ end
577
+ end
@@ -405,6 +405,7 @@ describe GoCardlessPro::Resources::CreditorBankAccount do
405
405
  # /creditor_bank_accounts/%v/actions/disable
406
406
  stub_url = '/creditor_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
407
407
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
408
+
408
409
  body: {
409
410
  'creditor_bank_accounts' => {
410
411
 
@@ -421,6 +422,7 @@ describe GoCardlessPro::Resources::CreditorBankAccount do
421
422
  'metadata' => 'metadata-input',
422
423
  },
423
424
  }.to_json,
425
+
424
426
  headers: response_headers
425
427
  )
426
428
  end
@@ -442,6 +442,7 @@ describe GoCardlessPro::Resources::CustomerBankAccount do
442
442
  # /customer_bank_accounts/%v/actions/disable
443
443
  stub_url = '/customer_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
444
444
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
445
+
445
446
  body: {
446
447
  'customer_bank_accounts' => {
447
448
 
@@ -458,6 +459,7 @@ describe GoCardlessPro::Resources::CustomerBankAccount do
458
459
  'metadata' => 'metadata-input',
459
460
  },
460
461
  }.to_json,
462
+
461
463
  headers: response_headers
462
464
  )
463
465
  end
@@ -18,6 +18,7 @@ describe GoCardlessPro::Resources::CustomerNotification do
18
18
  # /customer_notifications/%v/actions/handle
19
19
  stub_url = '/customer_notifications/:identity/actions/handle'.gsub(':identity', resource_id)
20
20
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
21
+
21
22
  body: {
22
23
  'customer_notifications' => {
23
24
 
@@ -29,6 +30,7 @@ describe GoCardlessPro::Resources::CustomerNotification do
29
30
  'type' => 'type-input',
30
31
  },
31
32
  }.to_json,
33
+
32
34
  headers: response_headers
33
35
  )
34
36
  end
@@ -535,6 +535,7 @@ describe GoCardlessPro::Resources::Customer do
535
535
  # /customers/%v
536
536
  stub_url = '/customers/:identity'.gsub(':identity', resource_id)
537
537
  stub_request(:delete, /.*api.gocardless.com#{stub_url}/).to_return(
538
+
538
539
  body: {
539
540
  'customers' => {
540
541
 
@@ -558,6 +559,7 @@ describe GoCardlessPro::Resources::Customer do
558
559
  'swedish_identity_number' => 'swedish_identity_number-input',
559
560
  },
560
561
  }.to_json,
562
+
561
563
  headers: response_headers
562
564
  )
563
565
  end
@@ -573,6 +573,7 @@ describe GoCardlessPro::Resources::InstalmentSchedule do
573
573
  # /instalment_schedules/%v/actions/cancel
574
574
  stub_url = '/instalment_schedules/:identity/actions/cancel'.gsub(':identity', resource_id)
575
575
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
576
+
576
577
  body: {
577
578
  'instalment_schedules' => {
578
579
 
@@ -587,6 +588,7 @@ describe GoCardlessPro::Resources::InstalmentSchedule do
587
588
  'total_amount' => 'total_amount-input',
588
589
  },
589
590
  }.to_json,
591
+
590
592
  headers: response_headers
591
593
  )
592
594
  end
@@ -18,6 +18,7 @@ describe GoCardlessPro::Resources::Institution do
18
18
  body: {
19
19
  'institutions' => [{
20
20
 
21
+ 'country_code' => 'country_code-input',
21
22
  'icon_url' => 'icon_url-input',
22
23
  'id' => 'id-input',
23
24
  'logo_url' => 'logo_url-input',
@@ -37,6 +38,8 @@ describe GoCardlessPro::Resources::Institution do
37
38
  it 'wraps each item in the resource class' do
38
39
  expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Institution)
39
40
 
41
+ expect(get_list_response.records.first.country_code).to eq('country_code-input')
42
+
40
43
  expect(get_list_response.records.first.icon_url).to eq('icon_url-input')
41
44
 
42
45
  expect(get_list_response.records.first.id).to eq('id-input')
@@ -61,6 +64,7 @@ describe GoCardlessPro::Resources::Institution do
61
64
  body: {
62
65
  'institutions' => [{
63
66
 
67
+ 'country_code' => 'country_code-input',
64
68
  'icon_url' => 'icon_url-input',
65
69
  'id' => 'id-input',
66
70
  'logo_url' => 'logo_url-input',
@@ -80,6 +84,7 @@ describe GoCardlessPro::Resources::Institution do
80
84
  body: {
81
85
  'institutions' => [{
82
86
 
87
+ 'country_code' => 'country_code-input',
83
88
  'icon_url' => 'icon_url-input',
84
89
  'id' => 'id-input',
85
90
  'logo_url' => 'logo_url-input',