plaider 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ {
2
+ "code": 1200,
3
+ "message": "invalid credentials",
4
+ "resolve": "The username or password provided were not correct."
5
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "questions",
3
+ "mfa": [
4
+ {
5
+ "question": "You say tomato, I say...?"
6
+ }
7
+ ],
8
+ "access_token": "test"
9
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "code": 1203,
3
+ "message": "invalid mfa",
4
+ "resolve": "The MFA response provided was not correct."
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "message": "Successfully removed from system"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "_id": "539c40548590c9d05eaec20a",
3
+ "name": "Apple Store",
4
+ "_category": {
5
+ "_id": "52544965f71e87d00700018a",
6
+ "hierarchy": {
7
+ "0": "Shops",
8
+ "1": "Computers and Electronics",
9
+ "2": ""
10
+ }
11
+ },
12
+ "meta": {
13
+ "location": {
14
+ "address": "1 Stockton St",
15
+ "city": "San Francisco",
16
+ "state": "CA"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "credentials": {
3
+ "password": "Password",
4
+ "username": "User ID"
5
+ },
6
+ "has_mfa": false,
7
+ "id": "5301a9d704977c52b60000db",
8
+ "mfa": [],
9
+ "name": "American Express",
10
+ "type": "amex",
11
+ "products": [
12
+ "connect",
13
+ "balance"
14
+ ]
15
+ }
@@ -0,0 +1,175 @@
1
+ [
2
+ {
3
+ "credentials": {
4
+ "password": "Password",
5
+ "username": "User ID"
6
+ },
7
+ "has_mfa": false,
8
+ "id": "5301a9d704977c52b60000db",
9
+ "mfa": [],
10
+ "name": "American Express",
11
+ "type": "amex",
12
+ "products": [
13
+ "connect",
14
+ "balance"
15
+ ]
16
+ },
17
+ {
18
+ "credentials": {
19
+ "password": "Password",
20
+ "username": "Online ID"
21
+ },
22
+ "has_mfa": true,
23
+ "id": "5301a93ac140de84910000e0",
24
+ "mfa": [
25
+ "code",
26
+ "list",
27
+ "questions(3)"
28
+ ],
29
+ "name": "Bank of America",
30
+ "type": "bofa",
31
+ "products": [
32
+ "connect",
33
+ "auth",
34
+ "balance"
35
+ ]
36
+ },
37
+ {
38
+ "credentials": {
39
+ "password": "PIN",
40
+ "username": "Username or Customer Number"
41
+ },
42
+ "has_mfa": false,
43
+ "id": "53c5c8631f9bda09c7000222",
44
+ "mfa": [],
45
+ "name": "Capital One 360",
46
+ "type": "capone360",
47
+ "products": [
48
+ "auth",
49
+ "balance"
50
+ ]
51
+ },
52
+ {
53
+ "credentials": {
54
+ "password": "Password",
55
+ "username": "Login ID"
56
+ },
57
+ "has_mfa": false,
58
+ "id": "53b34fab1a73941962000186",
59
+ "mfa": [],
60
+ "name": "Charles Schwab",
61
+ "type": "schwab",
62
+ "products": [
63
+ "auth",
64
+ "balance"
65
+ ]
66
+ },
67
+ {
68
+ "credentials": {
69
+ "password": "Password",
70
+ "username": "User ID"
71
+ },
72
+ "has_mfa": true,
73
+ "id": "5301a99504977c52b60000d0",
74
+ "mfa": [
75
+ "code",
76
+ "list"
77
+ ],
78
+ "name": "Chase",
79
+ "type": "chase",
80
+ "products": [
81
+ "connect",
82
+ "auth",
83
+ "balance",
84
+ "info"
85
+ ]
86
+ },
87
+ {
88
+ "credentials": {
89
+ "password": "Password",
90
+ "username": "User ID"
91
+ },
92
+ "has_mfa": true,
93
+ "id": "5301aa306b3f82a00500018b",
94
+ "mfa": [
95
+ "questions",
96
+ "selections"
97
+ ],
98
+ "name": "Citi",
99
+ "type": "citi",
100
+ "products": [
101
+ "connect",
102
+ "auth",
103
+ "balance"
104
+ ]
105
+ },
106
+ {
107
+ "credentials": {
108
+ "password": "Password",
109
+ "username": "Username"
110
+ },
111
+ "has_mfa": false,
112
+ "id": "53cee1d8c003c2747b000051",
113
+ "mfa": [],
114
+ "name": "Fidelity",
115
+ "type": "fidelity",
116
+ "products": [
117
+ "auth",
118
+ "balance"
119
+ ]
120
+ },
121
+ {
122
+ "credentials": {
123
+ "password": "Password",
124
+ "pin": "PIN",
125
+ "username": "Online ID"
126
+ },
127
+ "has_mfa": true,
128
+ "id": "531ea6602ad939b68700047c",
129
+ "mfa": [
130
+ "questions(3)"
131
+ ],
132
+ "name": "USAA",
133
+ "type": "usaa",
134
+ "products": [
135
+ "connect",
136
+ "auth",
137
+ "balance"
138
+ ]
139
+ },
140
+ {
141
+ "credentials": {
142
+ "password": "Password",
143
+ "username": "Personal ID"
144
+ },
145
+ "has_mfa": true,
146
+ "id": "531ea6327de8211c80000440",
147
+ "mfa": [
148
+ "questions(1)"
149
+ ],
150
+ "name": "US Bank",
151
+ "type": "us",
152
+ "products": [
153
+ "connect",
154
+ "auth",
155
+ "balance"
156
+ ]
157
+ },
158
+ {
159
+ "credentials": {
160
+ "password": "Password",
161
+ "username": "Username"
162
+ },
163
+ "has_mfa": false,
164
+ "id": "5301aa096b3f822b440001cb",
165
+ "mfa": [],
166
+ "name": "Wells Fargo",
167
+ "type": "wells",
168
+ "products": [
169
+ "connect",
170
+ "auth",
171
+ "balance",
172
+ "info"
173
+ ]
174
+ }
175
+ ]
@@ -0,0 +1,204 @@
1
+ require 'test_helper'
2
+
3
+ class ClientTest < Test::Unit::TestCase
4
+ def setup
5
+ @client = Plaider::Client.new(
6
+ {
7
+ client_id: 'client_id',
8
+ secret: 'secret',
9
+ access_token: 'access_token'
10
+ }
11
+ )
12
+ end
13
+
14
+ def test_arguments
15
+ assert_equal 'client_id', @client.instance_variable_get(:'@client_id')
16
+ assert_equal 'secret', @client.instance_variable_get(:'@secret')
17
+ assert_equal 'access_token', @client.instance_variable_get(:'@access_token')
18
+ end
19
+
20
+ def test_institutions
21
+ stub_get('/institutions').to_return(body: fixture('institutions.json'))
22
+ response = @client.institutions
23
+ assert_not_nil response
24
+ result = response[:result]
25
+ assert_not_nil result
26
+ assert_equal result.size, 10
27
+ assert_equal result[0][:id], '5301a9d704977c52b60000db'
28
+ assert_equal result[0][:type], 'amex'
29
+ assert_equal result[0][:name], 'American Express'
30
+ end
31
+
32
+ def test_institution
33
+ institution_id = '5301a9d704977c52b60000db'
34
+ stub_get("/institutions/#{institution_id}").to_return(body: fixture('institution.json'))
35
+ response = @client.institution(institution_id)
36
+ assert_not_nil response
37
+ result = response[:result]
38
+ assert_not_nil result
39
+ assert_equal institution_id, result[:id]
40
+ assert_equal 'amex', result[:type]
41
+ assert_equal 'American Express', result[:name]
42
+ end
43
+
44
+ def test_institution_with_bad_args
45
+ [nil, ''].each do |arg|
46
+ exception = assert_raise(ArgumentError) { @client.institution(arg) }
47
+ assert_equal('institution_id is required', exception.message)
48
+ end
49
+ end
50
+
51
+ def test_add_user
52
+ stub_post('/connect').to_return(body: fixture('connect.json'))
53
+ response = @client.add_user('institution_type', 'username', 'password', 'test@testemail.com')
54
+ assert_not_nil response
55
+ assert_not_nil '200', response[:status_code]
56
+ result = response[:result]
57
+ assert_not_nil result
58
+ assert_not_nil result[:accounts]
59
+ assert_equal 4, result[:accounts].size
60
+ assert_equal 1203.42, result[:accounts][0][:balance][:available]
61
+ assert_equal 1274.93, result[:accounts][0][:balance][:current]
62
+ assert_equal 'fake_institution', result[:accounts][0][:institution_type]
63
+ assert_equal 'depository', result[:accounts][0][:type]
64
+ assert_not_nil result[:transactions]
65
+ assert_equal 16, result[:transactions].size
66
+ end
67
+
68
+ def test_add_user_with_invalid_credencials
69
+ stub_post('/connect').to_return(body: fixture('connect_invalid.json'))
70
+ response = @client.add_user('institution_type', 'username', 'password', 'test@testemail.com')
71
+ assert_not_nil response
72
+ result = response[:result]
73
+ assert_not_nil result
74
+ assert_equal 'invalid credentials', result[:message]
75
+ end
76
+
77
+ def test_add_user_with_mfa
78
+ stub_post('/connect').to_return(status: 201, body: fixture('connect_mfa.json'))
79
+ response = @client.add_user('institution_type', 'username', 'password', 'test@testemail.com')
80
+ assert_not_nil response
81
+ assert_not_nil '201', response[:status_code]
82
+ result = response[:result]
83
+ assert_not_nil result
84
+ assert_equal 'You say tomato, I say...?', result[:mfa][0][:question]
85
+ end
86
+
87
+ def test_user_confirmation
88
+ stub_post('/connect/step').to_return(body: fixture('connect.json'))
89
+ response = @client.user_confirmation('tomato')
90
+ assert_not_nil response
91
+ result = response[:result]
92
+ assert_not_nil result
93
+ assert_not_nil result[:accounts]
94
+ assert_equal 4, result[:accounts].size
95
+ assert_equal 1203.42, result[:accounts][0][:balance][:available]
96
+ assert_equal 1274.93, result[:accounts][0][:balance][:current]
97
+ assert_equal 'fake_institution', result[:accounts][0][:institution_type]
98
+ assert_equal 'depository', result[:accounts][0][:type]
99
+ assert_not_nil result[:transactions]
100
+ assert_equal 16, result[:transactions].size
101
+ end
102
+
103
+ def test_user_confirmation_with_invalid_answer
104
+ stub_post('/connect/step').to_return(body: fixture('connect_mfa_invalid.json'))
105
+ response = @client.user_confirmation('abc')
106
+ assert_not_nil response
107
+ result = response[:result]
108
+ assert_not_nil result
109
+ assert_equal 'invalid mfa', result[:message]
110
+ end
111
+
112
+ def test_transactions
113
+ stub_post('/connect/get').to_return(body: fixture('connect.json'))
114
+ response = @client.transactions
115
+ result = response[:result]
116
+ assert_not_nil result
117
+ assert_not_nil result[:accounts]
118
+ assert_equal 4, result[:accounts].size
119
+ assert_equal 1203.42, result[:accounts][0][:balance][:available]
120
+ assert_equal 1274.93, result[:accounts][0][:balance][:current]
121
+ assert_equal 'fake_institution', result[:accounts][0][:institution_type]
122
+ assert_equal 'depository', result[:accounts][0][:type]
123
+ assert_not_nil result[:transactions]
124
+ assert_equal 16, result[:transactions].size
125
+ end
126
+
127
+ def test_transactions_valid_args
128
+ stub_post('/connect/get').to_return(body: fixture('connect.json'))
129
+ response = @client.transactions('123456789', Date.today - 30, Date.today, true)
130
+ result = response[:result]
131
+ assert_not_nil result
132
+ assert_not_nil result[:accounts]
133
+ assert_equal 4, result[:accounts].size
134
+ assert_equal 1203.42, result[:accounts][0][:balance][:available]
135
+ assert_equal 1274.93, result[:accounts][0][:balance][:current]
136
+ assert_equal 'fake_institution', result[:accounts][0][:institution_type]
137
+ assert_equal 'depository', result[:accounts][0][:type]
138
+ assert_not_nil result[:transactions]
139
+ assert_equal 16, result[:transactions].size
140
+ end
141
+
142
+ def test_update_user
143
+ stub_patch('/connect').to_return(body: fixture('connect_mfa.json'))
144
+ response = @client.update_user('username', 'password')
145
+ assert_not_nil response
146
+ assert_not_nil '201', response[:status_code]
147
+ result = response[:result]
148
+ assert_not_nil result
149
+ assert_equal 'You say tomato, I say...?', result[:mfa][0][:question]
150
+ end
151
+
152
+ def test_delete_user
153
+ stub_delete('/connect').to_return(body: fixture('delete_user.json'))
154
+ response = @client.delete_user
155
+ assert_not_nil response
156
+ result = response[:result]
157
+ assert_not_nil result
158
+ assert_equal 'Successfully removed from system', result[:message]
159
+ end
160
+
161
+ def test_balance
162
+ stub_post('/balance').to_return(body: fixture('balance.json'))
163
+ response = @client.balance
164
+ assert_not_nil response
165
+ result = response[:result]
166
+ assert_not_nil result
167
+ assert_not_nil result[:accounts]
168
+ assert_equal 4, result[:accounts].size
169
+ assert_equal 1203.42, result[:accounts][0][:balance][:available]
170
+ assert_equal 1274.93, result[:accounts][0][:balance][:current]
171
+ assert_equal 'fake_institution', result[:accounts][0][:institution_type]
172
+ assert_equal 'depository', result[:accounts][0][:type]
173
+ end
174
+
175
+ def test_categories
176
+ stub_get('/categories').to_return(body: fixture('categories.json'))
177
+ response = @client.categories
178
+ assert_not_nil response
179
+ result = response[:result]
180
+ assert_not_nil result
181
+ assert_equal 4, result.size
182
+ end
183
+
184
+ def test_category
185
+ stub_get('/categories/52544965f71e87d007000008').to_return(body: fixture('category.json'))
186
+ response = @client.category('52544965f71e87d007000008')
187
+ assert_not_nil response
188
+ result = response[:result]
189
+ assert_not_nil result
190
+ assert_not_nil result[:mappings]
191
+ assert_equal 3, result[:mappings].size
192
+ assert_equal 'Arts and Entertainment', result[:hierarchy][0]
193
+ end
194
+
195
+ def test_entity
196
+ stub_get('/entities/539c40548590c9d05eaec20a').to_return(body: fixture('entity.json'))
197
+ response = @client.entity('539c40548590c9d05eaec20a')
198
+ assert_not_nil response
199
+ result = response[:result]
200
+ assert_not_nil result
201
+ assert_equal 'Apple Store', result[:name]
202
+ end
203
+
204
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class PlaiderTest < Test::Unit::TestCase
4
+ def setup
5
+ Plaider.configure do |config|
6
+ config.client_id = 'client_id'
7
+ config.secret = 'secret'
8
+ end
9
+ end
10
+
11
+ def test_configure
12
+ configurable = Plaider.configure do |config|
13
+ config.client_id = 'client_id'
14
+ config.secret = 'secret'
15
+ config.access_token = 'access_token'
16
+ config.open_timeout = 5
17
+ config.read_timeout = 30
18
+ end
19
+ assert_equal 'client_id', configurable.instance_variable_get(:'@client_id')
20
+ assert_equal 'secret', configurable.instance_variable_get(:'@secret')
21
+ assert_equal 'access_token', configurable.instance_variable_get(:'@access_token')
22
+ assert_equal 5, configurable.instance_variable_get(:'@open_timeout')
23
+ assert_equal 30, configurable.instance_variable_get(:'@read_timeout')
24
+ end
25
+
26
+ def test_scope
27
+ client1 = Plaider.scope('1')
28
+ assert_true client1.is_a?(Plaider::Client)
29
+ assert_equal 'client_id', client1.instance_variable_get(:'@client_id')
30
+ assert_equal 'secret', client1.instance_variable_get(:'@secret')
31
+ client2 = Plaider.client
32
+ assert_equal client1, client2
33
+ client3 = Plaider.scope('1')
34
+ assert_equal client1, client3
35
+ client4 = Plaider.scope('2')
36
+ assert_not_equal client1, client4
37
+ end
38
+
39
+ def test_static_call
40
+ stub_get('/institutions').to_return(body: fixture('institutions.json'))
41
+ response = Plaider.institutions
42
+ assert_not_nil response
43
+ result = response[:result]
44
+ assert_not_nil result
45
+ assert_equal result.size, 10
46
+ assert_equal result[0][:id], '5301a9d704977c52b60000db'
47
+ assert_equal result[0][:type], 'amex'
48
+ assert_equal result[0][:name], 'American Express'
49
+ end
50
+ end