-
-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathbank-account.spec.js
125 lines (110 loc) · 3.1 KB
/
bank-account.spec.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { BankAccount, ValueError } from './bank-account';
describe('Bank Account', () => {
test('newly opened account has zero balance', () => {
const account = new BankAccount();
account.open();
expect(account.balance).toEqual(0);
});
xtest('can deposit money', () => {
const account = new BankAccount();
account.open();
account.deposit(100);
expect(account.balance).toEqual(100);
});
xtest('can deposit money sequentially', () => {
const account = new BankAccount();
account.open();
account.deposit(100);
account.deposit(50);
expect(account.balance).toEqual(150);
});
xtest('can withdraw money', () => {
const account = new BankAccount();
account.open();
account.deposit(100);
account.withdraw(50);
expect(account.balance).toEqual(50);
});
xtest('can withdraw money sequentially', () => {
const account = new BankAccount();
account.open();
account.deposit(100);
account.withdraw(20);
account.withdraw(80);
expect(account.balance).toEqual(0);
});
xtest('checking balance of closed account throws error', () => {
const account = new BankAccount();
account.open();
account.close();
expect(() => account.balance).toThrow(ValueError);
});
xtest('deposit into closed account throws error', () => {
const account = new BankAccount();
account.open();
account.close();
expect(() => {
account.deposit(50);
}).toThrow(ValueError);
});
xtest('withdraw from closed account throws error', () => {
const account = new BankAccount();
account.open();
account.close();
expect(() => {
account.withdraw(50);
}).toThrow(ValueError);
});
xtest('close already closed account throws error', () => {
const account = new BankAccount();
account.close();
expect(() => {
account.close();
}).toThrow(ValueError);
});
xtest('open already opened account throws error', () => {
const account = new BankAccount();
account.open();
expect(() => {
account.open();
}).toThrow(ValueError);
});
xtest('reopened account does not retain balance', () => {
const account = new BankAccount();
account.open();
account.deposit(50);
account.close();
account.open();
expect(account.balance).toEqual(0);
});
xtest('cannot withdraw more than deposited', () => {
const account = new BankAccount();
account.open();
account.deposit(25);
expect(() => {
account.withdraw(50);
}).toThrow(ValueError);
});
xtest('cannot withdraw negative amount', () => {
const account = new BankAccount();
account.open();
account.deposit(100);
expect(() => {
account.withdraw(-50);
}).toThrow(ValueError);
});
xtest('cannot deposit negative amount', () => {
const account = new BankAccount();
account.open();
expect(() => {
account.deposit(-50);
}).toThrow(ValueError);
});
xtest('changing balance directly throws error', () => {
const account = new BankAccount();
account.open();
expect(() => {
account.balance = 100;
}).toThrow(Error);
});
});