/
account_test.go
55 lines (40 loc) · 1.06 KB
/
account_test.go
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
package main
import (
"testing"
"github.com/shopspring/decimal"
)
func TestTransactions(t *testing.T) {
a := &Account{IsActive: true, CurrencyCode: "AUD"}
credit10, _ := decimal.NewFromString("10.0")
debit, _ := decimal.NewFromString("0.0")
trans := Transaction{
Credit: credit10,
Debit: debit,
IsCleared: true,
}
a.AddTransaction(trans)
total := a.GetTotal()
if total.String() != credit10.String() {
t.Errorf("Total not right, expected %v got %v", credit10, a.GetTotal())
}
if a.GetClearedTotal().String() != credit10.String() {
t.Error("Cleared Total not right")
}
credit, _ := decimal.NewFromString("0.0")
debit, _ = decimal.NewFromString("5.0")
trans.Credit = credit
trans.Debit = debit
trans.IsCleared = false
a.AddTransaction(trans)
if a.GetTotal().String() != debit.String() {
t.Error("Total not right")
}
if a.GetClearedTotal().String() != credit10.String() {
t.Error("Cleared total not right")
}
tr := a.GetTransactions()
if len(tr) != 2 {
t.Error("Number of transactions not right")
}
// log.Printf("%v\n", tr)
}