gocardless_pro 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -0
- data/README.md +71 -28
- data/gocardless_pro.gemspec +1 -1
- data/lib/gocardless_pro/api_service.rb +4 -2
- data/lib/gocardless_pro/client.rb +2 -1
- data/lib/gocardless_pro/error.rb +12 -1
- data/lib/gocardless_pro/resources/mandate.rb +3 -0
- data/lib/gocardless_pro/resources/payout.rb +3 -0
- data/lib/gocardless_pro/resources/redirect_flow.rb +15 -14
- data/lib/gocardless_pro/services/bank_details_lookups_service.rb +10 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +5 -2
- data/lib/gocardless_pro/services/creditors_service.rb +5 -2
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +7 -3
- data/lib/gocardless_pro/services/customers_service.rb +5 -2
- data/lib/gocardless_pro/services/events_service.rb +2 -1
- data/lib/gocardless_pro/services/mandate_pdfs_service.rb +2 -1
- data/lib/gocardless_pro/services/mandates_service.rb +10 -5
- data/lib/gocardless_pro/services/payments_service.rb +11 -6
- data/lib/gocardless_pro/services/payouts_service.rb +2 -1
- data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -3
- data/lib/gocardless_pro/services/refunds_service.rb +5 -2
- data/lib/gocardless_pro/services/subscriptions_service.rb +7 -3
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/api_response_spec.rb +4 -4
- data/spec/api_service_spec.rb +41 -43
- data/spec/client_spec.rb +2 -2
- data/spec/error_spec.rb +27 -18
- data/spec/resources/bank_details_lookup_spec.rb +19 -34
- data/spec/resources/creditor_bank_account_spec.rb +54 -99
- data/spec/resources/creditor_spec.rb +66 -115
- data/spec/resources/customer_bank_account_spec.rb +54 -99
- data/spec/resources/customer_spec.rb +71 -138
- data/spec/resources/event_spec.rb +74 -107
- data/spec/resources/mandate_pdf_spec.rb +15 -26
- data/spec/resources/mandate_spec.rb +54 -87
- data/spec/resources/payment_spec.rb +70 -119
- data/spec/resources/payout_spec.rb +50 -79
- data/spec/resources/redirect_flow_spec.rb +58 -95
- data/spec/resources/refund_spec.rb +42 -75
- data/spec/resources/subscription_spec.rb +82 -155
- data/spec/response_spec.rb +45 -46
- data/spec/services/bank_details_lookups_service_spec.rb +55 -60
- data/spec/services/creditor_bank_accounts_service_spec.rb +303 -347
- data/spec/services/creditors_service_spec.rb +290 -333
- data/spec/services/customer_bank_accounts_service_spec.rb +332 -380
- data/spec/services/customers_service_spec.rb +347 -400
- data/spec/services/events_service_spec.rb +154 -184
- data/spec/services/mandate_pdfs_service_spec.rb +52 -57
- data/spec/services/mandates_service_spec.rb +374 -410
- data/spec/services/payments_service_spec.rb +404 -461
- data/spec/services/payouts_service_spec.rb +161 -184
- data/spec/services/redirect_flows_service_spec.rb +188 -205
- data/spec/services/refunds_service_spec.rb +245 -280
- data/spec/services/subscriptions_service_spec.rb +423 -485
- data/spec/spec_helper.rb +46 -48
- metadata +22 -20
@@ -3,393 +3,350 @@ require 'spec_helper'
|
|
3
3
|
describe GoCardlessPro::Services::CreditorsService do
|
4
4
|
let(:client) do
|
5
5
|
GoCardlessPro::Client.new(
|
6
|
-
access_token:
|
6
|
+
access_token: 'SECRET_TOKEN'
|
7
7
|
)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
describe "#create" do
|
10
|
+
describe '#create' do
|
17
11
|
subject(:post_create_response) { client.creditors.create(params: new_resource) }
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
12
|
+
context 'with a valid request' do
|
13
|
+
let(:new_resource) do
|
14
|
+
{
|
15
|
+
|
16
|
+
'address_line1' => 'address_line1-input',
|
17
|
+
'address_line2' => 'address_line2-input',
|
18
|
+
'address_line3' => 'address_line3-input',
|
19
|
+
'city' => 'city-input',
|
20
|
+
'country_code' => 'country_code-input',
|
21
|
+
'created_at' => 'created_at-input',
|
22
|
+
'id' => 'id-input',
|
23
|
+
'links' => 'links-input',
|
24
|
+
'name' => 'name-input',
|
25
|
+
'postal_code' => 'postal_code-input',
|
26
|
+
'region' => 'region-input'
|
27
|
+
}
|
28
|
+
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
with(
|
30
|
+
before do
|
31
|
+
stub_request(:post, %r{.*api.gocardless.com/creditors})
|
32
|
+
.with(
|
39
33
|
body: {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
34
|
+
'creditors' => {
|
35
|
+
|
36
|
+
'address_line1' => 'address_line1-input',
|
37
|
+
'address_line2' => 'address_line2-input',
|
38
|
+
'address_line3' => 'address_line3-input',
|
39
|
+
'city' => 'city-input',
|
40
|
+
'country_code' => 'country_code-input',
|
41
|
+
'created_at' => 'created_at-input',
|
42
|
+
'id' => 'id-input',
|
43
|
+
'links' => 'links-input',
|
44
|
+
'name' => 'name-input',
|
45
|
+
'postal_code' => 'postal_code-input',
|
46
|
+
'region' => 'region-input'
|
47
|
+
}
|
54
48
|
}
|
55
|
-
)
|
56
|
-
to_return(
|
49
|
+
)
|
50
|
+
.to_return(
|
57
51
|
body: {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
52
|
+
'creditors' =>
|
53
|
+
|
54
|
+
{
|
55
|
+
|
56
|
+
'address_line1' => 'address_line1-input',
|
57
|
+
'address_line2' => 'address_line2-input',
|
58
|
+
'address_line3' => 'address_line3-input',
|
59
|
+
'city' => 'city-input',
|
60
|
+
'country_code' => 'country_code-input',
|
61
|
+
'created_at' => 'created_at-input',
|
62
|
+
'id' => 'id-input',
|
63
|
+
'links' => 'links-input',
|
64
|
+
'name' => 'name-input',
|
65
|
+
'postal_code' => 'postal_code-input',
|
66
|
+
'region' => 'region-input'
|
71
67
|
}
|
72
|
-
}.to_json,
|
73
|
-
:headers => {'Content-Type' => 'application/json'}
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "creates and returns the resource" do
|
78
|
-
expect(post_create_response).to be_a(GoCardlessPro::Resources::Creditor)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "with a request that returns a validation error" do
|
83
|
-
let(:new_resource) { {} }
|
84
68
|
|
85
|
-
before do
|
86
|
-
stub_request(:post, %r(.*api.gocardless.com/creditors)).to_return(
|
87
|
-
body: {
|
88
|
-
error: {
|
89
|
-
type: 'validation_failed',
|
90
|
-
code: 422,
|
91
|
-
errors: [
|
92
|
-
{ message: 'test error message', field: 'test_field' }
|
93
|
-
]
|
94
|
-
}
|
95
69
|
}.to_json,
|
96
|
-
headers: {'Content-Type' => 'application/json'}
|
97
|
-
status: 422
|
70
|
+
headers: { 'Content-Type' => 'application/json' }
|
98
71
|
)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "throws the correct error" do
|
102
|
-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
103
|
-
end
|
104
72
|
end
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
73
|
|
110
|
-
|
111
|
-
|
112
|
-
describe "with no filters" do
|
113
|
-
subject(:get_list_response) { client.creditors.list }
|
114
|
-
|
115
|
-
before do
|
116
|
-
stub_request(:get, %r(.*api.gocardless.com/creditors)).to_return(
|
117
|
-
body: {
|
118
|
-
"creditors" => [{
|
119
|
-
|
120
|
-
"address_line1" => "address_line1-input",
|
121
|
-
"address_line2" => "address_line2-input",
|
122
|
-
"address_line3" => "address_line3-input",
|
123
|
-
"city" => "city-input",
|
124
|
-
"country_code" => "country_code-input",
|
125
|
-
"created_at" => "created_at-input",
|
126
|
-
"id" => "id-input",
|
127
|
-
"links" => "links-input",
|
128
|
-
"name" => "name-input",
|
129
|
-
"postal_code" => "postal_code-input",
|
130
|
-
"region" => "region-input",
|
131
|
-
}],
|
132
|
-
meta: {
|
133
|
-
cursors: {
|
134
|
-
before: nil,
|
135
|
-
after: "ABC123"
|
136
|
-
}
|
137
|
-
}
|
138
|
-
}.to_json,
|
139
|
-
:headers => {'Content-Type' => 'application/json'}
|
140
|
-
)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "wraps each item in the resource class" do
|
144
|
-
expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Creditor)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
expect(get_list_response.records.first.address_line1).to eq("address_line1-input")
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
expect(get_list_response.records.first.address_line2).to eq("address_line2-input")
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
expect(get_list_response.records.first.address_line3).to eq("address_line3-input")
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
expect(get_list_response.records.first.city).to eq("city-input")
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
expect(get_list_response.records.first.country_code).to eq("country_code-input")
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
expect(get_list_response.records.first.created_at).to eq("created_at-input")
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
expect(get_list_response.records.first.id).to eq("id-input")
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
expect(get_list_response.records.first.name).to eq("name-input")
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
expect(get_list_response.records.first.postal_code).to eq("postal_code-input")
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
expect(get_list_response.records.first.region).to eq("region-input")
|
187
|
-
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
it "exposes the cursors for before and after" do
|
192
|
-
expect(get_list_response.before).to eq(nil)
|
193
|
-
expect(get_list_response.after).to eq("ABC123")
|
194
|
-
end
|
195
|
-
|
196
|
-
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
74
|
+
it 'creates and returns the resource' do
|
75
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::Creditor)
|
197
76
|
end
|
198
77
|
end
|
199
78
|
|
200
|
-
|
201
|
-
let
|
202
|
-
|
79
|
+
context 'with a request that returns a validation error' do
|
80
|
+
let(:new_resource) { {} }
|
81
|
+
|
82
|
+
before do
|
83
|
+
stub_request(:post, %r{.*api.gocardless.com/creditors}).to_return(
|
203
84
|
body: {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
"country_code" => "country_code-input",
|
211
|
-
"created_at" => "created_at-input",
|
212
|
-
"id" => "id-input",
|
213
|
-
"links" => "links-input",
|
214
|
-
"name" => "name-input",
|
215
|
-
"postal_code" => "postal_code-input",
|
216
|
-
"region" => "region-input",
|
217
|
-
}],
|
218
|
-
meta: {
|
219
|
-
cursors: { after: 'AB345' },
|
220
|
-
limit: 1
|
85
|
+
error: {
|
86
|
+
type: 'validation_failed',
|
87
|
+
code: 422,
|
88
|
+
errors: [
|
89
|
+
{ message: 'test error message', field: 'test_field' }
|
90
|
+
]
|
221
91
|
}
|
222
92
|
}.to_json,
|
223
|
-
:
|
93
|
+
headers: { 'Content-Type' => 'application/json' },
|
94
|
+
status: 422
|
224
95
|
)
|
225
96
|
end
|
226
97
|
|
227
|
-
|
228
|
-
|
98
|
+
it 'throws the correct error' do
|
99
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#list' do
|
105
|
+
describe 'with no filters' do
|
106
|
+
subject(:get_list_response) { client.creditors.list }
|
107
|
+
|
108
|
+
before do
|
109
|
+
stub_request(:get, %r{.*api.gocardless.com/creditors}).to_return(
|
229
110
|
body: {
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
111
|
+
'creditors' => [{
|
112
|
+
|
113
|
+
'address_line1' => 'address_line1-input',
|
114
|
+
'address_line2' => 'address_line2-input',
|
115
|
+
'address_line3' => 'address_line3-input',
|
116
|
+
'city' => 'city-input',
|
117
|
+
'country_code' => 'country_code-input',
|
118
|
+
'created_at' => 'created_at-input',
|
119
|
+
'id' => 'id-input',
|
120
|
+
'links' => 'links-input',
|
121
|
+
'name' => 'name-input',
|
122
|
+
'postal_code' => 'postal_code-input',
|
123
|
+
'region' => 'region-input'
|
243
124
|
}],
|
244
125
|
meta: {
|
245
|
-
|
246
|
-
|
126
|
+
cursors: {
|
127
|
+
before: nil,
|
128
|
+
after: 'ABC123'
|
129
|
+
}
|
247
130
|
}
|
248
131
|
}.to_json,
|
249
|
-
:
|
132
|
+
headers: { 'Content-Type' => 'application/json' }
|
250
133
|
)
|
251
134
|
end
|
252
135
|
|
253
|
-
it
|
254
|
-
expect(
|
255
|
-
|
256
|
-
expect(
|
136
|
+
it 'wraps each item in the resource class' do
|
137
|
+
expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Creditor)
|
138
|
+
|
139
|
+
expect(get_list_response.records.first.address_line1).to eq('address_line1-input')
|
140
|
+
|
141
|
+
expect(get_list_response.records.first.address_line2).to eq('address_line2-input')
|
142
|
+
|
143
|
+
expect(get_list_response.records.first.address_line3).to eq('address_line3-input')
|
144
|
+
|
145
|
+
expect(get_list_response.records.first.city).to eq('city-input')
|
146
|
+
|
147
|
+
expect(get_list_response.records.first.country_code).to eq('country_code-input')
|
148
|
+
|
149
|
+
expect(get_list_response.records.first.created_at).to eq('created_at-input')
|
150
|
+
|
151
|
+
expect(get_list_response.records.first.id).to eq('id-input')
|
152
|
+
|
153
|
+
expect(get_list_response.records.first.name).to eq('name-input')
|
154
|
+
|
155
|
+
expect(get_list_response.records.first.postal_code).to eq('postal_code-input')
|
156
|
+
|
157
|
+
expect(get_list_response.records.first.region).to eq('region-input')
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'exposes the cursors for before and after' do
|
161
|
+
expect(get_list_response.before).to eq(nil)
|
162
|
+
expect(get_list_response.after).to eq('ABC123')
|
257
163
|
end
|
164
|
+
|
165
|
+
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#all' do
|
170
|
+
let!(:first_response_stub) do
|
171
|
+
stub_request(:get, %r{.*api.gocardless.com/creditors$}).to_return(
|
172
|
+
body: {
|
173
|
+
'creditors' => [{
|
174
|
+
|
175
|
+
'address_line1' => 'address_line1-input',
|
176
|
+
'address_line2' => 'address_line2-input',
|
177
|
+
'address_line3' => 'address_line3-input',
|
178
|
+
'city' => 'city-input',
|
179
|
+
'country_code' => 'country_code-input',
|
180
|
+
'created_at' => 'created_at-input',
|
181
|
+
'id' => 'id-input',
|
182
|
+
'links' => 'links-input',
|
183
|
+
'name' => 'name-input',
|
184
|
+
'postal_code' => 'postal_code-input',
|
185
|
+
'region' => 'region-input'
|
186
|
+
}],
|
187
|
+
meta: {
|
188
|
+
cursors: { after: 'AB345' },
|
189
|
+
limit: 1
|
190
|
+
}
|
191
|
+
}.to_json,
|
192
|
+
headers: { 'Content-Type' => 'application/json' }
|
193
|
+
)
|
258
194
|
end
|
259
195
|
|
260
|
-
|
261
|
-
|
262
|
-
|
196
|
+
let!(:second_response_stub) do
|
197
|
+
stub_request(:get, %r{.*api.gocardless.com/creditors\?after=AB345}).to_return(
|
198
|
+
body: {
|
199
|
+
'creditors' => [{
|
200
|
+
|
201
|
+
'address_line1' => 'address_line1-input',
|
202
|
+
'address_line2' => 'address_line2-input',
|
203
|
+
'address_line3' => 'address_line3-input',
|
204
|
+
'city' => 'city-input',
|
205
|
+
'country_code' => 'country_code-input',
|
206
|
+
'created_at' => 'created_at-input',
|
207
|
+
'id' => 'id-input',
|
208
|
+
'links' => 'links-input',
|
209
|
+
'name' => 'name-input',
|
210
|
+
'postal_code' => 'postal_code-input',
|
211
|
+
'region' => 'region-input'
|
212
|
+
}],
|
213
|
+
meta: {
|
214
|
+
limit: 2,
|
215
|
+
cursors: {}
|
216
|
+
}
|
217
|
+
}.to_json,
|
218
|
+
headers: { 'Content-Type' => 'application/json' }
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'automatically makes the extra requests' do
|
223
|
+
expect(client.creditors.all.to_a.length).to eq(2)
|
224
|
+
expect(first_response_stub).to have_been_requested
|
225
|
+
expect(second_response_stub).to have_been_requested
|
226
|
+
end
|
227
|
+
end
|
263
228
|
|
264
|
-
|
265
|
-
|
266
|
-
let(:id) { "ID123" }
|
229
|
+
describe '#get' do
|
230
|
+
let(:id) { 'ID123' }
|
267
231
|
|
268
|
-
|
232
|
+
subject(:get_response) { client.creditors.get(id) }
|
269
233
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
with(headers: { 'Foo' => 'Bar' })
|
275
|
-
to_return(
|
234
|
+
context 'passing in a custom header' do
|
235
|
+
let!(:stub) do
|
236
|
+
stub_url = '/creditors/:identity'.gsub(':identity', id)
|
237
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/)
|
238
|
+
.with(headers: { 'Foo' => 'Bar' })
|
239
|
+
.to_return(
|
276
240
|
body: {
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
241
|
+
'creditors' => {
|
242
|
+
|
243
|
+
'address_line1' => 'address_line1-input',
|
244
|
+
'address_line2' => 'address_line2-input',
|
245
|
+
'address_line3' => 'address_line3-input',
|
246
|
+
'city' => 'city-input',
|
247
|
+
'country_code' => 'country_code-input',
|
248
|
+
'created_at' => 'created_at-input',
|
249
|
+
'id' => 'id-input',
|
250
|
+
'links' => 'links-input',
|
251
|
+
'name' => 'name-input',
|
252
|
+
'postal_code' => 'postal_code-input',
|
253
|
+
'region' => 'region-input'
|
290
254
|
}
|
291
255
|
}.to_json,
|
292
|
-
:
|
256
|
+
headers: { 'Content-Type' => 'application/json' }
|
293
257
|
)
|
294
|
-
end
|
295
|
-
|
296
|
-
subject(:get_response) do
|
297
|
-
client.creditors.get(id, headers: {
|
298
|
-
'Foo' => 'Bar'
|
299
|
-
})
|
300
|
-
end
|
301
|
-
|
302
|
-
it "includes the header" do
|
303
|
-
get_response
|
304
|
-
expect(stub).to have_been_requested
|
305
|
-
end
|
306
258
|
end
|
307
259
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
"creditors" => {
|
314
|
-
|
315
|
-
"address_line1" => "address_line1-input",
|
316
|
-
"address_line2" => "address_line2-input",
|
317
|
-
"address_line3" => "address_line3-input",
|
318
|
-
"city" => "city-input",
|
319
|
-
"country_code" => "country_code-input",
|
320
|
-
"created_at" => "created_at-input",
|
321
|
-
"id" => "id-input",
|
322
|
-
"links" => "links-input",
|
323
|
-
"name" => "name-input",
|
324
|
-
"postal_code" => "postal_code-input",
|
325
|
-
"region" => "region-input",
|
326
|
-
}
|
327
|
-
}.to_json,
|
328
|
-
:headers => {'Content-Type' => 'application/json'}
|
329
|
-
)
|
330
|
-
end
|
260
|
+
subject(:get_response) do
|
261
|
+
client.creditors.get(id, headers: {
|
262
|
+
'Foo' => 'Bar'
|
263
|
+
})
|
264
|
+
end
|
331
265
|
|
332
|
-
|
333
|
-
|
334
|
-
|
266
|
+
it 'includes the header' do
|
267
|
+
get_response
|
268
|
+
expect(stub).to have_been_requested
|
335
269
|
end
|
270
|
+
end
|
336
271
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
272
|
+
context 'when there is a creditor to return' do
|
273
|
+
before do
|
274
|
+
stub_url = '/creditors/:identity'.gsub(':identity', id)
|
275
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
276
|
+
body: {
|
277
|
+
'creditors' => {
|
278
|
+
|
279
|
+
'address_line1' => 'address_line1-input',
|
280
|
+
'address_line2' => 'address_line2-input',
|
281
|
+
'address_line3' => 'address_line3-input',
|
282
|
+
'city' => 'city-input',
|
283
|
+
'country_code' => 'country_code-input',
|
284
|
+
'created_at' => 'created_at-input',
|
285
|
+
'id' => 'id-input',
|
286
|
+
'links' => 'links-input',
|
287
|
+
'name' => 'name-input',
|
288
|
+
'postal_code' => 'postal_code-input',
|
289
|
+
'region' => 'region-input'
|
290
|
+
}
|
291
|
+
}.to_json,
|
292
|
+
headers: { 'Content-Type' => 'application/json' }
|
293
|
+
)
|
294
|
+
end
|
345
295
|
|
346
|
-
|
347
|
-
|
348
|
-
end
|
296
|
+
it 'wraps the response in a resource' do
|
297
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::Creditor)
|
349
298
|
end
|
350
299
|
end
|
351
300
|
|
352
|
-
|
353
|
-
|
354
|
-
|
301
|
+
context 'when nothing is returned' do
|
302
|
+
before do
|
303
|
+
stub_url = '/creditors/:identity'.gsub(':identity', id)
|
304
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
305
|
+
body: '',
|
306
|
+
headers: { 'Content-Type' => 'application/json' }
|
307
|
+
)
|
308
|
+
end
|
355
309
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
310
|
+
it 'returns nil' do
|
311
|
+
expect(get_response).to be_nil
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
360
315
|
|
361
|
-
|
362
|
-
|
316
|
+
describe '#update' do
|
317
|
+
subject(:put_update_response) { client.creditors.update(id, params: update_params) }
|
318
|
+
let(:id) { 'ABC123' }
|
363
319
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
320
|
+
context 'with a valid request' do
|
321
|
+
let(:update_params) { { 'hello' => 'world' } }
|
322
|
+
|
323
|
+
let!(:stub) do
|
324
|
+
stub_url = '/creditors/:identity'.gsub(':identity', id)
|
325
|
+
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
326
|
+
body: {
|
327
|
+
'creditors' => {
|
328
|
+
|
329
|
+
'address_line1' => 'address_line1-input',
|
330
|
+
'address_line2' => 'address_line2-input',
|
331
|
+
'address_line3' => 'address_line3-input',
|
332
|
+
'city' => 'city-input',
|
333
|
+
'country_code' => 'country_code-input',
|
334
|
+
'created_at' => 'created_at-input',
|
335
|
+
'id' => 'id-input',
|
336
|
+
'links' => 'links-input',
|
337
|
+
'name' => 'name-input',
|
338
|
+
'postal_code' => 'postal_code-input',
|
339
|
+
'region' => 'region-input'
|
340
|
+
}
|
341
|
+
}.to_json,
|
342
|
+
headers: { 'Content-Type' => 'application/json' }
|
343
|
+
)
|
344
|
+
end
|
386
345
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
end
|
346
|
+
it 'updates and returns the resource' do
|
347
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::Creditor)
|
348
|
+
expect(stub).to have_been_requested
|
391
349
|
end
|
392
350
|
end
|
393
|
-
|
394
|
-
|
351
|
+
end
|
395
352
|
end
|