gocardless_pro 2.41.0 → 2.41.2

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/Gemfile +0 -10
  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,241 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::InstitutionsService 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.institutions.list }
15
-
16
- let(:body) do
17
- {
18
- 'institutions' => [{
19
-
20
- 'bank_redirect' => 'bank_redirect-input',
21
- 'country_code' => 'country_code-input',
22
- 'icon_url' => 'icon_url-input',
23
- 'id' => 'id-input',
24
- 'logo_url' => 'logo_url-input',
25
- 'name' => 'name-input',
26
- }],
27
- meta: {
28
- cursors: {
29
- before: nil,
30
- after: 'ABC123',
31
- },
32
- },
33
- }.to_json
34
- end
35
-
36
- before do
37
- stub_request(:get, %r{.*api.gocardless.com/institutions}).to_return(
38
- body: body,
39
- headers: response_headers
40
- )
41
- end
42
-
43
- it 'wraps each item in the resource class' do
44
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Institution)
45
-
46
- expect(get_list_response.records.first.bank_redirect).to eq('bank_redirect-input')
47
-
48
- expect(get_list_response.records.first.country_code).to eq('country_code-input')
49
-
50
- expect(get_list_response.records.first.icon_url).to eq('icon_url-input')
51
-
52
- expect(get_list_response.records.first.id).to eq('id-input')
53
-
54
- expect(get_list_response.records.first.logo_url).to eq('logo_url-input')
55
-
56
- expect(get_list_response.records.first.name).to eq('name-input')
57
- end
58
-
59
- it 'exposes the cursors for before and after' do
60
- expect(get_list_response.before).to eq(nil)
61
- expect(get_list_response.after).to eq('ABC123')
62
- end
63
-
64
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
65
-
66
- describe 'retry behaviour' do
67
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
68
-
69
- it 'retries timeouts' do
70
- stub = stub_request(:get, %r{.*api.gocardless.com/institutions}).
71
- to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
72
-
73
- get_list_response
74
- expect(stub).to have_been_requested.twice
75
- end
76
-
77
- it 'retries 5XX errors' do
78
- stub = stub_request(:get, %r{.*api.gocardless.com/institutions}).
79
- to_return(status: 502,
80
- headers: { 'Content-Type' => 'text/html' },
81
- body: '<html><body>Response from Cloudflare</body></html>').
82
- then.to_return(status: 200, headers: response_headers, body: body)
83
-
84
- get_list_response
85
- expect(stub).to have_been_requested.twice
86
- end
87
- end
88
- end
89
- end
90
-
91
- describe '#all' do
92
- let!(:first_response_stub) do
93
- stub_request(:get, %r{.*api.gocardless.com/institutions$}).to_return(
94
- body: {
95
- 'institutions' => [{
96
-
97
- 'bank_redirect' => 'bank_redirect-input',
98
- 'country_code' => 'country_code-input',
99
- 'icon_url' => 'icon_url-input',
100
- 'id' => 'id-input',
101
- 'logo_url' => 'logo_url-input',
102
- 'name' => 'name-input',
103
- }],
104
- meta: {
105
- cursors: { after: 'AB345' },
106
- limit: 1,
107
- },
108
- }.to_json,
109
- headers: response_headers
110
- )
111
- end
112
-
113
- let!(:second_response_stub) do
114
- stub_request(:get, %r{.*api.gocardless.com/institutions\?after=AB345}).to_return(
115
- body: {
116
- 'institutions' => [{
117
-
118
- 'bank_redirect' => 'bank_redirect-input',
119
- 'country_code' => 'country_code-input',
120
- 'icon_url' => 'icon_url-input',
121
- 'id' => 'id-input',
122
- 'logo_url' => 'logo_url-input',
123
- 'name' => 'name-input',
124
- }],
125
- meta: {
126
- limit: 2,
127
- cursors: {},
128
- },
129
- }.to_json,
130
- headers: response_headers
131
- )
132
- end
133
-
134
- it 'automatically makes the extra requests' do
135
- expect(client.institutions.all.to_a.length).to eq(2)
136
- expect(first_response_stub).to have_been_requested
137
- expect(second_response_stub).to have_been_requested
138
- end
139
-
140
- describe 'retry behaviour' do
141
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
142
-
143
- it 'retries timeouts' do
144
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/institutions$}).to_return(
145
- body: {
146
- 'institutions' => [{
147
-
148
- 'bank_redirect' => 'bank_redirect-input',
149
- 'country_code' => 'country_code-input',
150
- 'icon_url' => 'icon_url-input',
151
- 'id' => 'id-input',
152
- 'logo_url' => 'logo_url-input',
153
- 'name' => 'name-input',
154
- }],
155
- meta: {
156
- cursors: { after: 'AB345' },
157
- limit: 1,
158
- },
159
- }.to_json,
160
- headers: response_headers
161
- )
162
-
163
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/institutions\?after=AB345}).
164
- to_timeout.then.
165
- to_return(
166
- body: {
167
- 'institutions' => [{
168
-
169
- 'bank_redirect' => 'bank_redirect-input',
170
- 'country_code' => 'country_code-input',
171
- 'icon_url' => 'icon_url-input',
172
- 'id' => 'id-input',
173
- 'logo_url' => 'logo_url-input',
174
- 'name' => 'name-input',
175
- }],
176
- meta: {
177
- limit: 2,
178
- cursors: {},
179
- },
180
- }.to_json,
181
- headers: response_headers
182
- )
183
-
184
- client.institutions.all.to_a
185
-
186
- expect(first_response_stub).to have_been_requested
187
- expect(second_response_stub).to have_been_requested.twice
188
- end
189
-
190
- it 'retries 5XX errors' do
191
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/institutions$}).to_return(
192
- body: {
193
- 'institutions' => [{
194
-
195
- 'bank_redirect' => 'bank_redirect-input',
196
- 'country_code' => 'country_code-input',
197
- 'icon_url' => 'icon_url-input',
198
- 'id' => 'id-input',
199
- 'logo_url' => 'logo_url-input',
200
- 'name' => 'name-input',
201
- }],
202
- meta: {
203
- cursors: { after: 'AB345' },
204
- limit: 1,
205
- },
206
- }.to_json,
207
- headers: response_headers
208
- )
209
-
210
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/institutions\?after=AB345}).
211
- to_return(
212
- status: 502,
213
- body: '<html><body>Response from Cloudflare</body></html>',
214
- headers: { 'Content-Type' => 'text/html' }
215
- ).then.to_return(
216
- body: {
217
- 'institutions' => [{
218
-
219
- 'bank_redirect' => 'bank_redirect-input',
220
- 'country_code' => 'country_code-input',
221
- 'icon_url' => 'icon_url-input',
222
- 'id' => 'id-input',
223
- 'logo_url' => 'logo_url-input',
224
- 'name' => 'name-input',
225
- }],
226
- meta: {
227
- limit: 2,
228
- cursors: {},
229
- },
230
- }.to_json,
231
- headers: response_headers
232
- )
233
-
234
- client.institutions.all.to_a
235
-
236
- expect(first_response_stub).to have_been_requested
237
- expect(second_response_stub).to have_been_requested.twice
238
- end
239
- end
240
- end
241
- end
@@ -1,345 +0,0 @@
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