yodlee-icious 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ unless defined?(SPEC_HELPER_LOADED)
7
+ SPEC_HELPER_LOADED = true
8
+
9
+ require "yodleeicious"
10
+ require 'dotenv'
11
+ Dotenv.load
12
+
13
+ Yodleeicious::Config.logger = Logger.new("log/test.log")
14
+ Yodleeicious::Config.logger.level = Logger::DEBUG
15
+
16
+ RSpec.configure do |config|
17
+
18
+ config.filter_run :focus
19
+ config.run_all_when_everything_filtered = true
20
+
21
+ end
22
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+ require "yodleeicious/config"
3
+
4
+ describe Yodleeicious::Config do
5
+ describe "#base_url" do
6
+ it "default value is nil" do
7
+ Yodleeicious::Config.base_url = nil
8
+ end
9
+ end
10
+
11
+ describe "#cobranded_username" do
12
+ it "default value is nil" do
13
+ Yodleeicious::Config.cobranded_username = nil
14
+ end
15
+ end
16
+
17
+ describe "#cobranded_password" do
18
+ it "default value is nil" do
19
+ Yodleeicious::Config.cobranded_password = nil
20
+ end
21
+ end
22
+
23
+ describe "#proxy_url" do
24
+ it "default value is nil" do
25
+ Yodleeicious::Config.proxy_url = nil
26
+ end
27
+ end
28
+
29
+ describe "#base_url=" do
30
+ it "can set value" do
31
+ Yodleeicious::Config.base_url = 'http://someurl'
32
+ expect(Yodleeicious::Config.base_url).to eq('http://someurl')
33
+ end
34
+ end
35
+
36
+ describe "#cobranded_username=" do
37
+ it "can set value" do
38
+ Yodleeicious::Config.cobranded_username = 'some username'
39
+ expect(Yodleeicious::Config.cobranded_username).to eq('some username')
40
+ end
41
+ end
42
+
43
+ describe "#cobranded_password=" do
44
+ it "can set value" do
45
+ Yodleeicious::Config.cobranded_password = 'some password'
46
+ expect(Yodleeicious::Config.cobranded_password).to eq('some password')
47
+ end
48
+ end
49
+
50
+ describe "#proxy_url=" do
51
+ it "can set value" do
52
+ Yodleeicious::Config.proxy_url = 'http://someurl'
53
+ expect(Yodleeicious::Config.proxy_url).to eq('http://someurl')
54
+ end
55
+ end
56
+
57
+ describe "#logger="do
58
+ let(:logger) { Logger.new(STDOUT) }
59
+ it "can set value" do
60
+ Yodleeicious::Config.logger = logger
61
+ expect(Yodleeicious::Config.logger).to eq(logger)
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,80 @@
1
+ require "yodleeicious/parameter_translator"
2
+
3
+ describe 'parameter translator' do
4
+ subject { Yodleeicious::ParameterTranslator.new }
5
+ context 'converting login params json to add site params' do
6
+ let (:login_form) {
7
+ {
8
+ 'componentList' => [
9
+ {
10
+ 'valueIdentifier' => 'LOGIN',
11
+ 'valueMask' => 'LOGIN_FIELD',
12
+ 'fieldType' => {
13
+ 'typeName' => 'IF_LOGIN'
14
+ },
15
+ 'size' => 20,
16
+ 'maxlength' => 32,
17
+ 'name' => 'LOGIN',
18
+ 'displayName' => 'User ID',
19
+ 'isEditable' => true,
20
+ 'isOptional' => false,
21
+ 'isEscaped' => false,
22
+ 'helpText' => 4710,
23
+ 'isOptionalMFA' => false,
24
+ 'isMFA' => false,
25
+ 'fieldValue' => 'kanyewest'
26
+ },
27
+ {
28
+ 'valueIdentifier' => 'PASSWORD',
29
+ 'valueMask' => 'LOGIN_FIELD',
30
+ 'fieldType' => {
31
+ 'typeName' => 'IF_PASSWORD'
32
+ },
33
+ 'size' => 20,
34
+ 'maxlength' => 40,
35
+ 'name' => 'PASSWORD',
36
+ 'displayName' => 'Password',
37
+ 'isEditable' => true,
38
+ 'isOptional' => false,
39
+ 'isEscaped' => false,
40
+ 'helpText' => 11976,
41
+ 'isOptionalMFA' => false,
42
+ 'isMFA' => false,
43
+ 'fieldValue' => 'iLoveTheGrammys'
44
+ }
45
+ ]
46
+ }
47
+ }
48
+
49
+ let (:add_site_params) {
50
+ {
51
+ "credentialFields.enclosedType" => "com.yodlee.common.FieldInfoSingle",
52
+ "credentialFields[0].displayName" => "User ID",
53
+ "credentialFields[0].fieldType.typeName" => "IF_LOGIN",
54
+ "credentialFields[0].helpText" => 4710,
55
+ "credentialFields[0].maxlength" => 32,
56
+ "credentialFields[0].name" => "LOGIN",
57
+ "credentialFields[0].size" => 20,
58
+ "credentialFields[0].value" => 'kanyewest',
59
+ "credentialFields[0].valueIdentifier" => "LOGIN",
60
+ "credentialFields[0].valueMask" => "LOGIN_FIELD",
61
+ "credentialFields[0].isEditable" => true,
62
+ "credentialFields[1].displayName" => "Password",
63
+ "credentialFields[1].fieldType.typeName" => "IF_PASSWORD",
64
+ "credentialFields[1].helpText" => 11976,
65
+ "credentialFields[1].maxlength" => 40,
66
+ "credentialFields[1].name" => "PASSWORD",
67
+ "credentialFields[1].size" => 20,
68
+ "credentialFields[1].value" => 'iLoveTheGrammys',
69
+ "credentialFields[1].valueIdentifier" => "PASSWORD",
70
+ "credentialFields[1].valueMask" => "LOGIN_FIELD",
71
+ "credentialFields[1].isEditable" => true
72
+ }
73
+ }
74
+
75
+ it "converts correctly to params hash" do
76
+ expect(subject.site_login_form_to_add_site_account_params(login_form)).to be == add_site_params
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,61 @@
1
+ require "yodleeicious"
2
+
3
+ describe Yodleeicious::Response do
4
+ let(:error_response_1) {
5
+ {
6
+ "errorOccurred"=>"true",
7
+ "exceptionType"=>"com.yodlee.core.IllegalArgumentValueException",
8
+ "referenceCode"=>"_3932d208-345a-400f-a273-83619b8b548b",
9
+ "message"=>"Multiple exceptions encapsulated within: invoke getWrappedExceptions for details"
10
+ }
11
+ }
12
+
13
+ let(:error_response_2) {
14
+ { "Error" => [ {"errorDetail" => "Invalid User Credentials"} ] }
15
+ }
16
+
17
+ let(:success_hash_response) {
18
+ {}
19
+ }
20
+
21
+ let(:success_array_response) {
22
+ [{}]
23
+ }
24
+
25
+ context 'When the error_response is the errorOccured syntax' do
26
+ subject { Yodleeicious::Response.new error_response_1 }
27
+ it { is_expected.not_to be_success }
28
+ it { is_expected.to be_fail }
29
+ it "is expected to return error of InvalidArgumentValueException" do
30
+ expect(subject.error).to eq('com.yodlee.core.IllegalArgumentValueException')
31
+ end
32
+ end
33
+
34
+ context 'When the error_response is the Error : ["errorDetail"] syntax' do
35
+ subject { Yodleeicious::Response.new error_response_2 }
36
+ it { is_expected.not_to be_success }
37
+ it { is_expected.to be_fail }
38
+ it "is expected to return error of Invalid User Credentials" do
39
+ expect(subject.error).to eq('Invalid User Credentials')
40
+ end
41
+ end
42
+
43
+ context 'When operation is a success and returns hash' do
44
+ subject { Yodleeicious::Response.new success_hash_response }
45
+ it { is_expected.to be_success }
46
+ it { is_expected.not_to be_fail }
47
+ it 'is expected to return nil for error' do
48
+ expect(subject.error).to be_nil
49
+ end
50
+ end
51
+
52
+ context 'When operation is a success and return array' do
53
+ subject { Yodleeicious::Response.new success_array_response }
54
+ it { is_expected.to be_success }
55
+ it { is_expected.not_to be_fail }
56
+ it 'is expected to return nil for error' do
57
+ expect(subject.error).to be_nil
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,341 @@
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