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