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.
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
@@ -3,221 +3,198 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::PayoutsService 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
-
10
+ describe '#list' do
11
+ describe 'with no filters' do
12
+ subject(:get_list_response) { client.payouts.list }
14
13
 
15
-
16
- describe "#list" do
17
- describe "with no filters" do
18
- subject(:get_list_response) { client.payouts.list }
19
-
20
- before do
21
- stub_request(:get, %r(.*api.gocardless.com/payouts)).to_return(
22
- body: {
23
- "payouts" => [{
24
-
25
- "amount" => "amount-input",
26
- "created_at" => "created_at-input",
27
- "currency" => "currency-input",
28
- "id" => "id-input",
29
- "links" => "links-input",
30
- "reference" => "reference-input",
31
- "status" => "status-input",
32
- }],
33
- meta: {
34
- cursors: {
35
- before: nil,
36
- after: "ABC123"
37
- }
38
- }
39
- }.to_json,
40
- :headers => {'Content-Type' => 'application/json'}
41
- )
42
- end
43
-
44
- it "wraps each item in the resource class" do
45
- expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Payout)
46
-
47
-
48
-
49
- expect(get_list_response.records.first.amount).to eq("amount-input")
50
-
51
-
52
-
53
- expect(get_list_response.records.first.created_at).to eq("created_at-input")
54
-
55
-
56
-
57
- expect(get_list_response.records.first.currency).to eq("currency-input")
58
-
59
-
60
-
61
- expect(get_list_response.records.first.id).to eq("id-input")
62
-
63
-
64
-
65
-
66
-
67
- expect(get_list_response.records.first.reference).to eq("reference-input")
68
-
69
-
70
-
71
- expect(get_list_response.records.first.status).to eq("status-input")
72
-
73
-
74
- end
75
-
76
- it "exposes the cursors for before and after" do
77
- expect(get_list_response.before).to eq(nil)
78
- expect(get_list_response.after).to eq("ABC123")
79
- end
80
-
81
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
82
- end
83
- end
84
-
85
- describe "#all" do
86
- let!(:first_response_stub) do
87
- stub_request(:get, %r(.*api.gocardless.com/payouts$)).to_return(
14
+ before do
15
+ stub_request(:get, %r{.*api.gocardless.com/payouts}).to_return(
88
16
  body: {
89
- "payouts" => [{
90
-
91
- "amount" => "amount-input",
92
- "created_at" => "created_at-input",
93
- "currency" => "currency-input",
94
- "id" => "id-input",
95
- "links" => "links-input",
96
- "reference" => "reference-input",
97
- "status" => "status-input",
17
+ 'payouts' => [{
18
+
19
+ 'amount' => 'amount-input',
20
+ 'arrival_date' => 'arrival_date-input',
21
+ 'created_at' => 'created_at-input',
22
+ 'currency' => 'currency-input',
23
+ 'id' => 'id-input',
24
+ 'links' => 'links-input',
25
+ 'reference' => 'reference-input',
26
+ 'status' => 'status-input'
98
27
  }],
99
28
  meta: {
100
- cursors: { after: 'AB345' },
101
- limit: 1
29
+ cursors: {
30
+ before: nil,
31
+ after: 'ABC123'
32
+ }
102
33
  }
103
34
  }.to_json,
104
- :headers => {'Content-Type' => 'application/json'}
35
+ headers: { 'Content-Type' => 'application/json' }
105
36
  )
106
37
  end
107
38
 
108
- let!(:second_response_stub) do
109
- stub_request(:get, %r(.*api.gocardless.com/payouts\?after=AB345)).to_return(
110
- body: {
111
- "payouts" => [{
112
-
113
- "amount" => "amount-input",
114
- "created_at" => "created_at-input",
115
- "currency" => "currency-input",
116
- "id" => "id-input",
117
- "links" => "links-input",
118
- "reference" => "reference-input",
119
- "status" => "status-input",
120
- }],
121
- meta: {
122
- limit: 2,
123
- cursors: {}
124
- }
125
- }.to_json,
126
- :headers => {'Content-Type' => 'application/json'}
127
- )
39
+ it 'wraps each item in the resource class' do
40
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Payout)
41
+
42
+ expect(get_list_response.records.first.amount).to eq('amount-input')
43
+
44
+ expect(get_list_response.records.first.arrival_date).to eq('arrival_date-input')
45
+
46
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
47
+
48
+ expect(get_list_response.records.first.currency).to eq('currency-input')
49
+
50
+ expect(get_list_response.records.first.id).to eq('id-input')
51
+
52
+ expect(get_list_response.records.first.reference).to eq('reference-input')
53
+
54
+ expect(get_list_response.records.first.status).to eq('status-input')
128
55
  end
129
56
 
130
- it "automatically makes the extra requests" do
131
- expect(client.payouts.all.to_a.length).to eq(2)
132
- expect(first_response_stub).to have_been_requested
133
- expect(second_response_stub).to have_been_requested
57
+ it 'exposes the cursors for before and after' do
58
+ expect(get_list_response.before).to eq(nil)
59
+ expect(get_list_response.after).to eq('ABC123')
134
60
  end
61
+
62
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
135
63
  end
64
+ end
136
65
 
137
-
138
-
139
-
66
+ describe '#all' do
67
+ let!(:first_response_stub) do
68
+ stub_request(:get, %r{.*api.gocardless.com/payouts$}).to_return(
69
+ body: {
70
+ 'payouts' => [{
71
+
72
+ 'amount' => 'amount-input',
73
+ 'arrival_date' => 'arrival_date-input',
74
+ 'created_at' => 'created_at-input',
75
+ 'currency' => 'currency-input',
76
+ 'id' => 'id-input',
77
+ 'links' => 'links-input',
78
+ 'reference' => 'reference-input',
79
+ 'status' => 'status-input'
80
+ }],
81
+ meta: {
82
+ cursors: { after: 'AB345' },
83
+ limit: 1
84
+ }
85
+ }.to_json,
86
+ headers: { 'Content-Type' => 'application/json' }
87
+ )
88
+ end
140
89
 
141
-
142
- describe "#get" do
143
- let(:id) { "ID123" }
90
+ let!(:second_response_stub) do
91
+ stub_request(:get, %r{.*api.gocardless.com/payouts\?after=AB345}).to_return(
92
+ body: {
93
+ 'payouts' => [{
94
+
95
+ 'amount' => 'amount-input',
96
+ 'arrival_date' => 'arrival_date-input',
97
+ 'created_at' => 'created_at-input',
98
+ 'currency' => 'currency-input',
99
+ 'id' => 'id-input',
100
+ 'links' => 'links-input',
101
+ 'reference' => 'reference-input',
102
+ 'status' => 'status-input'
103
+ }],
104
+ meta: {
105
+ limit: 2,
106
+ cursors: {}
107
+ }
108
+ }.to_json,
109
+ headers: { 'Content-Type' => 'application/json' }
110
+ )
111
+ end
144
112
 
145
- subject(:get_response) { client.payouts.get(id) }
113
+ it 'automatically makes the extra requests' do
114
+ expect(client.payouts.all.to_a.length).to eq(2)
115
+ expect(first_response_stub).to have_been_requested
116
+ expect(second_response_stub).to have_been_requested
117
+ end
118
+ end
119
+
120
+ describe '#get' do
121
+ let(:id) { 'ID123' }
146
122
 
147
- context "passing in a custom header" do
148
- let!(:stub) do
149
- stub_url = "/payouts/:identity".gsub(':identity', id)
150
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
151
- with(headers: { 'Foo' => 'Bar' }).
152
- to_return(
123
+ subject(:get_response) { client.payouts.get(id) }
124
+
125
+ context 'passing in a custom header' do
126
+ let!(:stub) do
127
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
128
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/)
129
+ .with(headers: { 'Foo' => 'Bar' })
130
+ .to_return(
153
131
  body: {
154
- "payouts" => {
155
-
156
- "amount" => "amount-input",
157
- "created_at" => "created_at-input",
158
- "currency" => "currency-input",
159
- "id" => "id-input",
160
- "links" => "links-input",
161
- "reference" => "reference-input",
162
- "status" => "status-input",
132
+ 'payouts' => {
133
+
134
+ 'amount' => 'amount-input',
135
+ 'arrival_date' => 'arrival_date-input',
136
+ 'created_at' => 'created_at-input',
137
+ 'currency' => 'currency-input',
138
+ 'id' => 'id-input',
139
+ 'links' => 'links-input',
140
+ 'reference' => 'reference-input',
141
+ 'status' => 'status-input'
163
142
  }
164
143
  }.to_json,
165
- :headers => {'Content-Type' => 'application/json'}
144
+ headers: { 'Content-Type' => 'application/json' }
166
145
  )
167
- end
168
-
169
- subject(:get_response) do
170
- client.payouts.get(id, headers: {
171
- 'Foo' => 'Bar'
172
- })
173
- end
174
-
175
- it "includes the header" do
176
- get_response
177
- expect(stub).to have_been_requested
178
- end
179
146
  end
180
147
 
181
- context "when there is a payout to return" do
182
- before do
183
- stub_url = "/payouts/:identity".gsub(':identity', id)
184
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
185
- body: {
186
- "payouts" => {
187
-
188
- "amount" => "amount-input",
189
- "created_at" => "created_at-input",
190
- "currency" => "currency-input",
191
- "id" => "id-input",
192
- "links" => "links-input",
193
- "reference" => "reference-input",
194
- "status" => "status-input",
195
- }
196
- }.to_json,
197
- :headers => {'Content-Type' => 'application/json'}
198
- )
199
- end
148
+ subject(:get_response) do
149
+ client.payouts.get(id, headers: {
150
+ 'Foo' => 'Bar'
151
+ })
152
+ end
200
153
 
201
- it "wraps the response in a resource" do
202
- expect(get_response).to be_a(GoCardlessPro::Resources::Payout)
203
- end
154
+ it 'includes the header' do
155
+ get_response
156
+ expect(stub).to have_been_requested
204
157
  end
158
+ end
205
159
 
206
- context "when nothing is returned" do
207
- before do
208
- stub_url = "/payouts/:identity".gsub(':identity', id)
209
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
210
- body: "",
211
- headers: { 'Content-Type' => 'application/json' }
212
- )
213
- end
160
+ context 'when there is a payout to return' do
161
+ before do
162
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
163
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
164
+ body: {
165
+ 'payouts' => {
166
+
167
+ 'amount' => 'amount-input',
168
+ 'arrival_date' => 'arrival_date-input',
169
+ 'created_at' => 'created_at-input',
170
+ 'currency' => 'currency-input',
171
+ 'id' => 'id-input',
172
+ 'links' => 'links-input',
173
+ 'reference' => 'reference-input',
174
+ 'status' => 'status-input'
175
+ }
176
+ }.to_json,
177
+ headers: { 'Content-Type' => 'application/json' }
178
+ )
179
+ end
214
180
 
215
- it "returns nil" do
216
- expect(get_response).to be_nil
217
- end
181
+ it 'wraps the response in a resource' do
182
+ expect(get_response).to be_a(GoCardlessPro::Resources::Payout)
218
183
  end
219
184
  end
220
185
 
221
-
222
-
186
+ context 'when nothing is returned' do
187
+ before do
188
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
189
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
190
+ body: '',
191
+ headers: { 'Content-Type' => 'application/json' }
192
+ )
193
+ end
194
+
195
+ it 'returns nil' do
196
+ expect(get_response).to be_nil
197
+ end
198
+ end
199
+ end
223
200
  end
@@ -3,256 +3,239 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::RedirectFlowsService 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.redirect_flows.create(params: new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "created_at" => "created_at-input",
23
- "description" => "description-input",
24
- "id" => "id-input",
25
- "links" => "links-input",
26
- "redirect_url" => "redirect_url-input",
27
- "scheme" => "scheme-input",
28
- "session_token" => "session_token-input",
29
- "success_redirect_url" => "success_redirect_url-input",
30
- }
31
- end
12
+ context 'with a valid request' do
13
+ let(:new_resource) do
14
+ {
15
+
16
+ 'created_at' => 'created_at-input',
17
+ 'description' => 'description-input',
18
+ 'id' => 'id-input',
19
+ 'links' => 'links-input',
20
+ 'redirect_url' => 'redirect_url-input',
21
+ 'scheme' => 'scheme-input',
22
+ 'session_token' => 'session_token-input',
23
+ 'success_redirect_url' => 'success_redirect_url-input'
24
+ }
25
+ end
32
26
 
33
- before do
34
- stub_request(:post, %r(.*api.gocardless.com/redirect_flows)).
35
- with(
27
+ before do
28
+ stub_request(:post, %r{.*api.gocardless.com/redirect_flows})
29
+ .with(
36
30
  body: {
37
- "redirect_flows" => {
38
-
39
- "created_at" => "created_at-input",
40
- "description" => "description-input",
41
- "id" => "id-input",
42
- "links" => "links-input",
43
- "redirect_url" => "redirect_url-input",
44
- "scheme" => "scheme-input",
45
- "session_token" => "session_token-input",
46
- "success_redirect_url" => "success_redirect_url-input",
47
- }
31
+ 'redirect_flows' => {
32
+
33
+ 'created_at' => 'created_at-input',
34
+ 'description' => 'description-input',
35
+ 'id' => 'id-input',
36
+ 'links' => 'links-input',
37
+ 'redirect_url' => 'redirect_url-input',
38
+ 'scheme' => 'scheme-input',
39
+ 'session_token' => 'session_token-input',
40
+ 'success_redirect_url' => 'success_redirect_url-input'
41
+ }
48
42
  }
49
- ).
50
- to_return(
43
+ )
44
+ .to_return(
51
45
  body: {
52
- "redirect_flows" => {
53
-
54
- "created_at" => "created_at-input",
55
- "description" => "description-input",
56
- "id" => "id-input",
57
- "links" => "links-input",
58
- "redirect_url" => "redirect_url-input",
59
- "scheme" => "scheme-input",
60
- "session_token" => "session_token-input",
61
- "success_redirect_url" => "success_redirect_url-input",
46
+ 'redirect_flows' =>
47
+
48
+ {
49
+
50
+ 'created_at' => 'created_at-input',
51
+ 'description' => 'description-input',
52
+ 'id' => 'id-input',
53
+ 'links' => 'links-input',
54
+ 'redirect_url' => 'redirect_url-input',
55
+ 'scheme' => 'scheme-input',
56
+ 'session_token' => 'session_token-input',
57
+ 'success_redirect_url' => 'success_redirect_url-input'
62
58
  }
59
+
63
60
  }.to_json,
64
- :headers => {'Content-Type' => 'application/json'}
61
+ headers: { 'Content-Type' => 'application/json' }
65
62
  )
66
- end
63
+ end
67
64
 
68
- it "creates and returns the resource" do
69
- expect(post_create_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
70
- end
65
+ it 'creates and returns the resource' do
66
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
71
67
  end
68
+ end
72
69
 
73
- context "with a request that returns a validation error" do
74
- let(:new_resource) { {} }
70
+ context 'with a request that returns a validation error' do
71
+ let(:new_resource) { {} }
75
72
 
76
- before do
77
- stub_request(:post, %r(.*api.gocardless.com/redirect_flows)).to_return(
78
- body: {
79
- error: {
80
- type: 'validation_failed',
81
- code: 422,
82
- errors: [
83
- { message: 'test error message', field: 'test_field' }
84
- ]
85
- }
86
- }.to_json,
87
- headers: {'Content-Type' => 'application/json'},
88
- status: 422
89
- )
90
- end
73
+ before do
74
+ stub_request(:post, %r{.*api.gocardless.com/redirect_flows}).to_return(
75
+ body: {
76
+ error: {
77
+ type: 'validation_failed',
78
+ code: 422,
79
+ errors: [
80
+ { message: 'test error message', field: 'test_field' }
81
+ ]
82
+ }
83
+ }.to_json,
84
+ headers: { 'Content-Type' => 'application/json' },
85
+ status: 422
86
+ )
87
+ end
91
88
 
92
- it "throws the correct error" do
93
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
94
- end
89
+ it 'throws the correct error' do
90
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
95
91
  end
96
92
  end
97
-
98
-
99
-
100
-
101
-
102
- describe "#get" do
103
- let(:id) { "ID123" }
104
-
105
- subject(:get_response) { client.redirect_flows.get(id) }
106
-
107
- context "passing in a custom header" do
108
- let!(:stub) do
109
- stub_url = "/redirect_flows/:identity".gsub(':identity', id)
110
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
111
- with(headers: { 'Foo' => 'Bar' }).
112
- to_return(
113
- body: {
114
- "redirect_flows" => {
115
-
116
- "created_at" => "created_at-input",
117
- "description" => "description-input",
118
- "id" => "id-input",
119
- "links" => "links-input",
120
- "redirect_url" => "redirect_url-input",
121
- "scheme" => "scheme-input",
122
- "session_token" => "session_token-input",
123
- "success_redirect_url" => "success_redirect_url-input",
124
- }
125
- }.to_json,
126
- :headers => {'Content-Type' => 'application/json'}
127
- )
128
- end
129
-
130
- subject(:get_response) do
131
- client.redirect_flows.get(id, headers: {
132
- 'Foo' => 'Bar'
133
- })
134
- end
135
-
136
- it "includes the header" do
137
- get_response
138
- expect(stub).to have_been_requested
139
- end
140
- end
93
+ end
94
+
95
+ describe '#get' do
96
+ let(:id) { 'ID123' }
141
97
 
142
- context "when there is a redirect_flow to return" do
143
- before do
144
- stub_url = "/redirect_flows/:identity".gsub(':identity', id)
145
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
98
+ subject(:get_response) { client.redirect_flows.get(id) }
99
+
100
+ context 'passing in a custom header' do
101
+ let!(:stub) do
102
+ stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
103
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/)
104
+ .with(headers: { 'Foo' => 'Bar' })
105
+ .to_return(
146
106
  body: {
147
- "redirect_flows" => {
148
-
149
- "created_at" => "created_at-input",
150
- "description" => "description-input",
151
- "id" => "id-input",
152
- "links" => "links-input",
153
- "redirect_url" => "redirect_url-input",
154
- "scheme" => "scheme-input",
155
- "session_token" => "session_token-input",
156
- "success_redirect_url" => "success_redirect_url-input",
107
+ 'redirect_flows' => {
108
+
109
+ 'created_at' => 'created_at-input',
110
+ 'description' => 'description-input',
111
+ 'id' => 'id-input',
112
+ 'links' => 'links-input',
113
+ 'redirect_url' => 'redirect_url-input',
114
+ 'scheme' => 'scheme-input',
115
+ 'session_token' => 'session_token-input',
116
+ 'success_redirect_url' => 'success_redirect_url-input'
157
117
  }
158
118
  }.to_json,
159
- :headers => {'Content-Type' => 'application/json'}
119
+ headers: { 'Content-Type' => 'application/json' }
160
120
  )
161
- end
162
-
163
- it "wraps the response in a resource" do
164
- expect(get_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
165
- end
166
121
  end
167
122
 
168
- context "when nothing is returned" do
169
- before do
170
- stub_url = "/redirect_flows/:identity".gsub(':identity', id)
171
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
172
- body: "",
173
- headers: { 'Content-Type' => 'application/json' }
174
- )
175
- end
123
+ subject(:get_response) do
124
+ client.redirect_flows.get(id, headers: {
125
+ 'Foo' => 'Bar'
126
+ })
127
+ end
176
128
 
177
- it "returns nil" do
178
- expect(get_response).to be_nil
179
- end
129
+ it 'includes the header' do
130
+ get_response
131
+ expect(stub).to have_been_requested
180
132
  end
181
133
  end
182
134
 
183
-
184
-
185
-
186
-
187
-
188
- describe "#complete" do
189
-
190
-
191
- subject(:post_response) { client.redirect_flows.complete(resource_id) }
192
-
193
- let(:resource_id) { "ABC123" }
194
-
195
- let!(:stub) do
196
- # /redirect_flows/%v/actions/complete
197
- stub_url = "/redirect_flows/:identity/actions/complete".gsub(':identity', resource_id)
198
- stub_request(:post, %r(.*api.gocardless.com#{stub_url})).to_return(
135
+ context 'when there is a redirect_flow to return' do
136
+ before do
137
+ stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
138
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
199
139
  body: {
200
- "redirect_flows" => {
201
-
202
- "created_at" => "created_at-input",
203
- "description" => "description-input",
204
- "id" => "id-input",
205
- "links" => "links-input",
206
- "redirect_url" => "redirect_url-input",
207
- "scheme" => "scheme-input",
208
- "session_token" => "session_token-input",
209
- "success_redirect_url" => "success_redirect_url-input",
140
+ 'redirect_flows' => {
141
+
142
+ 'created_at' => 'created_at-input',
143
+ 'description' => 'description-input',
144
+ 'id' => 'id-input',
145
+ 'links' => 'links-input',
146
+ 'redirect_url' => 'redirect_url-input',
147
+ 'scheme' => 'scheme-input',
148
+ 'session_token' => 'session_token-input',
149
+ 'success_redirect_url' => 'success_redirect_url-input'
210
150
  }
211
151
  }.to_json,
212
- headers: {'Content-Type' => 'application/json'},
152
+ headers: { 'Content-Type' => 'application/json' }
213
153
  )
214
154
  end
215
155
 
216
- it "wraps the response and calls the right endpoint" do
217
- expect(post_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
156
+ it 'wraps the response in a resource' do
157
+ expect(get_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
158
+ end
159
+ end
218
160
 
219
- expect(stub).to have_been_requested
161
+ context 'when nothing is returned' do
162
+ before do
163
+ stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
164
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
165
+ body: '',
166
+ headers: { 'Content-Type' => 'application/json' }
167
+ )
220
168
  end
221
169
 
222
- context "when the request needs a body and custom header" do
223
-
224
- let(:body) { { foo: 'bar' } }
225
- let(:headers) { { 'Foo' => 'Bar' } }
226
- subject(:post_response) { client.redirect_flows.complete(resource_id, body, headers) }
227
-
228
- let(:resource_id) { "ABC123" }
229
-
230
- let!(:stub) do
231
- # /redirect_flows/%v/actions/complete
232
- stub_url = "/redirect_flows/:identity/actions/complete".gsub(':identity', resource_id)
233
- stub_request(:post, %r(.*api.gocardless.com#{stub_url})).
234
- with(
170
+ it 'returns nil' do
171
+ expect(get_response).to be_nil
172
+ end
173
+ end
174
+ end
175
+
176
+ describe '#complete' do
177
+ subject(:post_response) { client.redirect_flows.complete(resource_id) }
178
+
179
+ let(:resource_id) { 'ABC123' }
180
+
181
+ let!(:stub) do
182
+ # /redirect_flows/%v/actions/complete
183
+ stub_url = '/redirect_flows/:identity/actions/complete'.gsub(':identity', resource_id)
184
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
185
+ body: {
186
+ 'redirect_flows' => {
187
+
188
+ 'created_at' => 'created_at-input',
189
+ 'description' => 'description-input',
190
+ 'id' => 'id-input',
191
+ 'links' => 'links-input',
192
+ 'redirect_url' => 'redirect_url-input',
193
+ 'scheme' => 'scheme-input',
194
+ 'session_token' => 'session_token-input',
195
+ 'success_redirect_url' => 'success_redirect_url-input'
196
+ }
197
+ }.to_json,
198
+ headers: { 'Content-Type' => 'application/json' }
199
+ )
200
+ end
201
+
202
+ it 'wraps the response and calls the right endpoint' do
203
+ expect(post_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
204
+
205
+ expect(stub).to have_been_requested
206
+ end
207
+
208
+ context 'when the request needs a body and custom header' do
209
+ let(:body) { { foo: 'bar' } }
210
+ let(:headers) { { 'Foo' => 'Bar' } }
211
+ subject(:post_response) { client.redirect_flows.complete(resource_id, body, headers) }
212
+
213
+ let(:resource_id) { 'ABC123' }
214
+
215
+ let!(:stub) do
216
+ # /redirect_flows/%v/actions/complete
217
+ stub_url = '/redirect_flows/:identity/actions/complete'.gsub(':identity', resource_id)
218
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/)
219
+ .with(
235
220
  body: { foo: 'bar' },
236
221
  headers: { 'Foo' => 'Bar' }
237
222
  ).to_return(
238
223
  body: {
239
- "redirect_flows" => {
240
-
241
- "created_at" => "created_at-input",
242
- "description" => "description-input",
243
- "id" => "id-input",
244
- "links" => "links-input",
245
- "redirect_url" => "redirect_url-input",
246
- "scheme" => "scheme-input",
247
- "session_token" => "session_token-input",
248
- "success_redirect_url" => "success_redirect_url-input",
224
+ 'redirect_flows' => {
225
+
226
+ 'created_at' => 'created_at-input',
227
+ 'description' => 'description-input',
228
+ 'id' => 'id-input',
229
+ 'links' => 'links-input',
230
+ 'redirect_url' => 'redirect_url-input',
231
+ 'scheme' => 'scheme-input',
232
+ 'session_token' => 'session_token-input',
233
+ 'success_redirect_url' => 'success_redirect_url-input'
249
234
  }
250
235
  }.to_json,
251
- headers: {'Content-Type' => 'application/json'},
236
+ headers: { 'Content-Type' => 'application/json' }
252
237
  )
253
- end
254
238
  end
255
239
  end
256
-
257
-
240
+ end
258
241
  end