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.
- checksums.yaml +4 -4
- data/lib/gocardless_pro/api_service.rb +4 -5
- data/lib/gocardless_pro/client.rb +3 -3
- data/lib/gocardless_pro/error/invalid_state_error.rb +1 -0
- data/lib/gocardless_pro/error.rb +1 -0
- data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +7 -9
- data/lib/gocardless_pro/request.rb +5 -7
- data/lib/gocardless_pro/resources/bank_authorisation.rb +0 -2
- data/lib/gocardless_pro/resources/bank_details_lookup.rb +0 -2
- data/lib/gocardless_pro/resources/billing_request.rb +0 -2
- data/lib/gocardless_pro/resources/billing_request_flow.rb +0 -2
- data/lib/gocardless_pro/resources/billing_request_template.rb +0 -2
- data/lib/gocardless_pro/resources/block.rb +0 -2
- data/lib/gocardless_pro/resources/creditor.rb +0 -2
- data/lib/gocardless_pro/resources/creditor_bank_account.rb +0 -2
- data/lib/gocardless_pro/resources/currency_exchange_rate.rb +0 -2
- data/lib/gocardless_pro/resources/customer.rb +0 -2
- data/lib/gocardless_pro/resources/customer_bank_account.rb +0 -2
- data/lib/gocardless_pro/resources/customer_notification.rb +0 -2
- data/lib/gocardless_pro/resources/event.rb +0 -2
- data/lib/gocardless_pro/resources/instalment_schedule.rb +0 -2
- data/lib/gocardless_pro/resources/institution.rb +0 -2
- data/lib/gocardless_pro/resources/mandate.rb +0 -2
- data/lib/gocardless_pro/resources/mandate_import.rb +0 -2
- data/lib/gocardless_pro/resources/mandate_import_entry.rb +0 -2
- data/lib/gocardless_pro/resources/mandate_pdf.rb +0 -2
- data/lib/gocardless_pro/resources/payer_authorisation.rb +0 -2
- data/lib/gocardless_pro/resources/payment.rb +0 -2
- data/lib/gocardless_pro/resources/payout.rb +0 -2
- data/lib/gocardless_pro/resources/payout_item.rb +0 -2
- data/lib/gocardless_pro/resources/redirect_flow.rb +0 -2
- data/lib/gocardless_pro/resources/refund.rb +0 -2
- data/lib/gocardless_pro/resources/scenario_simulator.rb +0 -2
- data/lib/gocardless_pro/resources/scheme_identifier.rb +0 -2
- data/lib/gocardless_pro/resources/subscription.rb +0 -2
- data/lib/gocardless_pro/resources/tax_rate.rb +0 -2
- data/lib/gocardless_pro/resources/verification_detail.rb +0 -2
- data/lib/gocardless_pro/resources/webhook.rb +0 -2
- data/lib/gocardless_pro/services/bank_authorisations_service.rb +3 -1
- data/lib/gocardless_pro/services/billing_request_flows_service.rb +3 -1
- data/lib/gocardless_pro/services/billing_request_templates_service.rb +6 -2
- data/lib/gocardless_pro/services/billing_requests_service.rb +27 -9
- data/lib/gocardless_pro/services/blocks_service.rb +9 -3
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +6 -2
- data/lib/gocardless_pro/services/creditors_service.rb +9 -3
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +9 -3
- data/lib/gocardless_pro/services/customer_notifications_service.rb +3 -1
- data/lib/gocardless_pro/services/customers_service.rb +9 -3
- data/lib/gocardless_pro/services/events_service.rb +3 -1
- data/lib/gocardless_pro/services/instalment_schedules_service.rb +9 -3
- data/lib/gocardless_pro/services/mandate_imports_service.rb +9 -3
- data/lib/gocardless_pro/services/mandates_service.rb +12 -4
- data/lib/gocardless_pro/services/payer_authorisations_service.rb +12 -4
- data/lib/gocardless_pro/services/payments_service.rb +12 -4
- data/lib/gocardless_pro/services/payouts_service.rb +6 -2
- data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -2
- data/lib/gocardless_pro/services/refunds_service.rb +6 -2
- data/lib/gocardless_pro/services/scenario_simulators_service.rb +3 -1
- data/lib/gocardless_pro/services/scheme_identifiers_service.rb +3 -1
- data/lib/gocardless_pro/services/subscriptions_service.rb +15 -5
- data/lib/gocardless_pro/services/tax_rates_service.rb +3 -1
- data/lib/gocardless_pro/services/webhooks_service.rb +6 -2
- data/lib/gocardless_pro/version.rb +1 -2
- data/lib/gocardless_pro/webhook.rb +5 -4
- data/lib/gocardless_pro.rb +2 -4
- metadata +5 -195
- data/.github/workflows/tests.yml +0 -40
- data/.gitignore +0 -1
- data/.rspec +0 -2
- data/.rubocop.yml +0 -5
- data/.travis.yml +0 -10
- data/LICENSE.txt +0 -22
- data/demo.rb +0 -9
- data/gocardless_pro.gemspec +0 -39
- data/spec/api_response_spec.rb +0 -28
- data/spec/api_service_spec.rb +0 -188
- data/spec/client_spec.rb +0 -19
- data/spec/error_spec.rb +0 -53
- data/spec/middlewares/raise_gocardless_errors_spec.rb +0 -127
- data/spec/resources/bank_authorisation_spec.rb +0 -259
- data/spec/resources/bank_details_lookup_spec.rb +0 -121
- data/spec/resources/billing_request_flow_spec.rb +0 -257
- data/spec/resources/billing_request_spec.rb +0 -962
- data/spec/resources/billing_request_template_spec.rb +0 -515
- data/spec/resources/block_spec.rb +0 -577
- data/spec/resources/creditor_bank_account_spec.rb +0 -472
- data/spec/resources/creditor_spec.rb +0 -659
- data/spec/resources/currency_exchange_rate_spec.rb +0 -103
- data/spec/resources/customer_bank_account_spec.rb +0 -509
- data/spec/resources/customer_notification_spec.rb +0 -75
- data/spec/resources/customer_spec.rb +0 -616
- data/spec/resources/event_spec.rb +0 -210
- data/spec/resources/instalment_schedule_spec.rb +0 -636
- data/spec/resources/institution_spec.rb +0 -113
- data/spec/resources/mandate_import_entry_spec.rb +0 -206
- data/spec/resources/mandate_import_spec.rb +0 -344
- data/spec/resources/mandate_pdf_spec.rb +0 -117
- data/spec/resources/mandate_spec.rb +0 -600
- data/spec/resources/payer_authorisation_spec.rb +0 -422
- data/spec/resources/payment_spec.rb +0 -617
- data/spec/resources/payout_item_spec.rb +0 -101
- data/spec/resources/payout_spec.rb +0 -284
- data/spec/resources/redirect_flow_spec.rb +0 -347
- data/spec/resources/refund_spec.rb +0 -409
- data/spec/resources/scenario_simulator_spec.rb +0 -65
- data/spec/resources/scheme_identifier_spec.rb +0 -484
- data/spec/resources/subscription_spec.rb +0 -828
- data/spec/resources/tax_rate_spec.rb +0 -198
- data/spec/resources/verification_detail_spec.rb +0 -145
- data/spec/resources/webhook_spec.rb +0 -325
- data/spec/response_spec.rb +0 -34
- data/spec/services/bank_authorisations_service_spec.rb +0 -353
- data/spec/services/bank_details_lookups_service_spec.rb +0 -144
- data/spec/services/billing_request_flows_service_spec.rb +0 -291
- data/spec/services/billing_request_templates_service_spec.rb +0 -806
- data/spec/services/billing_requests_service_spec.rb +0 -1288
- data/spec/services/blocks_service_spec.rb +0 -840
- data/spec/services/creditor_bank_accounts_service_spec.rb +0 -725
- data/spec/services/creditors_service_spec.rb +0 -977
- data/spec/services/currency_exchange_rates_service_spec.rb +0 -223
- data/spec/services/customer_bank_accounts_service_spec.rb +0 -787
- data/spec/services/customer_notifications_service_spec.rb +0 -86
- data/spec/services/customers_service_spec.rb +0 -922
- data/spec/services/events_service_spec.rb +0 -401
- data/spec/services/instalment_schedules_service_spec.rb +0 -945
- data/spec/services/institutions_service_spec.rb +0 -241
- data/spec/services/mandate_import_entries_service_spec.rb +0 -345
- data/spec/services/mandate_imports_service_spec.rb +0 -460
- data/spec/services/mandate_pdfs_service_spec.rb +0 -140
- data/spec/services/mandates_service_spec.rb +0 -893
- data/spec/services/payer_authorisations_service_spec.rb +0 -563
- data/spec/services/payments_service_spec.rb +0 -914
- data/spec/services/payout_items_service_spec.rb +0 -221
- data/spec/services/payouts_service_spec.rb +0 -520
- data/spec/services/redirect_flows_service_spec.rb +0 -452
- data/spec/services/refunds_service_spec.rb +0 -668
- data/spec/services/scenario_simulators_service_spec.rb +0 -76
- data/spec/services/scheme_identifiers_service_spec.rb +0 -754
- data/spec/services/subscriptions_service_spec.rb +0 -1164
- data/spec/services/tax_rates_service_spec.rb +0 -381
- data/spec/services/verification_details_service_spec.rb +0 -168
- data/spec/services/webhooks_service_spec.rb +0 -547
- data/spec/spec_helper.rb +0 -90
- data/spec/webhook_spec.rb +0 -122
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GoCardlessPro::Middlewares::RaiseGoCardlessErrors do
|
4
|
-
let(:connection) do
|
5
|
-
Faraday.new do |faraday|
|
6
|
-
faraday.response :raise_gocardless_errors
|
7
|
-
faraday.adapter :net_http
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
before do
|
12
|
-
stub_request(:post, 'https://api.gocardless.com/widgets').to_return(status: status,
|
13
|
-
body: body,
|
14
|
-
headers: headers)
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:body) { nil }
|
18
|
-
let(:headers) { { 'Content-Type' => 'application/json' } }
|
19
|
-
|
20
|
-
context 'with a non-JSON response' do
|
21
|
-
let(:body) { '<html><body>Response from Cloudflare</body></html>' }
|
22
|
-
let(:headers) { { 'Content-Type' => 'text/html' } }
|
23
|
-
let(:status) { 514 }
|
24
|
-
|
25
|
-
it 'raises an error' do
|
26
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
27
|
-
to raise_error(GoCardlessPro::ApiError)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with a 5XX response' do
|
32
|
-
let(:status) { 503 }
|
33
|
-
|
34
|
-
it 'raises an error' do
|
35
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
36
|
-
to raise_error(GoCardlessPro::ApiError)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with a 2XX response' do
|
41
|
-
let(:status) { 200 }
|
42
|
-
|
43
|
-
it "doesn't raise an error" do
|
44
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
45
|
-
to_not raise_error(GoCardlessPro::ApiError)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'with a 4XX response' do
|
50
|
-
context 'for a validation error' do
|
51
|
-
let(:raw_response) do
|
52
|
-
double('response',
|
53
|
-
headers: default_headers,
|
54
|
-
status: 400,
|
55
|
-
body: { error: { type: 'validation_failed' } }.to_json)
|
56
|
-
end
|
57
|
-
|
58
|
-
let(:status) { 422 }
|
59
|
-
let(:body) { { error: { type: 'validation_failed' } }.to_json }
|
60
|
-
|
61
|
-
it 'raises a ValidationError' do
|
62
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
63
|
-
to raise_error(GoCardlessPro::ValidationError)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'for a GoCardless error' do
|
68
|
-
let(:status) { 500 }
|
69
|
-
let(:body) { { error: { type: 'gocardless' } }.to_json }
|
70
|
-
|
71
|
-
it 'raises a GoCardlessError' do
|
72
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
73
|
-
to raise_error(GoCardlessPro::GoCardlessError)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'for a Permission error' do
|
78
|
-
let(:status) { 403 }
|
79
|
-
let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
|
80
|
-
|
81
|
-
it 'raises a GoCardlessError' do
|
82
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
83
|
-
to raise_error(GoCardlessPro::PermissionError)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'for a RateLimit error' do
|
88
|
-
let(:status) { 429 }
|
89
|
-
let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
|
90
|
-
|
91
|
-
it 'raises a GoCardlessError' do
|
92
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
93
|
-
to raise_error(GoCardlessPro::RateLimitError)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'for a Authentication error' do
|
98
|
-
let(:status) { 401 }
|
99
|
-
let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
|
100
|
-
|
101
|
-
it 'raises a GoCardlessError' do
|
102
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
103
|
-
to raise_error(GoCardlessPro::AuthenticationError)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'for an invalid API usage error' do
|
108
|
-
let(:status) { 400 }
|
109
|
-
let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
|
110
|
-
|
111
|
-
it 'raises a InvalidApiUsageError' do
|
112
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
113
|
-
to raise_error(GoCardlessPro::InvalidApiUsageError)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'for an invalid state error' do
|
118
|
-
let(:status) { 422 }
|
119
|
-
let(:body) { { error: { type: 'invalid_state' } }.to_json }
|
120
|
-
|
121
|
-
it 'raises an InvalidStateError' do
|
122
|
-
expect { connection.post('https://api.gocardless.com/widgets') }.
|
123
|
-
to raise_error(GoCardlessPro::InvalidStateError)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,259 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GoCardlessPro::Resources::BankAuthorisation 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 '#get' do
|
13
|
-
let(:id) { 'ID123' }
|
14
|
-
|
15
|
-
subject(:get_response) { client.bank_authorisations.get(id) }
|
16
|
-
|
17
|
-
context 'passing in a custom header' do
|
18
|
-
let!(:stub) do
|
19
|
-
stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
|
20
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
21
|
-
with(headers: { 'Foo' => 'Bar' }).
|
22
|
-
to_return(
|
23
|
-
body: {
|
24
|
-
'bank_authorisations' => {
|
25
|
-
|
26
|
-
'authorisation_type' => 'authorisation_type-input',
|
27
|
-
'authorised_at' => 'authorised_at-input',
|
28
|
-
'created_at' => 'created_at-input',
|
29
|
-
'expires_at' => 'expires_at-input',
|
30
|
-
'id' => 'id-input',
|
31
|
-
'last_visited_at' => 'last_visited_at-input',
|
32
|
-
'links' => 'links-input',
|
33
|
-
'redirect_uri' => 'redirect_uri-input',
|
34
|
-
'url' => 'url-input',
|
35
|
-
},
|
36
|
-
}.to_json,
|
37
|
-
headers: response_headers
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
subject(:get_response) do
|
42
|
-
client.bank_authorisations.get(id, headers: {
|
43
|
-
'Foo' => 'Bar',
|
44
|
-
})
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'includes the header' do
|
48
|
-
get_response
|
49
|
-
expect(stub).to have_been_requested
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when there is a bank_authorisation to return' do
|
54
|
-
before do
|
55
|
-
stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
|
56
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
57
|
-
body: {
|
58
|
-
'bank_authorisations' => {
|
59
|
-
|
60
|
-
'authorisation_type' => 'authorisation_type-input',
|
61
|
-
'authorised_at' => 'authorised_at-input',
|
62
|
-
'created_at' => 'created_at-input',
|
63
|
-
'expires_at' => 'expires_at-input',
|
64
|
-
'id' => 'id-input',
|
65
|
-
'last_visited_at' => 'last_visited_at-input',
|
66
|
-
'links' => 'links-input',
|
67
|
-
'redirect_uri' => 'redirect_uri-input',
|
68
|
-
'url' => 'url-input',
|
69
|
-
},
|
70
|
-
}.to_json,
|
71
|
-
headers: response_headers
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'wraps the response in a resource' do
|
76
|
-
expect(get_response).to be_a(GoCardlessPro::Resources::BankAuthorisation)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when nothing is returned' do
|
81
|
-
before do
|
82
|
-
stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
|
83
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
84
|
-
body: '',
|
85
|
-
headers: response_headers
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'returns nil' do
|
90
|
-
expect(get_response).to be_nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when an ID is specified which can't be included in a valid URI" do
|
95
|
-
let(:id) { '`' }
|
96
|
-
|
97
|
-
it "doesn't raise an error" do
|
98
|
-
expect { get_response }.to_not raise_error(/bad URI/)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe '#create' do
|
104
|
-
subject(:post_create_response) { client.bank_authorisations.create(params: new_resource) }
|
105
|
-
context 'with a valid request' do
|
106
|
-
let(:new_resource) do
|
107
|
-
{
|
108
|
-
|
109
|
-
'authorisation_type' => 'authorisation_type-input',
|
110
|
-
'authorised_at' => 'authorised_at-input',
|
111
|
-
'created_at' => 'created_at-input',
|
112
|
-
'expires_at' => 'expires_at-input',
|
113
|
-
'id' => 'id-input',
|
114
|
-
'last_visited_at' => 'last_visited_at-input',
|
115
|
-
'links' => 'links-input',
|
116
|
-
'redirect_uri' => 'redirect_uri-input',
|
117
|
-
'url' => 'url-input',
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
before do
|
122
|
-
stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).
|
123
|
-
with(
|
124
|
-
body: {
|
125
|
-
'bank_authorisations' => {
|
126
|
-
|
127
|
-
'authorisation_type' => 'authorisation_type-input',
|
128
|
-
'authorised_at' => 'authorised_at-input',
|
129
|
-
'created_at' => 'created_at-input',
|
130
|
-
'expires_at' => 'expires_at-input',
|
131
|
-
'id' => 'id-input',
|
132
|
-
'last_visited_at' => 'last_visited_at-input',
|
133
|
-
'links' => 'links-input',
|
134
|
-
'redirect_uri' => 'redirect_uri-input',
|
135
|
-
'url' => 'url-input',
|
136
|
-
},
|
137
|
-
}
|
138
|
-
).
|
139
|
-
to_return(
|
140
|
-
body: {
|
141
|
-
'bank_authorisations' =>
|
142
|
-
|
143
|
-
{
|
144
|
-
|
145
|
-
'authorisation_type' => 'authorisation_type-input',
|
146
|
-
'authorised_at' => 'authorised_at-input',
|
147
|
-
'created_at' => 'created_at-input',
|
148
|
-
'expires_at' => 'expires_at-input',
|
149
|
-
'id' => 'id-input',
|
150
|
-
'last_visited_at' => 'last_visited_at-input',
|
151
|
-
'links' => 'links-input',
|
152
|
-
'redirect_uri' => 'redirect_uri-input',
|
153
|
-
'url' => 'url-input',
|
154
|
-
},
|
155
|
-
|
156
|
-
}.to_json,
|
157
|
-
headers: response_headers
|
158
|
-
)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'creates and returns the resource' do
|
162
|
-
expect(post_create_response).to be_a(GoCardlessPro::Resources::BankAuthorisation)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context 'with a request that returns a validation error' do
|
167
|
-
let(:new_resource) { {} }
|
168
|
-
|
169
|
-
before do
|
170
|
-
stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).to_return(
|
171
|
-
body: {
|
172
|
-
error: {
|
173
|
-
type: 'validation_failed',
|
174
|
-
code: 422,
|
175
|
-
errors: [
|
176
|
-
{ message: 'test error message', field: 'test_field' },
|
177
|
-
],
|
178
|
-
},
|
179
|
-
}.to_json,
|
180
|
-
headers: response_headers,
|
181
|
-
status: 422
|
182
|
-
)
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'throws the correct error' do
|
186
|
-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context 'with a request that returns an idempotent creation conflict error' do
|
191
|
-
let(:id) { 'ID123' }
|
192
|
-
|
193
|
-
let(:new_resource) do
|
194
|
-
{
|
195
|
-
|
196
|
-
'authorisation_type' => 'authorisation_type-input',
|
197
|
-
'authorised_at' => 'authorised_at-input',
|
198
|
-
'created_at' => 'created_at-input',
|
199
|
-
'expires_at' => 'expires_at-input',
|
200
|
-
'id' => 'id-input',
|
201
|
-
'last_visited_at' => 'last_visited_at-input',
|
202
|
-
'links' => 'links-input',
|
203
|
-
'redirect_uri' => 'redirect_uri-input',
|
204
|
-
'url' => 'url-input',
|
205
|
-
}
|
206
|
-
end
|
207
|
-
|
208
|
-
let!(:post_stub) do
|
209
|
-
stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).to_return(
|
210
|
-
body: {
|
211
|
-
error: {
|
212
|
-
type: 'invalid_state',
|
213
|
-
code: 409,
|
214
|
-
errors: [
|
215
|
-
{
|
216
|
-
message: 'A resource has already been created with this idempotency key',
|
217
|
-
reason: 'idempotent_creation_conflict',
|
218
|
-
links: {
|
219
|
-
conflicting_resource_id: id,
|
220
|
-
},
|
221
|
-
},
|
222
|
-
],
|
223
|
-
},
|
224
|
-
}.to_json,
|
225
|
-
headers: response_headers,
|
226
|
-
status: 409
|
227
|
-
)
|
228
|
-
end
|
229
|
-
|
230
|
-
let!(:get_stub) do
|
231
|
-
stub_url = "/bank_authorisations/#{id}"
|
232
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
233
|
-
to_return(
|
234
|
-
body: {
|
235
|
-
'bank_authorisations' => {
|
236
|
-
|
237
|
-
'authorisation_type' => 'authorisation_type-input',
|
238
|
-
'authorised_at' => 'authorised_at-input',
|
239
|
-
'created_at' => 'created_at-input',
|
240
|
-
'expires_at' => 'expires_at-input',
|
241
|
-
'id' => 'id-input',
|
242
|
-
'last_visited_at' => 'last_visited_at-input',
|
243
|
-
'links' => 'links-input',
|
244
|
-
'redirect_uri' => 'redirect_uri-input',
|
245
|
-
'url' => 'url-input',
|
246
|
-
},
|
247
|
-
}.to_json,
|
248
|
-
headers: response_headers
|
249
|
-
)
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'fetches the already-created resource' do
|
253
|
-
post_create_response
|
254
|
-
expect(post_stub).to have_been_requested
|
255
|
-
expect(get_stub).to have_been_requested
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GoCardlessPro::Resources::BankDetailsLookup 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.bank_details_lookups.create(params: new_resource) }
|
14
|
-
context 'with a valid request' do
|
15
|
-
let(:new_resource) do
|
16
|
-
{
|
17
|
-
|
18
|
-
'available_debit_schemes' => 'available_debit_schemes-input',
|
19
|
-
'bank_name' => 'bank_name-input',
|
20
|
-
'bic' => 'bic-input',
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
before do
|
25
|
-
stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).
|
26
|
-
with(
|
27
|
-
body: {
|
28
|
-
'bank_details_lookups' => {
|
29
|
-
|
30
|
-
'available_debit_schemes' => 'available_debit_schemes-input',
|
31
|
-
'bank_name' => 'bank_name-input',
|
32
|
-
'bic' => 'bic-input',
|
33
|
-
},
|
34
|
-
}
|
35
|
-
).
|
36
|
-
to_return(
|
37
|
-
body: {
|
38
|
-
'bank_details_lookups' =>
|
39
|
-
|
40
|
-
{
|
41
|
-
|
42
|
-
'available_debit_schemes' => 'available_debit_schemes-input',
|
43
|
-
'bank_name' => 'bank_name-input',
|
44
|
-
'bic' => 'bic-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::BankDetailsLookup)
|
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/bank_details_lookups}).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
|
-
'available_debit_schemes' => 'available_debit_schemes-input',
|
88
|
-
'bank_name' => 'bank_name-input',
|
89
|
-
'bic' => 'bic-input',
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
let!(:post_stub) do
|
94
|
-
stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).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
|
-
end
|