gocardless_pro 2.41.0 → 2.41.1

Sign up to get free protection for your applications and to get access to all the features.
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,547 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::WebhooksService 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 '#list' do
13
- describe 'with no filters' do
14
- subject(:get_list_response) { client.webhooks.list }
15
-
16
- let(:body) do
17
- {
18
- 'webhooks' => [{
19
-
20
- 'created_at' => 'created_at-input',
21
- 'id' => 'id-input',
22
- 'is_test' => 'is_test-input',
23
- 'request_body' => 'request_body-input',
24
- 'request_headers' => 'request_headers-input',
25
- 'response_body' => 'response_body-input',
26
- 'response_body_truncated' => 'response_body_truncated-input',
27
- 'response_code' => 'response_code-input',
28
- 'response_headers' => 'response_headers-input',
29
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
30
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
31
- 'successful' => 'successful-input',
32
- 'url' => 'url-input',
33
- }],
34
- meta: {
35
- cursors: {
36
- before: nil,
37
- after: 'ABC123',
38
- },
39
- },
40
- }.to_json
41
- end
42
-
43
- before do
44
- stub_request(:get, %r{.*api.gocardless.com/webhooks}).to_return(
45
- body: body,
46
- headers: response_headers
47
- )
48
- end
49
-
50
- it 'wraps each item in the resource class' do
51
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Webhook)
52
-
53
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
54
-
55
- expect(get_list_response.records.first.id).to eq('id-input')
56
-
57
- expect(get_list_response.records.first.is_test).to eq('is_test-input')
58
-
59
- expect(get_list_response.records.first.request_body).to eq('request_body-input')
60
-
61
- expect(get_list_response.records.first.request_headers).to eq('request_headers-input')
62
-
63
- expect(get_list_response.records.first.response_body).to eq('response_body-input')
64
-
65
- expect(get_list_response.records.first.response_body_truncated).to eq('response_body_truncated-input')
66
-
67
- expect(get_list_response.records.first.response_code).to eq('response_code-input')
68
-
69
- expect(get_list_response.records.first.response_headers).to eq('response_headers-input')
70
-
71
- expect(get_list_response.records.first.response_headers_content_truncated).to eq('response_headers_content_truncated-input')
72
-
73
- expect(get_list_response.records.first.response_headers_count_truncated).to eq('response_headers_count_truncated-input')
74
-
75
- expect(get_list_response.records.first.successful).to eq('successful-input')
76
-
77
- expect(get_list_response.records.first.url).to eq('url-input')
78
- end
79
-
80
- it 'exposes the cursors for before and after' do
81
- expect(get_list_response.before).to eq(nil)
82
- expect(get_list_response.after).to eq('ABC123')
83
- end
84
-
85
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
86
-
87
- describe 'retry behaviour' do
88
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
89
-
90
- it 'retries timeouts' do
91
- stub = stub_request(:get, %r{.*api.gocardless.com/webhooks}).
92
- to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
93
-
94
- get_list_response
95
- expect(stub).to have_been_requested.twice
96
- end
97
-
98
- it 'retries 5XX errors' do
99
- stub = stub_request(:get, %r{.*api.gocardless.com/webhooks}).
100
- to_return(status: 502,
101
- headers: { 'Content-Type' => 'text/html' },
102
- body: '<html><body>Response from Cloudflare</body></html>').
103
- then.to_return(status: 200, headers: response_headers, body: body)
104
-
105
- get_list_response
106
- expect(stub).to have_been_requested.twice
107
- end
108
- end
109
- end
110
- end
111
-
112
- describe '#all' do
113
- let!(:first_response_stub) do
114
- stub_request(:get, %r{.*api.gocardless.com/webhooks$}).to_return(
115
- body: {
116
- 'webhooks' => [{
117
-
118
- 'created_at' => 'created_at-input',
119
- 'id' => 'id-input',
120
- 'is_test' => 'is_test-input',
121
- 'request_body' => 'request_body-input',
122
- 'request_headers' => 'request_headers-input',
123
- 'response_body' => 'response_body-input',
124
- 'response_body_truncated' => 'response_body_truncated-input',
125
- 'response_code' => 'response_code-input',
126
- 'response_headers' => 'response_headers-input',
127
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
128
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
129
- 'successful' => 'successful-input',
130
- 'url' => 'url-input',
131
- }],
132
- meta: {
133
- cursors: { after: 'AB345' },
134
- limit: 1,
135
- },
136
- }.to_json,
137
- headers: response_headers
138
- )
139
- end
140
-
141
- let!(:second_response_stub) do
142
- stub_request(:get, %r{.*api.gocardless.com/webhooks\?after=AB345}).to_return(
143
- body: {
144
- 'webhooks' => [{
145
-
146
- 'created_at' => 'created_at-input',
147
- 'id' => 'id-input',
148
- 'is_test' => 'is_test-input',
149
- 'request_body' => 'request_body-input',
150
- 'request_headers' => 'request_headers-input',
151
- 'response_body' => 'response_body-input',
152
- 'response_body_truncated' => 'response_body_truncated-input',
153
- 'response_code' => 'response_code-input',
154
- 'response_headers' => 'response_headers-input',
155
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
156
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
157
- 'successful' => 'successful-input',
158
- 'url' => 'url-input',
159
- }],
160
- meta: {
161
- limit: 2,
162
- cursors: {},
163
- },
164
- }.to_json,
165
- headers: response_headers
166
- )
167
- end
168
-
169
- it 'automatically makes the extra requests' do
170
- expect(client.webhooks.all.to_a.length).to eq(2)
171
- expect(first_response_stub).to have_been_requested
172
- expect(second_response_stub).to have_been_requested
173
- end
174
-
175
- describe 'retry behaviour' do
176
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
177
-
178
- it 'retries timeouts' do
179
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/webhooks$}).to_return(
180
- body: {
181
- 'webhooks' => [{
182
-
183
- 'created_at' => 'created_at-input',
184
- 'id' => 'id-input',
185
- 'is_test' => 'is_test-input',
186
- 'request_body' => 'request_body-input',
187
- 'request_headers' => 'request_headers-input',
188
- 'response_body' => 'response_body-input',
189
- 'response_body_truncated' => 'response_body_truncated-input',
190
- 'response_code' => 'response_code-input',
191
- 'response_headers' => 'response_headers-input',
192
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
193
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
194
- 'successful' => 'successful-input',
195
- 'url' => 'url-input',
196
- }],
197
- meta: {
198
- cursors: { after: 'AB345' },
199
- limit: 1,
200
- },
201
- }.to_json,
202
- headers: response_headers
203
- )
204
-
205
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/webhooks\?after=AB345}).
206
- to_timeout.then.
207
- to_return(
208
- body: {
209
- 'webhooks' => [{
210
-
211
- 'created_at' => 'created_at-input',
212
- 'id' => 'id-input',
213
- 'is_test' => 'is_test-input',
214
- 'request_body' => 'request_body-input',
215
- 'request_headers' => 'request_headers-input',
216
- 'response_body' => 'response_body-input',
217
- 'response_body_truncated' => 'response_body_truncated-input',
218
- 'response_code' => 'response_code-input',
219
- 'response_headers' => 'response_headers-input',
220
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
221
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
222
- 'successful' => 'successful-input',
223
- 'url' => 'url-input',
224
- }],
225
- meta: {
226
- limit: 2,
227
- cursors: {},
228
- },
229
- }.to_json,
230
- headers: response_headers
231
- )
232
-
233
- client.webhooks.all.to_a
234
-
235
- expect(first_response_stub).to have_been_requested
236
- expect(second_response_stub).to have_been_requested.twice
237
- end
238
-
239
- it 'retries 5XX errors' do
240
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/webhooks$}).to_return(
241
- body: {
242
- 'webhooks' => [{
243
-
244
- 'created_at' => 'created_at-input',
245
- 'id' => 'id-input',
246
- 'is_test' => 'is_test-input',
247
- 'request_body' => 'request_body-input',
248
- 'request_headers' => 'request_headers-input',
249
- 'response_body' => 'response_body-input',
250
- 'response_body_truncated' => 'response_body_truncated-input',
251
- 'response_code' => 'response_code-input',
252
- 'response_headers' => 'response_headers-input',
253
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
254
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
255
- 'successful' => 'successful-input',
256
- 'url' => 'url-input',
257
- }],
258
- meta: {
259
- cursors: { after: 'AB345' },
260
- limit: 1,
261
- },
262
- }.to_json,
263
- headers: response_headers
264
- )
265
-
266
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/webhooks\?after=AB345}).
267
- to_return(
268
- status: 502,
269
- body: '<html><body>Response from Cloudflare</body></html>',
270
- headers: { 'Content-Type' => 'text/html' }
271
- ).then.to_return(
272
- body: {
273
- 'webhooks' => [{
274
-
275
- 'created_at' => 'created_at-input',
276
- 'id' => 'id-input',
277
- 'is_test' => 'is_test-input',
278
- 'request_body' => 'request_body-input',
279
- 'request_headers' => 'request_headers-input',
280
- 'response_body' => 'response_body-input',
281
- 'response_body_truncated' => 'response_body_truncated-input',
282
- 'response_code' => 'response_code-input',
283
- 'response_headers' => 'response_headers-input',
284
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
285
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
286
- 'successful' => 'successful-input',
287
- 'url' => 'url-input',
288
- }],
289
- meta: {
290
- limit: 2,
291
- cursors: {},
292
- },
293
- }.to_json,
294
- headers: response_headers
295
- )
296
-
297
- client.webhooks.all.to_a
298
-
299
- expect(first_response_stub).to have_been_requested
300
- expect(second_response_stub).to have_been_requested.twice
301
- end
302
- end
303
- end
304
-
305
- describe '#get' do
306
- let(:id) { 'ID123' }
307
-
308
- subject(:get_response) { client.webhooks.get(id) }
309
-
310
- context 'passing in a custom header' do
311
- let!(:stub) do
312
- stub_url = '/webhooks/:identity'.gsub(':identity', id)
313
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
314
- with(headers: { 'Foo' => 'Bar' }).
315
- to_return(
316
- body: {
317
- 'webhooks' => {
318
-
319
- 'created_at' => 'created_at-input',
320
- 'id' => 'id-input',
321
- 'is_test' => 'is_test-input',
322
- 'request_body' => 'request_body-input',
323
- 'request_headers' => 'request_headers-input',
324
- 'response_body' => 'response_body-input',
325
- 'response_body_truncated' => 'response_body_truncated-input',
326
- 'response_code' => 'response_code-input',
327
- 'response_headers' => 'response_headers-input',
328
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
329
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
330
- 'successful' => 'successful-input',
331
- 'url' => 'url-input',
332
- },
333
- }.to_json,
334
- headers: response_headers
335
- )
336
- end
337
-
338
- subject(:get_response) do
339
- client.webhooks.get(id, headers: {
340
- 'Foo' => 'Bar',
341
- })
342
- end
343
-
344
- it 'includes the header' do
345
- get_response
346
- expect(stub).to have_been_requested
347
- end
348
- end
349
-
350
- context 'when there is a webhook to return' do
351
- before do
352
- stub_url = '/webhooks/:identity'.gsub(':identity', id)
353
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
354
- body: {
355
- 'webhooks' => {
356
-
357
- 'created_at' => 'created_at-input',
358
- 'id' => 'id-input',
359
- 'is_test' => 'is_test-input',
360
- 'request_body' => 'request_body-input',
361
- 'request_headers' => 'request_headers-input',
362
- 'response_body' => 'response_body-input',
363
- 'response_body_truncated' => 'response_body_truncated-input',
364
- 'response_code' => 'response_code-input',
365
- 'response_headers' => 'response_headers-input',
366
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
367
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
368
- 'successful' => 'successful-input',
369
- 'url' => 'url-input',
370
- },
371
- }.to_json,
372
- headers: response_headers
373
- )
374
- end
375
-
376
- it 'wraps the response in a resource' do
377
- expect(get_response).to be_a(GoCardlessPro::Resources::Webhook)
378
- end
379
- end
380
-
381
- context 'when nothing is returned' do
382
- before do
383
- stub_url = '/webhooks/:identity'.gsub(':identity', id)
384
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
385
- body: '',
386
- headers: response_headers
387
- )
388
- end
389
-
390
- it 'returns nil' do
391
- expect(get_response).to be_nil
392
- end
393
- end
394
-
395
- context "when an ID is specified which can't be included in a valid URI" do
396
- let(:id) { '`' }
397
-
398
- it "doesn't raise an error" do
399
- expect { get_response }.to_not raise_error(/bad URI/)
400
- end
401
- end
402
-
403
- describe 'retry behaviour' do
404
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
405
-
406
- it 'retries timeouts' do
407
- stub_url = '/webhooks/:identity'.gsub(':identity', id)
408
-
409
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
410
- to_timeout.then.to_return(status: 200, headers: response_headers)
411
-
412
- get_response
413
- expect(stub).to have_been_requested.twice
414
- end
415
-
416
- it 'retries 5XX errors, other than 500s' do
417
- stub_url = '/webhooks/:identity'.gsub(':identity', id)
418
-
419
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
420
- to_return(status: 502,
421
- headers: { 'Content-Type' => 'text/html' },
422
- body: '<html><body>Response from Cloudflare</body></html>').
423
- then.to_return(status: 200, headers: response_headers)
424
-
425
- get_response
426
- expect(stub).to have_been_requested.twice
427
- end
428
-
429
- it 'retries 500 errors returned by the API' do
430
- stub_url = '/webhooks/:identity'.gsub(':identity', id)
431
-
432
- gocardless_error = {
433
- 'error' => {
434
- 'message' => 'Internal server error',
435
- 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
436
- 'errors' => [{
437
- 'message' => 'Internal server error',
438
- 'reason' => 'internal_server_error',
439
- }],
440
- 'type' => 'gocardless',
441
- 'code' => 500,
442
- 'request_id' => 'dummy_request_id',
443
- 'id' => 'dummy_exception_id',
444
- },
445
- }
446
-
447
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
448
- to_return(status: 500,
449
- headers: response_headers,
450
- body: gocardless_error.to_json).
451
- then.to_return(status: 200, headers: response_headers)
452
-
453
- get_response
454
- expect(stub).to have_been_requested.twice
455
- end
456
- end
457
- end
458
-
459
- describe '#retry' do
460
- subject(:post_response) { client.webhooks.retry(resource_id) }
461
-
462
- let(:resource_id) { 'ABC123' }
463
-
464
- let!(:stub) do
465
- # /webhooks/%v/actions/retry
466
- stub_url = '/webhooks/:identity/actions/retry'.gsub(':identity', resource_id)
467
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
468
-
469
- body: {
470
- 'webhooks' => {
471
-
472
- 'created_at' => 'created_at-input',
473
- 'id' => 'id-input',
474
- 'is_test' => 'is_test-input',
475
- 'request_body' => 'request_body-input',
476
- 'request_headers' => 'request_headers-input',
477
- 'response_body' => 'response_body-input',
478
- 'response_body_truncated' => 'response_body_truncated-input',
479
- 'response_code' => 'response_code-input',
480
- 'response_headers' => 'response_headers-input',
481
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
482
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
483
- 'successful' => 'successful-input',
484
- 'url' => 'url-input',
485
- },
486
- }.to_json,
487
-
488
- headers: response_headers
489
- )
490
- end
491
-
492
- it 'wraps the response and calls the right endpoint' do
493
- expect(post_response).to be_a(GoCardlessPro::Resources::Webhook)
494
-
495
- expect(stub).to have_been_requested
496
- end
497
-
498
- describe 'retry behaviour' do
499
- it "doesn't retry errors" do
500
- stub_url = '/webhooks/:identity/actions/retry'.gsub(':identity', resource_id)
501
- stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
502
- to_timeout
503
-
504
- expect { post_response }.to raise_error(Faraday::ConnectionFailed)
505
- expect(stub).to have_been_requested
506
- end
507
- end
508
-
509
- context 'when the request needs a body and custom header' do
510
- let(:body) { { foo: 'bar' } }
511
- let(:headers) { { 'Foo' => 'Bar' } }
512
- subject(:post_response) { client.webhooks.retry(resource_id, body, headers) }
513
-
514
- let(:resource_id) { 'ABC123' }
515
-
516
- let!(:stub) do
517
- # /webhooks/%v/actions/retry
518
- stub_url = '/webhooks/:identity/actions/retry'.gsub(':identity', resource_id)
519
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
520
- with(
521
- body: { foo: 'bar' },
522
- headers: { 'Foo' => 'Bar' }
523
- ).to_return(
524
- body: {
525
- 'webhooks' => {
526
-
527
- 'created_at' => 'created_at-input',
528
- 'id' => 'id-input',
529
- 'is_test' => 'is_test-input',
530
- 'request_body' => 'request_body-input',
531
- 'request_headers' => 'request_headers-input',
532
- 'response_body' => 'response_body-input',
533
- 'response_body_truncated' => 'response_body_truncated-input',
534
- 'response_code' => 'response_code-input',
535
- 'response_headers' => 'response_headers-input',
536
- 'response_headers_content_truncated' => 'response_headers_content_truncated-input',
537
- 'response_headers_count_truncated' => 'response_headers_count_truncated-input',
538
- 'successful' => 'successful-input',
539
- 'url' => 'url-input',
540
- },
541
- }.to_json,
542
- headers: response_headers
543
- )
544
- end
545
- end
546
- end
547
- end
data/spec/spec_helper.rb DELETED
@@ -1,90 +0,0 @@
1
- require 'webmock/rspec'
2
- require_relative '../lib/gocardless_pro'
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
- # file to always be loaded, without a need to explicitly require it in any files.
7
- #
8
- # Given that it is always loaded, you are encouraged to keep this file as
9
- # light-weight as possible. Requiring heavyweight dependencies from this file
10
- # will add to the boot time of your test suite on EVERY test run, even for an
11
- # individual file that may not need all of that loaded. Instead, consider making
12
- # a separate helper file that requires the additional dependencies and performs
13
- # the additional setup, and require it from the spec files that actually need it.
14
- #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- # This option will default to `true` in RSpec 4. It makes the `description`
25
- # and `failure_message` of custom matchers include text for helper methods
26
- # defined using `chain`, e.g.:
27
- # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
29
- # ...rather than:
30
- # # => "be bigger than 2"
31
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
- expectations.on_potential_false_positives = :nothing
33
- end
34
-
35
- # rspec-mocks config goes here. You can use an alternate test double
36
- # library (such as bogus or mocha) by changing the `mock_with` option here.
37
- config.mock_with :rspec do |mocks|
38
- # Prevents you from mocking or stubbing a method that does not exist on
39
- # a real object. This is generally recommended, and will default to
40
- # `true` in RSpec 4.
41
- mocks.verify_partial_doubles = true
42
- end
43
-
44
- # The settings below are suggested to provide a good initial experience
45
- # with RSpec, but feel free to customize to your heart's content.
46
- # # These two settings work together to allow you to limit a spec run
47
- # # to individual examples or groups you care about by tagging them with
48
- # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
- # # get run.
50
- # config.filter_run :focus
51
- # config.run_all_when_everything_filtered = true
52
- #
53
- # # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
- # # For more details, see:
55
- # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
- # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
- # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
- # config.disable_monkey_patching!
59
- #
60
- # # This setting enables warnings. It's recommended, but in some cases may
61
- # # be too noisy due to issues in dependencies.
62
- # config.warnings = true
63
- #
64
- # # Many RSpec users commonly either run the entire suite or an individual
65
- # # file, and it's useful to allow more verbose output when running an
66
- # # individual spec file.
67
- # if config.files_to_run.one?
68
- # # Use the documentation formatter for detailed output,
69
- # # unless a formatter has already been configured
70
- # # (e.g. via a command-line flag).
71
- # config.default_formatter = 'doc'
72
- # end
73
- #
74
- # # Print the 10 slowest examples and example groups at the
75
- # # end of the spec run, to help surface which specs are running
76
- # # particularly slow.
77
- # config.profile_examples = 10
78
- #
79
- # # Run specs in random order to surface order dependencies. If you find an
80
- # # order dependency and want to debug it, you can fix the order by providing
81
- # # the seed, which is printed after each run.
82
- # # --seed 1234
83
- # config.order = :random
84
- #
85
- # # Seed global randomization in this process using the `--seed` CLI option.
86
- # # Setting this allows you to use `--seed` to deterministically reproduce
87
- # # test failures related to randomization by passing the same `--seed` value
88
- # # as the one that triggered the failure.
89
- # Kernel.srand config.seed
90
- end