-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_footer_test.go
65 lines (61 loc) · 1.83 KB
/
file_footer_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
package cadeft
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseFileFooter(t *testing.T) {
r := require.New(t)
type testCase struct {
in string
expected FileFooter
}
cases := map[string]testCase{
"valid footer": {
in: "Z000000004000000061000010000000002016500000005000000000722200000000600000000000000000000000000000000000000000000",
expected: FileFooter{
RecordHeader: RecordHeader{
RecordType: FooterRecord,
OriginatorID: "0000000610",
FileCreationNum: 1,
recordCount: 4,
},
TotalValueOfDebit: 20165,
TotalCountOfDebit: 5,
TotalValueOfCredit: 72220,
TotalCountOfCredit: 6,
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ff := FileFooter{}
err := ff.Parse(tc.in)
r.NoError(err)
r.Equal(tc.expected, ff)
})
}
}
func TestBuildFileFooter(t *testing.T) {
r := require.New(t)
simpleDebitTxn := Debit{BaseTxn: BaseTxn{Amount: 1000}}
simpleDebitReturnTxn := DebitReturn{BaseTxn: BaseTxn{Amount: 1000}}
simpleCreditTxn := Credit{BaseTxn: BaseTxn{Amount: 1000}}
simpleCreditReturn := CreditReturn{BaseTxn: BaseTxn{Amount: 1000}}
txns := []Transaction{&simpleDebitTxn, &simpleCreditTxn, &simpleDebitReturnTxn, &simpleCreditReturn}
recordHeader := RecordHeader{
RecordType: FooterRecord,
OriginatorID: "0000000610",
FileCreationNum: 1,
}
ff := NewFileFooter(recordHeader, txns)
r.Equal(int64(2000), ff.TotalValueOfCredit)
r.Equal(int64(2000), ff.TotalValueOfDebit)
r.Equal(int64(2), ff.TotalCountOfCredit)
r.Equal(int64(2), ff.TotalCountOfDebit)
s, err := ff.Build()
r.NoError(err)
expectedFile := fmt.Sprintf("Z000000000000000061000010000000000200000000002000000000020000000000200000000000000000000000000000000000000000000%s", strings.Repeat(" ", 1352))
r.Equal(expectedFile, s)
}