gocardless_pro 2.41.0 → 2.41.1

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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gocardless_pro/api_service.rb +4 -5
  3. data/lib/gocardless_pro/client.rb +3 -3
  4. data/lib/gocardless_pro/error/invalid_state_error.rb +1 -0
  5. data/lib/gocardless_pro/error.rb +1 -0
  6. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +7 -9
  7. data/lib/gocardless_pro/request.rb +5 -7
  8. data/lib/gocardless_pro/resources/bank_authorisation.rb +0 -2
  9. data/lib/gocardless_pro/resources/bank_details_lookup.rb +0 -2
  10. data/lib/gocardless_pro/resources/billing_request.rb +0 -2
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +0 -2
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +0 -2
  13. data/lib/gocardless_pro/resources/block.rb +0 -2
  14. data/lib/gocardless_pro/resources/creditor.rb +0 -2
  15. data/lib/gocardless_pro/resources/creditor_bank_account.rb +0 -2
  16. data/lib/gocardless_pro/resources/currency_exchange_rate.rb +0 -2
  17. data/lib/gocardless_pro/resources/customer.rb +0 -2
  18. data/lib/gocardless_pro/resources/customer_bank_account.rb +0 -2
  19. data/lib/gocardless_pro/resources/customer_notification.rb +0 -2
  20. data/lib/gocardless_pro/resources/event.rb +0 -2
  21. data/lib/gocardless_pro/resources/instalment_schedule.rb +0 -2
  22. data/lib/gocardless_pro/resources/institution.rb +0 -2
  23. data/lib/gocardless_pro/resources/mandate.rb +0 -2
  24. data/lib/gocardless_pro/resources/mandate_import.rb +0 -2
  25. data/lib/gocardless_pro/resources/mandate_import_entry.rb +0 -2
  26. data/lib/gocardless_pro/resources/mandate_pdf.rb +0 -2
  27. data/lib/gocardless_pro/resources/payer_authorisation.rb +0 -2
  28. data/lib/gocardless_pro/resources/payment.rb +0 -2
  29. data/lib/gocardless_pro/resources/payout.rb +0 -2
  30. data/lib/gocardless_pro/resources/payout_item.rb +0 -2
  31. data/lib/gocardless_pro/resources/redirect_flow.rb +0 -2
  32. data/lib/gocardless_pro/resources/refund.rb +0 -2
  33. data/lib/gocardless_pro/resources/scenario_simulator.rb +0 -2
  34. data/lib/gocardless_pro/resources/scheme_identifier.rb +0 -2
  35. data/lib/gocardless_pro/resources/subscription.rb +0 -2
  36. data/lib/gocardless_pro/resources/tax_rate.rb +0 -2
  37. data/lib/gocardless_pro/resources/verification_detail.rb +0 -2
  38. data/lib/gocardless_pro/resources/webhook.rb +0 -2
  39. data/lib/gocardless_pro/services/bank_authorisations_service.rb +3 -1
  40. data/lib/gocardless_pro/services/billing_request_flows_service.rb +3 -1
  41. data/lib/gocardless_pro/services/billing_request_templates_service.rb +6 -2
  42. data/lib/gocardless_pro/services/billing_requests_service.rb +27 -9
  43. data/lib/gocardless_pro/services/blocks_service.rb +9 -3
  44. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +6 -2
  45. data/lib/gocardless_pro/services/creditors_service.rb +9 -3
  46. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +9 -3
  47. data/lib/gocardless_pro/services/customer_notifications_service.rb +3 -1
  48. data/lib/gocardless_pro/services/customers_service.rb +9 -3
  49. data/lib/gocardless_pro/services/events_service.rb +3 -1
  50. data/lib/gocardless_pro/services/instalment_schedules_service.rb +9 -3
  51. data/lib/gocardless_pro/services/mandate_imports_service.rb +9 -3
  52. data/lib/gocardless_pro/services/mandates_service.rb +12 -4
  53. data/lib/gocardless_pro/services/payer_authorisations_service.rb +12 -4
  54. data/lib/gocardless_pro/services/payments_service.rb +12 -4
  55. data/lib/gocardless_pro/services/payouts_service.rb +6 -2
  56. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -2
  57. data/lib/gocardless_pro/services/refunds_service.rb +6 -2
  58. data/lib/gocardless_pro/services/scenario_simulators_service.rb +3 -1
  59. data/lib/gocardless_pro/services/scheme_identifiers_service.rb +3 -1
  60. data/lib/gocardless_pro/services/subscriptions_service.rb +15 -5
  61. data/lib/gocardless_pro/services/tax_rates_service.rb +3 -1
  62. data/lib/gocardless_pro/services/webhooks_service.rb +6 -2
  63. data/lib/gocardless_pro/version.rb +1 -2
  64. data/lib/gocardless_pro/webhook.rb +5 -4
  65. data/lib/gocardless_pro.rb +2 -4
  66. metadata +5 -195
  67. data/.github/workflows/tests.yml +0 -40
  68. data/.gitignore +0 -1
  69. data/.rspec +0 -2
  70. data/.rubocop.yml +0 -5
  71. data/.travis.yml +0 -10
  72. data/LICENSE.txt +0 -22
  73. data/demo.rb +0 -9
  74. data/gocardless_pro.gemspec +0 -39
  75. data/spec/api_response_spec.rb +0 -28
  76. data/spec/api_service_spec.rb +0 -188
  77. data/spec/client_spec.rb +0 -19
  78. data/spec/error_spec.rb +0 -53
  79. data/spec/middlewares/raise_gocardless_errors_spec.rb +0 -127
  80. data/spec/resources/bank_authorisation_spec.rb +0 -259
  81. data/spec/resources/bank_details_lookup_spec.rb +0 -121
  82. data/spec/resources/billing_request_flow_spec.rb +0 -257
  83. data/spec/resources/billing_request_spec.rb +0 -962
  84. data/spec/resources/billing_request_template_spec.rb +0 -515
  85. data/spec/resources/block_spec.rb +0 -577
  86. data/spec/resources/creditor_bank_account_spec.rb +0 -472
  87. data/spec/resources/creditor_spec.rb +0 -659
  88. data/spec/resources/currency_exchange_rate_spec.rb +0 -103
  89. data/spec/resources/customer_bank_account_spec.rb +0 -509
  90. data/spec/resources/customer_notification_spec.rb +0 -75
  91. data/spec/resources/customer_spec.rb +0 -616
  92. data/spec/resources/event_spec.rb +0 -210
  93. data/spec/resources/instalment_schedule_spec.rb +0 -636
  94. data/spec/resources/institution_spec.rb +0 -113
  95. data/spec/resources/mandate_import_entry_spec.rb +0 -206
  96. data/spec/resources/mandate_import_spec.rb +0 -344
  97. data/spec/resources/mandate_pdf_spec.rb +0 -117
  98. data/spec/resources/mandate_spec.rb +0 -600
  99. data/spec/resources/payer_authorisation_spec.rb +0 -422
  100. data/spec/resources/payment_spec.rb +0 -617
  101. data/spec/resources/payout_item_spec.rb +0 -101
  102. data/spec/resources/payout_spec.rb +0 -284
  103. data/spec/resources/redirect_flow_spec.rb +0 -347
  104. data/spec/resources/refund_spec.rb +0 -409
  105. data/spec/resources/scenario_simulator_spec.rb +0 -65
  106. data/spec/resources/scheme_identifier_spec.rb +0 -484
  107. data/spec/resources/subscription_spec.rb +0 -828
  108. data/spec/resources/tax_rate_spec.rb +0 -198
  109. data/spec/resources/verification_detail_spec.rb +0 -145
  110. data/spec/resources/webhook_spec.rb +0 -325
  111. data/spec/response_spec.rb +0 -34
  112. data/spec/services/bank_authorisations_service_spec.rb +0 -353
  113. data/spec/services/bank_details_lookups_service_spec.rb +0 -144
  114. data/spec/services/billing_request_flows_service_spec.rb +0 -291
  115. data/spec/services/billing_request_templates_service_spec.rb +0 -806
  116. data/spec/services/billing_requests_service_spec.rb +0 -1288
  117. data/spec/services/blocks_service_spec.rb +0 -840
  118. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -725
  119. data/spec/services/creditors_service_spec.rb +0 -977
  120. data/spec/services/currency_exchange_rates_service_spec.rb +0 -223
  121. data/spec/services/customer_bank_accounts_service_spec.rb +0 -787
  122. data/spec/services/customer_notifications_service_spec.rb +0 -86
  123. data/spec/services/customers_service_spec.rb +0 -922
  124. data/spec/services/events_service_spec.rb +0 -401
  125. data/spec/services/instalment_schedules_service_spec.rb +0 -945
  126. data/spec/services/institutions_service_spec.rb +0 -241
  127. data/spec/services/mandate_import_entries_service_spec.rb +0 -345
  128. data/spec/services/mandate_imports_service_spec.rb +0 -460
  129. data/spec/services/mandate_pdfs_service_spec.rb +0 -140
  130. data/spec/services/mandates_service_spec.rb +0 -893
  131. data/spec/services/payer_authorisations_service_spec.rb +0 -563
  132. data/spec/services/payments_service_spec.rb +0 -914
  133. data/spec/services/payout_items_service_spec.rb +0 -221
  134. data/spec/services/payouts_service_spec.rb +0 -520
  135. data/spec/services/redirect_flows_service_spec.rb +0 -452
  136. data/spec/services/refunds_service_spec.rb +0 -668
  137. data/spec/services/scenario_simulators_service_spec.rb +0 -76
  138. data/spec/services/scheme_identifiers_service_spec.rb +0 -754
  139. data/spec/services/subscriptions_service_spec.rb +0 -1164
  140. data/spec/services/tax_rates_service_spec.rb +0 -381
  141. data/spec/services/verification_details_service_spec.rb +0 -168
  142. data/spec/services/webhooks_service_spec.rb +0 -547
  143. data/spec/spec_helper.rb +0 -90
  144. data/spec/webhook_spec.rb +0 -122
@@ -1,577 +0,0 @@
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
- # /blocks/block_by_ref
508
- stub_url = '/blocks/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
- # /blocks/block_by_ref
553
- stub_url = '/blocks/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