-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
104 lines (85 loc) · 3.84 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require_relative 'bank'
require_relative 'account'
require_relative 'enums'
# This is a simple bank program.
# A bank has a name.
# A bank also has several accounts.
# An account has an owner and a balance.
# Account types include: Checking, Savings.
# There are two types of Checking accounts: Individual, Money Market.
# Individual checking accounts have a withdrawal limit of 1000 dollars.
#
# Transactions are made on accounts.
# Transaction types include: Deposit, Withdraw, and Transfer.
# Include unit tests that, at a minimum, invoke a deposit, a withdrawal, and transfer.
describe Banking::Account do
let(:bank) { Bank.new('Bank of America') }
let(:saving) { bank.open_account!('John', AccountType::Saving) }
let(:checking_individual) { bank.open_account!('Jane', AccountType::Checking, CheckingAccountType::Individual) }
let(:checking_money_market) { bank.open_account!('Zack', AccountType::Checking, CheckingAccountType::MoneyMarket) }
describe '#deposit!' do
it 'can deposit to any account' do
saving.deposit!(1000)
checking_individual.deposit!(2000)
checking_money_market.deposit!(3000)
expect(saving.balance).to eq(1000)
expect(checking_individual.balance).to eq(2000)
expect(checking_money_market.balance).to eq(3000)
end
end
describe '#withdraw!' do
before do
saving.deposit!(1000)
checking_individual.deposit!(2000)
checking_money_market.deposit!(3000)
end
it 'cannot withdraw from saving account' do
expect { saving.withdraw!(100) }.to raise_error('Can withdraw or transfer from checking account only')
end
it 'cannot withdraw more than balance' do
expect { checking_individual.withdraw!(10000) }.to raise_error('Insufficient balance')
expect { checking_money_market.withdraw!(10000) }.to raise_error('Insufficient balance')
end
it 'cannot withdraw more than 1000 in individual account' do
expect { checking_individual.withdraw!(1001) }.to raise_error('Exceeded withdrawl limit for individual checking account')
end
it 'can withdraw from individual checking account' do
checking_individual.withdraw!(300)
expect(checking_individual.balance).to eq 1700
end
it 'can withdraw from money market checking account' do
checking_money_market.withdraw!(2500)
expect(checking_money_market.balance).to eq 500
end
end
describe '#transfer!' do
before do
saving.deposit!(1000)
checking_individual.deposit!(2000)
checking_money_market.deposit!(3000)
end
it 'cannot transfer to yourself' do
expect { checking_individual.transfer!(checking_individual, 100) }.to raise_error('Cannot transfer to yourself')
end
it 'cannot transfer from saving account' do
expect { saving.transfer!(checking_individual, 100) }.to raise_error('Can withdraw or transfer from checking account only')
end
it 'cannot transfer more than balance' do
expect { checking_individual.transfer!(checking_money_market, 10000) }.to raise_error('Insufficient balance')
expect { checking_money_market.transfer!(checking_individual, 10000) }.to raise_error('Insufficient balance')
end
it 'cannot transfer more than 1000 in individual account' do
expect { checking_individual.transfer!(checking_money_market, 1001) }.to raise_error('Exceeded withdrawl limit for individual checking account')
end
it 'can transfer from individual checking account' do
checking_individual.transfer!(checking_money_market, 300)
expect(checking_individual.balance).to eq 1700
expect(checking_money_market.balance).to eq 3300
end
it 'can transfer from money market checking account' do
checking_money_market.transfer!(checking_individual, 300)
expect(checking_individual.balance).to eq 2300
expect(checking_money_market.balance).to eq 2700
end
end
end