-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.test.js
66 lines (52 loc) · 1.73 KB
/
printer.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
const Printer = require("./printer");
const Transaction = require("./transaction");
jest.mock("./transaction");
describe("Printer", () => {
beforeEach(() => {
printer = new Printer();
transaction = new Transaction();
secondTransaction = new Transaction();
transaction.getDate.mockImplementation(() => {
return "19/06/2022";
});
transaction.getCredit.mockImplementation(() => {
return "500.00";
});
transaction.getDebit.mockImplementation(() => {
return null;
});
transaction.getBalance.mockImplementation(() => {
return "500.00";
});
secondTransaction.getDate.mockImplementation(() => {
return "20/06/2022";
});
secondTransaction.getCredit.mockImplementation(() => {
return "500.00";
});
secondTransaction.getDebit.mockImplementation(() => {
return null;
});
secondTransaction.getBalance.mockImplementation(() => {
return "1000.00";
});
Transaction.mockClear();
});
describe("printStatement", () => {
it("should return only the header if no transactions have occured", () => {
expect(printer.printStatement([])).toEqual(
"date || credit || debit || balance\n"
);
});
it("should take an array of transaction objects and return them as a string", () => {
expect(printer.printStatement([transaction])).toEqual(
"date || credit || debit || balance\n19/06/2022 || 500.00 || || 500.00"
);
});
it("should handle multiple transactions", () => {
expect(printer.printStatement([secondTransaction, transaction])).toEqual(
"date || credit || debit || balance\n20/06/2022 || 500.00 || || 1000.00\n19/06/2022 || 500.00 || || 500.00"
);
});
});
});