-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAccounting_test.go
executable file
·156 lines (140 loc) · 3.93 KB
/
Accounting_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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package acccore
import (
"context"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestAccounting_CreateNewAccount(t *testing.T) {
ClearInMemoryTables()
ctx := context.Background()
acc := &Accounting{
accountManager: &InMemoryAccountManager{},
transactionManager: &InMemoryTransactionManager{},
journalManager: &InMemoryJournalManager{},
uniqueIDGenerator: &RandomGenUniqueIDGenerator{
Length: 10,
LowerAlpha: false,
UpperAlpha: true,
Numeric: true,
CharSetBuffer: nil,
},
}
account, err := acc.CreateNewAccount(ctx, "", "Test Account", "Gold base test user account", "1.1", "GOLD", CREDIT, "aCreator")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
exist, err := acc.accountManager.IsAccountIDExist(ctx, account.GetAccountNumber())
if err != nil {
t.Error(err.Error())
t.FailNow()
}
if !exist {
t.Error("account should exist after creation")
t.FailNow()
}
render, err := acc.transactionManager.RenderTransactionsOnAccount(ctx, time.Now().Add(-2*time.Hour), time.Now().Add(2*time.Hour), account, PageRequest{
PageNo: 1,
ItemSize: 10,
Sorts: nil,
})
if err != nil {
t.Error(err.Error())
t.FailNow()
} else {
t.Log(render)
}
}
func TestDecimal(t *testing.T) {
pa := decimal.NewFromInt(123)
pa = pa.Add(decimal.NewFromInt(1))
assert.True(t, pa.Equal(decimal.NewFromInt(124)))
}
func TestAccounting_CreateNewJournal(t *testing.T) {
ClearInMemoryTables()
ctx := context.Background()
acc := &Accounting{
accountManager: &InMemoryAccountManager{},
transactionManager: &InMemoryTransactionManager{},
journalManager: &InMemoryJournalManager{},
uniqueIDGenerator: &RandomGenUniqueIDGenerator{
Length: 10,
LowerAlpha: false,
UpperAlpha: true,
Numeric: true,
CharSetBuffer: nil,
},
}
goldLoan, err := acc.CreateNewAccount(ctx, "", "Gold Loan", "Gold base loan reserve", "1.1", "GOLD", DEBIT, "aCreator")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
alphaCreditor, err := acc.CreateNewAccount(ctx, "", "Gold Creditor Alpha", "Gold base debitor alpha", "2.1", "GOLD", CREDIT, "aCreator")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
betaDebitor, err := acc.CreateNewAccount(ctx, "", "Gold Debitor Alpha", "Gold base creditor beta", "3.1", "GOLD", DEBIT, "aCreator")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
topupTransactions := []TransactionInfo{
{
AccountNumber: goldLoan.GetAccountNumber(),
Description: "Added Gold Reserve",
TxType: DEBIT,
Amount: decimal.NewFromInt(1000000),
},
{
AccountNumber: alphaCreditor.GetAccountNumber(),
Description: "Added Gold Equity",
TxType: CREDIT,
Amount: decimal.NewFromInt(1000000),
},
}
journal, err := acc.CreateNewJournal(ctx, "Creditor Topup Gold", topupTransactions, "aCreator")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
if journal == nil {
t.Error("No error but journal nil")
t.FailNow()
}
t.Log(acc.journalManager.RenderJournal(ctx, journal))
goldPurchaseTransaction := []TransactionInfo{
{
AccountNumber: betaDebitor.GetAccountNumber(),
Description: "Add debitor AR",
TxType: DEBIT,
Amount: decimal.NewFromInt(200000),
},
{
AccountNumber: goldLoan.GetAccountNumber(),
Description: "Gold Disbursement",
TxType: CREDIT,
Amount: decimal.NewFromInt(200000),
},
}
journal, err = acc.CreateNewJournal(ctx, "GOLD purchase transaction", goldPurchaseTransaction, "aCreator")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
t.Log(acc.journalManager.RenderJournal(ctx, journal))
render, err := acc.transactionManager.RenderTransactionsOnAccount(ctx, time.Now().Add(-2*time.Hour), time.Now().Add(2*time.Hour), goldLoan, PageRequest{
PageNo: 1,
ItemSize: 10,
Sorts: nil,
})
if err != nil {
t.Error(err.Error())
t.FailNow()
} else {
t.Log(render)
}
}