gocardless_pro 1.0.3 → 1.0.4

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