-
Notifications
You must be signed in to change notification settings - Fork 1
/
Transaction.unit.ts
41 lines (35 loc) · 1.32 KB
/
Transaction.unit.ts
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
import { Transaction } from './Transaction';
import { Amount } from './Amount';
import { Description } from './Description';
import { TransactionErrors } from './TransactionErrors';
test('Create transaction', () => {
const date = new Date();
const result = Transaction.create({
balance: Amount.create({ value: 100 }).value,
delta: Amount.create({ value: -100 }).value,
date,
description: Description.create({ value: 'Test transaction' }).value,
});
expect(result.isSuccess).toBe(true);
const transaction = result.value;
expect(transaction.balance.value).toBe(100);
expect(transaction.delta.value).toBe(-100);
expect(transaction.date).toBe(date);
expect(transaction.description.value).toBe('Test transaction');
});
test('initial transaction has 0 balance', () => {
const transaction = Transaction.Initial();
expect(transaction.balance.value).toBe(0);
expect(transaction.delta.value).toBe(0);
});
it('fails with negative balance', () => {
const date = new Date();
const result = Transaction.create({
balance: Amount.create({ value: -1 }).value,
delta: Amount.create({ value: -100 }).value,
date,
description: Description.create({ value: 'Test transaction' }).value,
});
expect(result.isFailure).toBe(true);
expect(result.error).toBeInstanceOf(TransactionErrors.NegativeBalance);
});