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