old_plaid 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ describe 'OldPlaid.config' do
2
+ around(:each) do |example|
3
+ old_customer_id = OldPlaid.customer_id
4
+ old_secret = OldPlaid.secret
5
+ old_environment_location = OldPlaid.environment_location
6
+
7
+ OldPlaid.config do |p|
8
+ p.customer_id = customer_id
9
+ p.secret = secret
10
+ p.environment_location = environment_location
11
+ end
12
+
13
+ example.run
14
+
15
+ OldPlaid.config do |p|
16
+ p.customer_id = old_customer_id
17
+ p.secret = old_secret
18
+ p.environment_location = old_environment_location
19
+ end
20
+ end
21
+
22
+ let(:customer_id) { 'test_id' }
23
+ let(:secret) { 'test_secret' }
24
+ let(:dev_url) { 'https://tartan.plaid.com/' }
25
+ let(:prod_url) { 'https://api.plaid.com/' }
26
+
27
+
28
+ let(:user) { OldPlaid.add_user('connect', 'plaid_test', 'plaid_good', 'wells') }
29
+
30
+ context ':environment_location' do
31
+ context 'with trailing slash' do
32
+ let(:environment_location) { 'http://example.org/' }
33
+ it 'leaves it as-is' do
34
+ expect(OldPlaid.environment_location).to eql(environment_location)
35
+ end
36
+ end
37
+
38
+ context 'without trailing slash' do
39
+ let(:environment_location) { 'http://example.org' }
40
+ it 'adds a trailing slash' do
41
+ expect(OldPlaid.environment_location).to eql(environment_location + '/')
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'has valid dev keys' do
47
+ let(:environment_location) { dev_url }
48
+ it { expect(user).to be_instance_of OldPlaid::User }
49
+ end
50
+
51
+ context 'has valid production keys' do
52
+ let(:environment_location) { prod_url }
53
+ it { expect(user).to be_instance_of OldPlaid::User }
54
+ end
55
+
56
+ context 'has invalid dev keys' do
57
+ let(:secret) { 'test_bad' }
58
+ let(:environment_location) { dev_url }
59
+ it { expect { user }.to raise_error(OldPlaid::Unauthorized, 'secret or client_id invalid') }
60
+ end
61
+
62
+ context 'has invalid production keys' do
63
+ let(:secret) { 'test_bad' }
64
+ let(:environment_location) { prod_url }
65
+ it { expect { user }.to raise_error(OldPlaid::Unauthorized, 'secret or client_id invalid') }
66
+ end
67
+ end
@@ -0,0 +1,191 @@
1
+ describe OldPlaid::Connection do
2
+ let(:stub_url) { "https://tartan.plaid.com/testing" }
3
+ let(:bad_req_response) { {"code" => 1005, "message" => "invalid credentials", "resolve" => "The username or password provided is not correct."}.to_json }
4
+ let(:unauth_response) { {"code" => 1105, "message" => "bad access_token", "resolve" => "This access_token appears to be corrupted."}.to_json }
5
+ let(:req_fail_response) { {"code" => 1200, "message" => "invalid credentials", "resolve" => "The username or password provided is not correct."}.to_json }
6
+ let(:req_not_found) { {"code" => 1600, "message" => "product not found", "resolve" => "This product doesn't exist yet, we're actually not sure how you reached this error..."}.to_json }
7
+
8
+ describe "#post" do
9
+ it "sends a post request" do
10
+ stub = stub_request(:post, stub_url).to_return({:body => {"response" => "OK"}.to_json})
11
+ OldPlaid::Connection.post("testing")
12
+ expect(stub).to have_requested(:post, stub_url)
13
+ end
14
+
15
+ it "returns response on 200 response" do
16
+ stub = stub_request(:post, stub_url).to_return({:body => {"response" => "OK"}.to_json})
17
+ response = OldPlaid::Connection.post("testing")
18
+ expect(response).to eq({"response" => "OK"})
19
+ end
20
+
21
+ it "returns message on 201 response" do
22
+ stub = stub_request(:post, stub_url).to_return(status: 201, body: {"response" => "OK"}.to_json)
23
+ response = OldPlaid::Connection.post("testing")
24
+ expect(response).to eq({:msg => "Requires further authentication", :body => {"response" => "OK"}})
25
+ end
26
+
27
+ it "throws OldPlaid::BadRequest on 400 response" do
28
+ stub = stub_request(:post, stub_url).to_return(status: 400, body: bad_req_response)
29
+ expect { OldPlaid::Connection.post("testing") }.to raise_error(OldPlaid::BadRequest, "invalid credentials")
30
+ end
31
+
32
+ it "throws OldPlaid::Unauthorized on 401 response" do
33
+ stub = stub_request(:post, stub_url).to_return(status: 401, body: unauth_response)
34
+ expect { OldPlaid::Connection.post("testing") }.to raise_error(OldPlaid::Unauthorized, "bad access_token")
35
+ end
36
+
37
+ it "throws OldPlaid::RequestFailed on 402 response" do
38
+ stub = stub_request(:post, stub_url).to_return(status: 402, body: req_fail_response)
39
+ expect { OldPlaid::Connection.post("testing") }.to raise_error(OldPlaid::RequestFailed, "invalid credentials")
40
+ end
41
+
42
+ it "throws a OldPlaid::NotFound on 404 response" do
43
+ stub = stub_request(:post, stub_url).to_return(status: 404, body: req_not_found)
44
+ expect { OldPlaid::Connection.post("testing") }.to raise_error(OldPlaid::NotFound, "product not found")
45
+ end
46
+
47
+ it "throws a OldPlaid::ServerError on empty response" do
48
+ stub = stub_request(:post, stub_url).to_return(status: 504, body: '')
49
+ expect { OldPlaid::Connection.post("testing") }.to raise_error(OldPlaid::ServerError, '')
50
+ end
51
+ end
52
+
53
+ describe "#get" do
54
+ it "sends a get request" do
55
+ stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
56
+ OldPlaid::Connection.get("testing")
57
+ expect(stub).to have_requested(:get, stub_url)
58
+ end
59
+
60
+ it "returns response when no code available" do
61
+ stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
62
+ response = OldPlaid::Connection.get("testing")
63
+ expect(response).to eq({"response" => "OK"})
64
+ end
65
+
66
+ it "returns response when code not [1301, 1401, 1501, 1601]" do
67
+ stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1502, "response" => "OK"}.to_json})
68
+ response = OldPlaid::Connection.get("testing")
69
+ expect(response).to eq({"code" => 1502, "response" => "OK"})
70
+ end
71
+
72
+ it "throws 404 for 1301 code" do
73
+ stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1301, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
74
+ expect { OldPlaid::Connection.get("testing")}.to raise_error(OldPlaid::NotFound, "Doesn't matter")
75
+ end
76
+
77
+ it "throws 404 for 1401 code" do
78
+ stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1401, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
79
+ expect { OldPlaid::Connection.get("testing")}.to raise_error(OldPlaid::NotFound, "Doesn't matter")
80
+ end
81
+
82
+ it "throws 404 for 1501 code" do
83
+ stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1501, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
84
+ expect { OldPlaid::Connection.get("testing")}.to raise_error(OldPlaid::NotFound, "Doesn't matter")
85
+ end
86
+
87
+ it "throws 404 for 1601 code" do
88
+ stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1601, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
89
+ expect { OldPlaid::Connection.get("testing")}.to raise_error(OldPlaid::NotFound, "Doesn't matter")
90
+ end
91
+
92
+ end
93
+
94
+ describe "#secure_get" do
95
+ it "sends a secure get request" do
96
+ stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
97
+ OldPlaid::Connection.secure_get("testing", "test_wells")
98
+ expect(stub).to have_requested(:get, stub_url).with(:body => {:access_token => "test_wells"})
99
+ end
100
+
101
+ it "returns response on 200 response" do
102
+ stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
103
+ response = OldPlaid::Connection.secure_get("testing", "test_wells")
104
+ expect(response).to eq({"response" => "OK"})
105
+ end
106
+
107
+ it "returns message on 201 response" do
108
+ stub = stub_request(:get, stub_url).to_return(status: 201, body: {"response" => "OK"}.to_json)
109
+ response = OldPlaid::Connection.secure_get("testing", "test_wells")
110
+ expect(response).to eq({:msg => "Requires further authentication", :body => {"response" => "OK"}})
111
+ end
112
+
113
+ it "throws OldPlaid::BadRequest on 400 response" do
114
+ stub = stub_request(:get, stub_url).to_return(status: 400, body: bad_req_response)
115
+ expect { OldPlaid::Connection.secure_get("testing", "test_wells") }.to raise_error(OldPlaid::BadRequest, "invalid credentials")
116
+ end
117
+
118
+ it "throws OldPlaid::Unauthorized on 401 response" do
119
+ stub = stub_request(:get, stub_url).to_return(status: 401, body: unauth_response)
120
+ expect { OldPlaid::Connection.secure_get("testing", "test_wells") }.to raise_error(OldPlaid::Unauthorized, "bad access_token")
121
+ end
122
+
123
+ it "throws OldPlaid::RequestFailed on 402 response" do
124
+ stub = stub_request(:get, stub_url).to_return(status: 402, body: req_fail_response)
125
+ expect { OldPlaid::Connection.secure_get("testing", "test_wells") }.to raise_error(OldPlaid::RequestFailed, "invalid credentials")
126
+ end
127
+
128
+ it "throws a OldPlaid::NotFound on 404 response" do
129
+ stub = stub_request(:get, stub_url).to_return(status: 404, body: req_not_found)
130
+ expect { OldPlaid::Connection.secure_get("testing", "test_wells") }.to raise_error(OldPlaid::NotFound, "product not found")
131
+ end
132
+
133
+ it "throws a OldPlaid::ServerError on empty response" do
134
+ stub = stub_request(:get, stub_url).to_return(status: 504, body: '')
135
+ expect { OldPlaid::Connection.secure_get("testing", "test_wells") }.to raise_error(OldPlaid::ServerError, '')
136
+ end
137
+ end
138
+
139
+ describe "#patch" do
140
+ it "sends a patch request" do
141
+ stub = stub_request(:patch, stub_url).to_return({:body => {"response" => "OK"}.to_json})
142
+ OldPlaid::Connection.patch("testing")
143
+ expect(stub).to have_requested(:patch, stub_url)
144
+ end
145
+
146
+ it "returns response on 200 response" do
147
+ stub = stub_request(:patch, stub_url).to_return({:body => {"response" => "OK"}.to_json})
148
+ response = OldPlaid::Connection.patch("testing")
149
+ expect(response).to eq({"response" => "OK"})
150
+ end
151
+
152
+ it "returns message on 201 response" do
153
+ stub = stub_request(:patch, stub_url).to_return(status: 201, body: {"response" => "OK"}.to_json)
154
+ response = OldPlaid::Connection.patch("testing")
155
+ expect(response).to eq({:msg => "Requires further authentication", :body => {"response" => "OK"}})
156
+ end
157
+
158
+ it "throws OldPlaid::BadRequest on 400 response" do
159
+ stub = stub_request(:patch, stub_url).to_return(status: 400, body: bad_req_response)
160
+ expect { OldPlaid::Connection.patch("testing") }.to raise_error(OldPlaid::BadRequest, "invalid credentials")
161
+ end
162
+
163
+ it "throws OldPlaid::Unauthorized on 401 response" do
164
+ stub = stub_request(:patch, stub_url).to_return(status: 401, body: unauth_response)
165
+ expect { OldPlaid::Connection.patch("testing") }.to raise_error(OldPlaid::Unauthorized, "bad access_token")
166
+ end
167
+
168
+ it "throws OldPlaid::RequestFailed on 402 response" do
169
+ stub = stub_request(:patch, stub_url).to_return(status: 402, body: req_fail_response)
170
+ expect { OldPlaid::Connection.patch("testing") }.to raise_error(OldPlaid::RequestFailed, "invalid credentials")
171
+ end
172
+
173
+ it "throws a OldPlaid::NotFound on 404 response" do
174
+ stub = stub_request(:patch, stub_url).to_return(status: 404, body: req_not_found)
175
+ expect { OldPlaid::Connection.patch("testing") }.to raise_error(OldPlaid::NotFound, "product not found")
176
+ end
177
+
178
+ it "throws a OldPlaid::ServerError on empty response" do
179
+ stub = stub_request(:patch, stub_url).to_return(status: 504, body: '')
180
+ expect { OldPlaid::Connection.patch("testing") }.to raise_error(OldPlaid::ServerError, '')
181
+ end
182
+ end
183
+
184
+ describe "#delete" do
185
+ it "sends a delete request" do
186
+ stub = stub_request(:delete, stub_url)
187
+ OldPlaid::Connection.delete("testing")
188
+ expect(stub).to have_requested(:delete, stub_url)
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,10 @@
1
+ describe OldPlaid::OldPlaidError do
2
+ describe "#new" do
3
+ it "allows code, message and resolution" do
4
+ error = OldPlaid::OldPlaidError.new 1, "testing", "fix it"
5
+ expect(error.code).to eq(1)
6
+ expect(error.message).to eq("testing")
7
+ expect(error.resolve).to eq("fix it")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ describe OldPlaid::Account do
2
+ # API: semi-private
3
+ describe '.new' do
4
+ subject { OldPlaid::Account.new(results) }
5
+
6
+ def self.with_results(_results, &examples)
7
+ context "with results #{_results}" do
8
+ let(:results) { _results }
9
+ instance_eval(&examples)
10
+ end
11
+ end
12
+
13
+ with_results('meta' => {'name' => 'Name'}) do it { expect(subject.name).to eql('Name') } end
14
+ with_results('_id' => 'ID') do it { expect(subject.id).to eql('ID') } end
15
+ with_results('type' => 'Type') do it { expect(subject.type).to eql('Type') } end
16
+ with_results('type' => 'STyp') do it { expect(subject.type).to eql('STyp') } end
17
+ with_results('meta' => nil) do it { expect(subject.meta).to be_nil } end
18
+ with_results('meta' => {}) do it { expect(subject.meta).to eql({}) } end
19
+
20
+ with_results('balance' => { 'available' => 100.00 } ) do it { expect(subject.available_balance).to eql(100.00) } end
21
+ with_results('balance' => { 'current' => 200.00 } ) do it { expect(subject.current_balance).to eql(200.00) } end
22
+
23
+ with_results('institution_type' => 'Type') do it { expect(subject.institution_type).to eql('Type') } end
24
+
25
+ with_results('numbers' => nil) do
26
+ it { expect(subject.numbers).to eql('Upgrade user to access routing information for this account') }
27
+ end
28
+
29
+ with_results('numbers' => {}) do
30
+ it { expect(subject.numbers).to eql({}) }
31
+ end
32
+
33
+ with_results({}) do
34
+ it { expect(subject.name).to eq nil } # doesn't blow up if 'meta' is missing
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ describe OldPlaid::Category do
2
+ context 'when a single category is found' do
3
+ let(:category) { OldPlaid.category('17001013') }
4
+ it { expect(category).to be_kind_of(OldPlaid::Category) }
5
+ end
6
+
7
+ context 'when all categories are found' do
8
+ let(:category) { OldPlaid.category }
9
+ it { expect(category).to be_kind_of(Array)}
10
+ end
11
+
12
+ context 'when category is not found' do
13
+ it { expect { OldPlaid.category('dumb_cat') }.to raise_error(OldPlaid::NotFound, 'unable to find category') }
14
+ end
15
+
16
+ end
@@ -0,0 +1,19 @@
1
+ describe OldPlaid::Institution do
2
+ context 'when a single institution is found' do
3
+ let(:institution) { OldPlaid.institution('5301a93ac140de84910000e0') }
4
+
5
+ it { expect(institution).to be_kind_of(OldPlaid::Institution) }
6
+ it { expect(institution.mfa).to be_kind_of(Array) }
7
+ it { expect(institution.products).to be_kind_of(Array) }
8
+ it { expect(institution.credentials).to be_kind_of(Hash) }
9
+ end
10
+
11
+ context 'when all institutions are found' do
12
+ let(:institution) { OldPlaid.institution }
13
+ it { expect(institution).to be_kind_of(Array) }
14
+ end
15
+
16
+ context 'when institution is not found' do
17
+ it { expect { OldPlaid.institution('dumb_bank') }.to raise_error(OldPlaid::NotFound, 'unable to find institution') }
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ describe OldPlaid::Transaction do
2
+ # API: semi-private
3
+ describe '.new' do
4
+ # The reason this looks weird is because it is. This will be refactored for 2.0
5
+ subject { OldPlaid::Transaction.new(results) }
6
+
7
+ def self.with_results(_results, &examples)
8
+ context "with results #{_results}" do
9
+ let(:results) { _results }
10
+ instance_eval(&examples)
11
+ end
12
+ end
13
+
14
+ with_results('_id' => 'ID') do it { expect(subject.id).to eql('ID') } end
15
+ with_results('_account' => 'acct') do it { expect(subject.account).to eql('acct') } end
16
+ with_results('date' => '00/00/00') do it { expect(subject.date).to eql('00/00/00') } end
17
+ with_results('amount' => 100.00) do it { expect(subject.amount).to eql(100.00) } end
18
+ with_results('name' => 'Name') do it { expect(subject.name).to eql('Name') } end
19
+ with_results('meta' => {} ) do it { expect(subject.meta).to eql({}) } end
20
+ with_results('meta' => {'location' => 'Location'}) do it { expect(subject.location).to eql('Location') } end
21
+ with_results('pending' => true) do it { expect(subject.pending).to eql(true) } end
22
+ with_results('score' => 200) do it { expect(subject.score).to eql(200) } end
23
+ with_results('type' => 'Type') do it { expect(subject.type).to eql('Type') } end
24
+
25
+ with_results('category' => 'Category') do it { expect(subject.category).to eql('Category') } end
26
+ with_results('category_id' => 100) do it { expect(subject.category_id).to eql(100) } end
27
+ end
28
+ end
@@ -0,0 +1,172 @@
1
+ describe OldPlaid::User do
2
+ let(:auth_user) { OldPlaid.add_user('auth', 'plaid_test', 'plaid_good', 'wells') }
3
+ let(:connect_user) { OldPlaid.add_user('connect', 'plaid_test', 'plaid_good', 'wells') }
4
+ let(:info_user) { OldPlaid.add_user('info', 'plaid_test', 'plaid_good', 'wells') }
5
+
6
+ context 'user vars' do
7
+ context 'valid user has accounts and accounts contain id attribute' do
8
+ let(:user) { OldPlaid.add_user('connect', 'plaid_test', 'plaid_good', 'wells') }
9
+ it { expect(user.accounts.first.id).not_to be_nil }
10
+ end
11
+
12
+ context 'valid user has accounts and accounts contain type attribute' do
13
+ let(:user) { OldPlaid.add_user('connect', 'plaid_test', 'plaid_good', 'wells') }
14
+ it { expect(user.accounts.first.type).to eq('depository') }
15
+ end
16
+ end
17
+
18
+ # MFA specs - after user is instantiated,
19
+ describe '#mfa_authentication' do
20
+ let(:user) { OldPlaid.add_user('connect', 'plaid_test', 'plaid_good', 'bofa') }
21
+ let(:new_mfa_user) { user.mfa_authentication('tomato') }
22
+
23
+ context 'enters correct credentials for MFA auth and authenticates' do
24
+ it { expect(new_mfa_user.accounts).not_to be_empty }
25
+ end
26
+
27
+ context 'enters old method of adding type strongly in each method and authenticates correctly using 2FA' do
28
+ let(:new_mfa_user) { user.mfa_authentication('tomato', 'bofa') }
29
+ it { expect(new_mfa_user.accounts).to be_truthy }
30
+ end
31
+
32
+ context 'has to enter another round of MFA credentials' do
33
+ let(:mfa_again) { user.mfa_authentication('again') }
34
+ it { expect(mfa_again.api_res).to eq 'Requires further authentication' }
35
+ end
36
+
37
+ context 'enters incorrect credentials for MFA auth' do
38
+ let(:mfa_user) { user.mfa_authentication('tomato') }
39
+ let(:mfa_bad) { mfa_user; OldPlaid.add_user('connect', 'plaid_test', 'plaid_good', 'bofa') }
40
+ it { expect { mfa_bad.mfa_authentication('bad') }.to raise_error(OldPlaid::RequestFailed, 'invalid mfa') }
41
+ end
42
+
43
+ context 'requests list of MFA credentials' do
44
+ let(:new_mfa_user) { OldPlaid.add_user('auth', 'plaid_test', 'plaid_good', 'chase', nil, '{"list":true}') }
45
+ let(:expected_questions) do
46
+ {
47
+ "type"=>"list",
48
+ "mfa"=> [
49
+ {"mask"=>"xxx-xxx-5309", "type"=>"phone"},
50
+ {"mask"=>"t..t@plaid.com", "type"=>"email"}
51
+ ],
52
+ "access_token"=>"test_chase"
53
+ }
54
+ end
55
+ it { expect(new_mfa_user.pending_mfa_questions).to eql(expected_questions) }
56
+ end
57
+
58
+ context 'selects MFA method and returns successful response' do
59
+ let(:user) { OldPlaid.add_user('auth', 'plaid_test', 'plaid_good', 'chase', nil, '{"list":true}') }
60
+ let(:new_mfa_user) { user.select_mfa_method({mask: 'xxx-xxx-5309' }, 'chase') }
61
+ let(:expected_pending_questions) do
62
+ {
63
+ "type" => "device",
64
+ "mfa" => { "message" => "Code sent to xxx-xxx-5309" },
65
+ "access_token" => "test_chase"
66
+ }
67
+ end
68
+ it { expect(new_mfa_user.pending_mfa_questions).to eql(expected_pending_questions) }
69
+ end
70
+
71
+ context 'selects MFA method, and delivers correct payload to authenticate user' do
72
+ let(:user) { OldPlaid.add_user('auth', 'plaid_test', 'plaid_good', 'chase', nil, '{"list":true}') }
73
+ let(:user_select_method) { user.select_mfa_method({mask:'xxx-xxx-5309'}) }
74
+ let(:new_mfa_user) { user_select_method.mfa_authentication(1234) }
75
+
76
+ it { expect(new_mfa_user.accounts).not_to be_empty }
77
+ end
78
+ end
79
+
80
+ context 'when authenticating' do
81
+ # Auth specs
82
+ describe '#get_auth' do
83
+
84
+ context 'has access and returns accounts' do
85
+ it { expect(auth_user.permissions[0]).to eq('auth') }
86
+ end
87
+
88
+ context 'does not have access to auth' do
89
+ it { expect(connect_user.permissions.include? 'auth' ).to eql(false) }
90
+ end
91
+ end
92
+
93
+ # Connect specs
94
+ describe '#get_connect' do
95
+ context 'has access and returns accounts' do
96
+ it { expect(connect_user.permissions[0]).to eq('connect') }
97
+ end
98
+
99
+ context 'does not have access to auth' do
100
+ it { expect(auth_user.permissions.include? 'connect' ).to eql(false) }
101
+ end
102
+ end
103
+
104
+ # Get info specs
105
+ describe '#get_info' do
106
+ context 'has access and returns user info' do
107
+ it { expect(info_user.permissions[0]).to eq('info') }
108
+ end
109
+
110
+ context 'does not have access to info' do
111
+ it{ expect(auth_user.permissions.include? 'info' ).to eql(false) }
112
+ end
113
+ end
114
+ end
115
+
116
+ describe '#get_balance' do
117
+ subject { user.tap(&:update_balance) }
118
+ let(:user) { OldPlaid.add_user('info', 'plaid_test', 'plaid_good', 'wells') }
119
+
120
+ context 'updates user accounts' do
121
+ it { expect(subject.accounts).not_to be_empty }
122
+ end
123
+
124
+ # TODO: This test needs to be rewritten better, such as using #uniq instead of this
125
+ context 'does not double up accounts or transactions' do
126
+ let(:total_duplicates) { duplicate_accounts.length + duplicate_transactions.length }
127
+ let(:duplicate_accounts) { subject.accounts.select {|element| user.accounts.count(element) > 1} }
128
+ let(:duplicate_transactions) { subject.transactions.select {|element| user.transactions.count(element) > 1} }
129
+ it{ expect(total_duplicates).to eql(0) }
130
+ end
131
+ end
132
+
133
+ describe '#update_info' do
134
+ let(:info_user) { OldPlaid.add_user('info', 'plaid_test', 'plaid_good', 'wells') }
135
+ context 'updates information correctly' do
136
+ # TODO: This test needs to pass, currently test credentials are failing
137
+ pending { expect { info_user.update_info('plaid_test', 'plaid_good') }.to_not raise_error }
138
+ end
139
+ end
140
+
141
+ describe '#delete_user' do
142
+ subject { info_user.tap(&:delete_user) }
143
+ let(:info_user) { OldPlaid.add_user('info', 'plaid_test', 'plaid_good', 'wells') }
144
+
145
+ context 'updates information correctly' do
146
+ it { expect { subject.get_info }.to raise_error(OldPlaid::Unauthorized, 'client_id missing') }
147
+ end
148
+ end
149
+
150
+ describe '#upgrade' do
151
+ subject { user.tap(&upgrade!) }
152
+ let(:upgrade!) { ->(x) { x.upgrade(upgrade_level) } }
153
+ let(:upgrade_level) { raise 'Define upgrade level' }
154
+
155
+ context 'auth upgrade is successful' do
156
+ let(:user) { connect_user }
157
+ let(:upgrade_level) { 'auth' }
158
+ it { expect{ subject.get_auth }.to_not raise_error }
159
+ end
160
+
161
+ context 'connect upgrade is successful' do
162
+ let(:user) { auth_user }
163
+ let(:upgrade_level) { 'connect' }
164
+ it { expect{ subject.get_connect }.to_not raise_error }
165
+ end
166
+ end
167
+
168
+ # This stuff needs to be tested and rewritten. Have already
169
+ # surfaced up a bug in it
170
+ pending '#populate_user'
171
+
172
+ end