spec/plaid_spec.rb in plaid-1.0.0 vs spec/plaid_spec.rb in plaid-1.0.1
- old
+ new
@@ -1,47 +1,47 @@
require 'spec_helper.rb'
########## Plaid specs ##########
describe Plaid do
+
# Configuration specs - used in gem configuration
describe '.config' do
context 'has valid dev keys' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
res = Plaid.auth('connect','plaid_test','plaid_good','wells')
- it { expect(res).to be instance_of Plaid::User }
+ it { expect(res).to be_instance_of Plaid::User }
end
context 'has valid production keys' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://api.plaid.com/'
end
- #TODO: Test production level credentials
res = Plaid.auth('connect','plaid_test','plaid_good','wells')
- it { expect(res).to raise_error }
+ it { expect(res).to be_instance_of Plaid::User }
end
context 'has invalid dev keys' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_bad'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.auth('connect','plaid_test','plaid_good','wells')).to raise_error }
+ it { expect{Plaid.auth('connect','plaid_bad','plaid_bad','wells')}.to raise_error }
end
context 'has invalid production keys' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_bad'
p.environment_location = 'https://api.plaid.com/'
end
- it { expect(Plaid.auth('connect','plaid_test','plaid_good','wells')).to raise_error }
+ it { expect{Plaid.auth('connect','plaid_bad','plaid_bad','wells')}.to raise_error }
end
end
# Authentication flow specs - returns Plaid::User
# TODO: Abstract the config from each section with the result in passing tests
@@ -52,201 +52,233 @@
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
user = Plaid.auth('connect','plaid_test','plaid_good','wells')
- it { expect(user.accounts.blank?).to be_false }
+ it { expect(user.accounts.empty?).to be_falsey }
end
context 'has correct credentials for single factor auth, authenticates to the auth path' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
user = Plaid.auth('auth','plaid_test','plaid_good','wells')
- it { expect(user.accounts[0].numbers.nil?).to be_false }
+ it { expect(user.accounts[0].numbers.nil?).to be_falsey }
end
context 'has correct username, but incorrect password for single factor auth under auth path' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.auth('auth','plaid_test','plaid_bad','wells')).to raise_error }
+ it { expect{Plaid.auth('auth','plaid_test','plaid_bad','wells')}.to raise_error }
end
context 'has incorrect username under auth path' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.auth('auth','plaid_bad','plaid_bad','wells')).to raise_error }
+ it { expect{Plaid.auth('auth','plaid_bad','plaid_bad','wells')}.to raise_error }
end
context 'has correct username, but incorrect password for single factor auth under connect path' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.auth('connect','plaid_test','plaid_bad','wells')).to raise_error }
+ it { expect{Plaid.auth('connect','plaid_test','plaid_bad','wells')}.to raise_error }
end
context 'has incorrect username under connect path' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.auth('connect','plaid_bad','plaid_bad','wells')).to raise_error }
+ it { expect{Plaid.auth('connect','plaid_bad','plaid_bad','wells')}.to raise_error }
end
context 'has to enter MFA credentials' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- user = Plaid.auth('connect','plaid_selections', 'plaid_good','wells')
- it { expect(user.accounts).to eq 'Requires further authentication' }
+ user = Plaid.auth('connect','plaid_selections', 'plaid_good','bofa')
+ it { expect(user.api_res).to eq 'Requires further authentication' }
end
context 'enters correct information with locked account' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
user = Plaid.auth('connect','plaid_selections', 'plaid_locked','wells')
- it { expect(user.accounts).to eq 'User account is locked' }
+ it { expect(user.api_res).to eq 'User account is locked' }
end
end
-=begin
- TODO: Finish up these tests
# Institution specs
- describe Plaid::Institution do
+ describe '#Institution' do
+ context 'when a single institution is found' do
+ Plaid.config do |p|
+ p.customer_id = 'test_id'
+ p.secret = 'test_secret'
+ p.environment_location = 'https://tartan.plaid.com/'
+ end
+ institution = Plaid.institution('5301a93ac140de84910000e0')
+ it { expect(institution.class).to eq(Plaid::Institution) }
+ end
- context 'when institution is found' do
+ context 'when all institutions are found' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- institution = Plaid.institution('amex')
- it { expect(institution).to be instance_of Plaid::Institution }
+ institution = Plaid.institution
+ it { expect(institution).to be_kind_of(Array) }
end
+=begin TODO: Get this test passing
context 'when institution is not found' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.institution('dumb_bank')).to raise_error }
+ res = Plaid.institution('dumb_bank')
+ it { expect(res).to eq('Bank not found') }
end
+=end
end
# Category specs
- describe Plaid::Category do
-
- context 'when category is found' do
+ describe '#Category' do
+ context 'when a single category is found' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
category = Plaid.category('17001013')
- it { expect(category).to be instance_of Plaid::Category }
+ it { expect(category.class).to eq (Plaid::Category) }
end
+ context 'when all categories are found' do
+ Plaid.config do |p|
+ p.customer_id = 'test_id'
+ p.secret = 'test_secret'
+ p.environment_location = 'https://tartan.plaid.com/'
+ end
+ category = Plaid.category
+ it { expect(category).to be_kind_of(Array)}
+ end
+
+=begin TODO: Get this test passing
context 'when category is not found' do
Plaid.config do |p|
p.customer_id = 'test_id'
p.secret = 'test_secret'
p.environment_location = 'https://tartan.plaid.com/'
end
- it { expect(Plaid.category('dumb_cat')).to raise_error }
+ it { expect { Plaid.category('dumb_cat') }.to raise_error }
end
+=end
end
-end
+ ########## Plaid instantiated user specs ##########
-########## Plaid instantiated user specs ##########
+ describe '#User' do
+ # MFA specs - after user is instantiated,
+ describe '#mfa_authentication' do
-describe Plaid::User do
- subject(:success_user) { Plaid.auth('connect','plaid_test','plaid_good','wells') }
- subject(:mfa_user) { Plaid.auth('connect','plaid_selections', 'plaid_good','wells') }
+ context 'enters correct credentials for MFA auth and authenticates' do
+ Plaid.config do |p|
+ p.customer_id = 'test_id'
+ p.secret = 'test_secret'
+ p.environment_location = 'https://tartan.plaid.com/'
+ end
+ new_mfa_user = Plaid.auth('connect','plaid_selections', 'plaid_good','bofa')
+ new_mfa_user.mfa_authentication('tomato','bofa')
+ it { expect(new_mfa_user.accounts).to be_truthy }
+ end
- # MFA specs - after user is instantiated,
- describe '#mfa_authentication' do
- context 'has to enter another round of MFA credentials' do
- res = user.mfa_authenticaiton('again')
- expect(res).to eq 'Another round requested'
- end
+ context 'has to enter another round of MFA credentials' do
+ Plaid.config do |p|
+ p.customer_id = 'test_id'
+ p.secret = 'test_secret'
+ p.environment_location = 'https://tartan.plaid.com/'
+ end
+ mfa_again = Plaid.auth('connect','plaid_selections', 'plaid_good','bofa')
+ mfa_again.mfa_authentication('again','bofa')
+ it { expect(mfa_again.api_res).to eq 'Requires further authentication' }
+ end
- context 'enters correct credentials for MFA auth and authenticates' do
- user.mfa_authentication('tomato')
- expect(user.accounts).to be_truthy
+ context 'enters incorrect credentials for MFA auth' do
+ Plaid.config do |p|
+ p.customer_id = 'test_id'
+ p.secret = 'test_secret'
+ p.environment_location = 'https://tartan.plaid.com/'
+ end
+ mfa_user = Plaid.auth('connect','plaid_selections', 'plaid_good','bofa')
+ mfa_user.mfa_authentication('tomato','bofa')
+ mfa_user = Plaid.auth('connect','plaid_selections', 'plaid_good','bofa')
+ it { expect { mfa_user.mfa_authentication('bad','bofa') }.to raise_error }
+ end
end
- context 'enters incorrect credentials for MFA auth' do
- res = user.mfa_authentication('bad')
- expect(res).to eq 'Incorrect answer to MFA'
- end
- end
+ # Auth specs
+ describe '#get_auth' do
+ auth_user = Plaid.auth('auth','plaid_test','plaid_good','wells')
+ connect_user = Plaid.auth('connect','plaid_test','plaid_good','wells')
- # Upgrade specs - either pass or fails
- describe '#upgrade' do
- context 'auth upgrade is successful' do
- user.upgrade('auth')
- expect(user.auth).to be true
- end
+ context 'has access and returns accounts' do
+ it { expect(auth_user.permissions[0]).to eq('auth') }
+ end
- context 'auth upgrade failed' do
- user.upgrade('auth')
- expect(user.auth).to be false
+ context 'does not have access to auth' do
+ it{ expect(connect_user.permissions.include? 'auth' ).to be false }
+ end
end
- context 'connect upgrade is successful' do
- user.upgrade('connect')
- expect(user.auth).to be true
- end
+ # Connect specs
+ describe '#get_connect' do
+ auth_user = Plaid.auth('auth','plaid_test','plaid_good','wells')
+ connect_user = Plaid.auth('connect','plaid_test','plaid_good','wells')
- context 'connect upgrade failed' do
- user.upgrade('connect')
- expect(user.auth).to be false
- end
- end
+ context 'has access and returns accounts' do
+ it { expect(connect_user.permissions[0]).to eq('connect') }
+ end
- # Auth specs
- describe '#auth' do
- context 'has access and returns accounts' do
- auth = user.auth
- expect(auth).to be true
- expect(user.accounts).to be_truthy
+ context 'does not have access to auth' do
+ it{ expect(auth_user.permissions.include? 'connect' ).to be false }
+ end
end
- context 'does not have access to auth' do
- auth = user.auth
- expect(auth).to be false
- end
- end
+ # Upgrade specs - either pass or fails
+=begin TODO: Write upgrade methods to pass without paying
+ describe '#upgrade' do
+ auth_user = Plaid.auth('auth','plaid_test','plaid_good','wells')
+ connect_user = Plaid.auth('connect','plaid_test','plaid_good','wells')
- # Connect specs
- describe '#connect' do
- context 'has access and returns accounts' do
- expect(user.connect).to be true
- expect(user.transactions).to be_truthy
- end
+ context 'auth upgrade is successful' do
+ connect_user.upgrade
+ it { expect(connect_user.get_auth).to be_truthy }
+ end
- context 'does not have access to auth' do
- expect(user.connect).to be false
+ context 'connect upgrade is successful' do
+ auth_user.upgrade
+ it { expect(auth_user.get_connect).to be_truthy }
+ end
end
- end
-
=end
+ end
end
\ No newline at end of file