-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank.test.js
75 lines (53 loc) · 2.44 KB
/
Bank.test.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
const Account = require("./Account");
const Action = require("./Action");
const StatementCreator = require("./StatementCreator");
describe("Bank Integration", () => {
const date = new Date().toLocaleDateString();
it("allows user to make a deposit", () => {
const account = new Account();
const action = new Action();
expect(account.deposit(20, action)).toBe("Deposit successful")
})
it("allows user to make a withdrawal", () => {
const account = new Account();
const action = new Action();
account.deposit(20, action)
expect(account.withdraw(20, action)).toBe("Withdrawal successful")
})
it("doesn't allow user to withdraw money they don't have", () => {
const account = new Account();
const action = new Action();
account.deposit(20, action)
expect(account.withdraw(30, action)).toBe("Withdrawal successful")
})
it("prints statement for a deposit", () => {
const account = new Account();
const action = new Action();
const statementCreator = new StatementCreator();
account.deposit(20, action)
expect(account.printStatement(statementCreator)).toBe(`date || credit || debit || balance\n${date} || 20.00 || || 20.00\n`)
})
it("prints statement for deposit and withdrawal", () => {
const account = new Account();
const action = new Action();
const statementCreator = new StatementCreator();
account.deposit(20, action)
account.withdraw(10, action)
expect(account.printStatement(statementCreator)).toBe(`date || credit || debit || balance\n${date} || || 10.00 || 10.00\n${date} || 20.00 || || 20.00\n`)
})
it("converts string amount to number when making a deposit", () => {
const account = new Account();
const action = new Action();
const statementCreator = new StatementCreator();
expect(account.deposit('20', action)).toBe("Deposit successful");
expect(account.printStatement(statementCreator)).toBe(`date || credit || debit || balance\n${date} || 20.00 || || 20.00\n`)
})
it("allows user to make a withdrawal when amount is a string", () => {
const account = new Account();
const action = new Action();
const statementCreator = new StatementCreator();
account.deposit(20, action)
expect(account.withdraw('10', action)).toBe("Withdrawal successful")
expect(account.printStatement(statementCreator)).toBe(`date || credit || debit || balance\n${date} || || 10.00 || 10.00\n${date} || 20.00 || || 20.00\n`)
})
})