yodlee_wrap 0.0.0 → 0.0.2

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.
@@ -1,341 +0,0 @@
1
- require "yodleeicious"
2
- require "yodleeicious/config"
3
-
4
- describe Yodleeicious::YodleeApi do
5
-
6
- context 'Given a new uninitialized YodleeApi object' do
7
- before {
8
- Yodleeicious::Config.base_url=nil
9
- Yodleeicious::Config.cobranded_username=nil
10
- Yodleeicious::Config.cobranded_password=nil
11
- Yodleeicious::Config.proxy_url=nil
12
- }
13
- subject { Yodleeicious::YodleeApi.new }
14
-
15
- it 'should return nil for cobranded_auth' do
16
- expect(subject.cobranded_auth).to be_nil
17
- end
18
-
19
- it 'should return nil for user_auth' do
20
- expect(subject.user_auth).to be_nil
21
- end
22
-
23
- it 'should return nil for session_token' do
24
- expect(subject.cobranded_session_token).to be_nil
25
- end
26
-
27
- it 'should return nil for user_session_token' do
28
- expect(subject.user_session_token).to be_nil
29
- end
30
-
31
- it 'should return a translator' do
32
- expect(subject.translator).not_to be_nil
33
- end
34
- end
35
-
36
- context 'Given a Yodleeicious::Config with nil configuration' do
37
- context 'When a new YodleeApi instance is created with no configuration' do
38
- before {
39
- Yodleeicious::Config.base_url=nil
40
- Yodleeicious::Config.cobranded_username=nil
41
- Yodleeicious::Config.cobranded_password=nil
42
- Yodleeicious::Config.proxy_url=nil
43
- }
44
- subject { Yodleeicious::YodleeApi.new }
45
-
46
- it 'no base_url set' do
47
- expect(subject.base_url).to be_nil
48
- end
49
-
50
- it 'no cobranded_username is set' do
51
- expect(subject.cobranded_username).to be_nil
52
- end
53
-
54
- it 'no cobranded_password is set' do
55
- expect(subject.cobranded_password).to be_nil
56
- end
57
-
58
- it 'no proxy_url is set' do
59
- expect(subject.proxy_url).to be_nil
60
- end
61
-
62
- it 'empty proxy_opts are created' do
63
- expect(subject.proxy_opts).to eq({})
64
- end
65
-
66
- it 'no socks proxy is used' do
67
- expect(subject.use_socks?).to eq(false)
68
- end
69
- end
70
- end
71
-
72
- context 'Given a Yodleeicious::Config with a configuration' do
73
- context 'When a new YodleeApi instance is created with the global configuration set' do
74
- before {
75
- Yodleeicious::Config.base_url='base url'
76
- Yodleeicious::Config.cobranded_username='user name'
77
- Yodleeicious::Config.cobranded_password='password'
78
- Yodleeicious::Config.proxy_url='socks5h://somehostname'
79
- }
80
- subject { Yodleeicious::YodleeApi.new }
81
-
82
- it 'base_url set' do
83
- expect(subject.base_url).to eq('base url')
84
- end
85
-
86
- it 'cobranded_username is set' do
87
- expect(subject.cobranded_username).to eq('user name')
88
- end
89
-
90
- it 'cobranded_password is set' do
91
- expect(subject.cobranded_password).to eq('password')
92
- end
93
-
94
- it 'proxy_url is set' do
95
- expect(subject.proxy_url).to eq('socks5h://somehostname')
96
- end
97
-
98
- it 'proxy_opts are created' do
99
- expect(subject.proxy_opts).to eq({ socks: true, uri: URI.parse('socks5h://somehostname') })
100
- end
101
-
102
- it 'socks proxy is used' do
103
- expect(subject.use_socks?).to eq(true)
104
- end
105
- end
106
- end
107
-
108
- context 'Given a Yodleeicious::Config with nil configuration' do
109
- context 'When a new YodleeApi instance is created and provided a configuration' do
110
- before {
111
- Yodleeicious::Config.base_url=nil
112
- Yodleeicious::Config.cobranded_username=nil
113
- Yodleeicious::Config.cobranded_password=nil
114
- Yodleeicious::Config.proxy_url=nil
115
- }
116
- let(:config) {
117
- {
118
- base_url: "https://rest.developer.yodlee.com/services/srest/restserver/v1.0",
119
- cobranded_username: "some_username",
120
- cobranded_password: "some_password",
121
- proxy_url: "socks5h://127.0.0.1:1080"
122
- }
123
- }
124
-
125
- subject { Yodleeicious::YodleeApi.new(config) }
126
-
127
- it 'the provided base url is set' do
128
- expect(subject.base_url).to eq(config[:base_url])
129
- end
130
-
131
- it 'the provided cobranded_username is set' do
132
- expect(subject.cobranded_username).to eq(config[:cobranded_username])
133
- end
134
-
135
- it 'the provided cobranded_password is set' do
136
- expect(subject.cobranded_password).to eq(config[:cobranded_password])
137
- end
138
-
139
- it 'the provided proxy_url is set' do
140
- expect(subject.proxy_url).to eq(config[:proxy_url])
141
- end
142
-
143
- it 'the provided proxy_opts are created' do
144
- proxy_opts = {
145
- socks: true,
146
- uri: URI.parse(config[:proxy_url])
147
- }
148
- expect(subject.proxy_opts).to eq(proxy_opts)
149
- end
150
-
151
- it 'the provided socks proxy is used' do
152
- expect(subject.use_socks?).to eq(true)
153
- end
154
- end
155
- end
156
-
157
- context 'Given a Yodleeicious::Config with set config values' do
158
- context 'When a new YodleeApi instance is created and provided a configuration' do
159
- before {
160
- Yodleeicious::Config.base_url='base url'
161
- Yodleeicious::Config.cobranded_username='user name'
162
- Yodleeicious::Config.cobranded_password='password'
163
- Yodleeicious::Config.proxy_url='socks5h://somehostname'
164
- }
165
- let(:config) {
166
- {
167
- base_url: "https://rest.developer.yodlee.com/services/srest/restserver/v1.0",
168
- cobranded_username: "some_username",
169
- cobranded_password: "some_password",
170
- proxy_url: "socks5h://127.0.0.1:1080"
171
- }
172
- }
173
-
174
- subject { Yodleeicious::YodleeApi.new(config) }
175
-
176
- it 'the provided base url is set' do
177
- expect(subject.base_url).to eq(config[:base_url])
178
- end
179
-
180
- it 'the provided cobranded_username is set' do
181
- expect(subject.cobranded_username).to eq(config[:cobranded_username])
182
- end
183
-
184
- it 'the provided cobranded_password is set' do
185
- expect(subject.cobranded_password).to eq(config[:cobranded_password])
186
- end
187
-
188
- it 'the provided proxy_url is set' do
189
- expect(subject.proxy_url).to eq(config[:proxy_url])
190
- end
191
-
192
- it 'the provided proxy_opts are created' do
193
- proxy_opts = {
194
- socks: true,
195
- uri: URI.parse(config[:proxy_url])
196
- }
197
- expect(subject.proxy_opts).to eq(proxy_opts)
198
- end
199
-
200
- it 'the provided socks proxy is used' do
201
- expect(subject.use_socks?).to eq(true)
202
- end
203
- end
204
- end
205
-
206
- context 'Given a Yodleeicious::Config with nil config values' do
207
- context 'When a new YodleeApi instance is configured with no proxy_url' do
208
- before {
209
- Yodleeicious::Config.base_url=nil
210
- Yodleeicious::Config.cobranded_username=nil
211
- Yodleeicious::Config.cobranded_password=nil
212
- Yodleeicious::Config.proxy_url=nil
213
- }
214
- let(:config) {
215
- {
216
- base_url: "https://rest.developer.yodlee.com/services/srest/restserver/v1.0",
217
- cobranded_username: "some_username",
218
- cobranded_password: "some_password"
219
- }
220
- }
221
-
222
- subject { Yodleeicious::YodleeApi.new(config) }
223
-
224
- it 'no proxy_url is set' do
225
- expect(subject.proxy_url).to be_nil
226
- end
227
-
228
- it 'no proxy_opts are created' do
229
- expect(subject.proxy_opts).to eq({})
230
- end
231
-
232
- it 'the socks proxy is not used' do
233
- expect(subject.use_socks?).to eq(false)
234
- end
235
- end
236
- end
237
-
238
- describe '#should_retry_get_mfa_response?' do
239
- let (:api) { Yodleeicious::YodleeApi.new }
240
- let (:response) { instance_double("Yodleeicious::Response") }
241
-
242
- context 'Given get mfa response has failed' do
243
- before { allow(response).to receive(:success?).and_return(false) }
244
- before { allow(response).to receive(:body).and_return({}) }
245
- subject { api.should_retry_get_mfa_response?(response,0,1) }
246
- it { is_expected.to be_falsy }
247
- end
248
-
249
- context 'Given get mfa response is success' do
250
- before { allow(response).to receive(:success?).and_return(true) }
251
-
252
- context 'Given an error code is returned' do
253
- before { allow(response).to receive(:body).and_return({ 'errorCode' => 100 }) }
254
- subject { api.should_retry_get_mfa_response?(response,0,1) }
255
- it { is_expected.to be_falsy }
256
- end
257
-
258
- context 'Given no error code is returned' do
259
- context 'Given the MFA message is available' do
260
- before { allow(response).to receive(:body).and_return({ 'isMessageAvailable' => true }) }
261
- subject { api.should_retry_get_mfa_response?(response,0,1) }
262
- it { is_expected.to be_falsy }
263
- end
264
-
265
- context 'Given the MFA message is not available' do
266
- before { allow(response).to receive(:body).and_return({ 'isMessageAvailable' => false }) }
267
- context 'Given all the trys have been used up' do
268
- subject { api.should_retry_get_mfa_response?(response,1,1) }
269
- it { is_expected.to be_falsy }
270
- end
271
-
272
- context 'Given the trys have not been used up' do
273
- subject { api.should_retry_get_mfa_response?(response,0,2) }
274
- it { is_expected.to be_truthy }
275
- end
276
- end
277
- end
278
- end
279
- end
280
-
281
- describe '#should_retry_get_site_refresh_info' do
282
- let (:api) { Yodleeicious::YodleeApi.new }
283
- let (:response) { double("response") }
284
-
285
- context 'Given get mfa response has failed' do
286
- before { allow(response).to receive(:success?).and_return(false) }
287
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
288
- it { is_expected.to be_falsy }
289
- end
290
-
291
- context 'Given get mfa response is success' do
292
- before { allow(response).to receive(:success?).and_return(true) }
293
-
294
- context 'Given an code 801 is returned' do
295
- before { allow(response).to receive(:body).and_return({ 'code' => 801 }) }
296
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
297
- it { is_expected.to be_truthy }
298
- end
299
-
300
- context 'Given not 801 and not 0 code is returned' do
301
- before { allow(response).to receive(:body).and_return({ 'code' => 5 }) }
302
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
303
- it { is_expected.to be_falsy }
304
- end
305
-
306
- context 'Given a code 0 is returned' do
307
- context 'Given a siteRefreshStatus of REFRESH_COMPLETED' do
308
- before { allow(response).to receive(:body).and_return({ 'code' => 0, "siteRefreshStatus" => { "siteRefreshStatus" => "REFRESH_COMPLETED" }}) }
309
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
310
- it { is_expected.to be_falsy }
311
- end
312
-
313
- context 'Given a siteRefreshStatus of REFRESH_TIMED_OUT' do
314
- before { allow(response).to receive(:body).and_return({ 'code' => 0, "siteRefreshStatus" => { "siteRefreshStatus" => "REFRESH_TIMED_OUT" }}) }
315
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
316
- it { is_expected.to be_falsy }
317
- end
318
-
319
- context 'Given a siteRefreshStatus of LOGIN_SUCCESS' do
320
- before { allow(response).to receive(:body).and_return({ 'code' => 0, "siteRefreshStatus" => { "siteRefreshStatus" => "LOGIN_SUCCESS" }}) }
321
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
322
- it { is_expected.to be_falsy }
323
- end
324
-
325
- context 'Given a siteRefreshStatus of REFRESH_TRIGGERED' do
326
- before { allow(response).to receive(:body).and_return({ 'code' => 0, "siteRefreshStatus" => { "siteRefreshStatus" => "REFRESH_TRIGGERED" }}) }
327
- subject { api.should_retry_get_site_refresh_info?(response,0,1) }
328
- it { is_expected.to be_truthy }
329
- end
330
-
331
- context 'Given a siteRefreshStatus of REFRESH_TRIGGERED' do
332
- before { allow(response).to receive(:body).and_return({ 'code' => 0, "siteRefreshStatus" => { "siteRefreshStatus" => "REFRESH_TRIGGERED" }}) }
333
- context 'Given trys have been used up' do
334
- subject { api.should_retry_get_site_refresh_info?(response,1,1) }
335
- it { is_expected.to be_falsy }
336
- end
337
- end
338
- end
339
- end
340
- end
341
- end