-
Notifications
You must be signed in to change notification settings - Fork 40
/
routingNumberSummary_test.go
136 lines (117 loc) · 4.24 KB
/
routingNumberSummary_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
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package imagecashletter
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockRoutingNumberSummary creates a RoutingNumberSummary
func mockRoutingNumberSummary() *RoutingNumberSummary {
rns := NewRoutingNumberSummary()
rns.CashLetterRoutingNumber = "231380104"
rns.RoutingNumberTotalAmount = 100000
rns.RoutingNumberItemCount = 1
rns.UserField = ""
return rns
}
func TestRoutingNumberSummaryParseErr(t *testing.T) {
var r RoutingNumberSummary
r.Parse("asdlahsakjajf")
require.Equal(t, "", r.CashLetterRoutingNumber)
}
// TestRoutingNumberSummary creates a ReturnRoutingNumberSummary
func TestRoutingNumberSummary(t *testing.T) {
rns := mockRoutingNumberSummary()
require.NoError(t, rns.Validate())
}
// TestParseRoutingNumberSummary validates parsing a RoutingNumberSummary
func TestParseRoutingNumberSummary(t *testing.T) {
var line = "8523138010400000000100000000001 "
r := NewReader(strings.NewReader(line))
r.line = line
clh := mockCashLetterHeader()
r.addCurrentCashLetter(NewCashLetter(clh))
bh := mockBundleHeader()
b := NewBundle(bh)
rns := mockRoutingNumberSummary()
r.currentCashLetter.AddBundle(b)
r.addCurrentBundle(b)
r.currentCashLetter.AddRoutingNumberSummary(rns)
r.addCurrentRoutingNumberSummary(rns)
require.NoError(t, r.parseRoutingNumberSummary())
record := r.currentCashLetter.currentRoutingNumberSummary
require.Equal(t, "85", record.recordType)
require.Equal(t, "231380104", record.CashLetterRoutingNumberField())
require.Equal(t, "00000000100000", record.RoutingNumberTotalAmountField())
require.Equal(t, "000001", record.RoutingNumberItemCountField())
}
// testRoutingNumberSummaryString validates that a known parsed RoutingNumberSummary can return to a string of the same value
func testRoutingNumberSummaryString(t testing.TB) {
var line = "8523138010400000000100000000001 "
r := NewReader(strings.NewReader(line))
r.line = line
clh := mockCashLetterHeader()
r.addCurrentCashLetter(NewCashLetter(clh))
bh := mockBundleHeader()
rb := NewBundle(bh)
rns := mockRoutingNumberSummary()
r.currentCashLetter.AddBundle(rb)
r.addCurrentBundle(rb)
r.currentCashLetter.AddRoutingNumberSummary(rns)
r.addCurrentRoutingNumberSummary(rns)
require.NoError(t, r.parseRoutingNumberSummary())
record := r.currentCashLetter.currentRoutingNumberSummary
require.Equal(t, line, record.String())
}
// TestRoutingNumberSummaryString tests validating that a known parsed RoutingNumberSummary an return to a string of the
// same value
func TestRoutingNumberSummaryString(t *testing.T) {
testRoutingNumberSummaryString(t)
}
// BenchmarkRoutingNumberSummaryString benchmarks validating that a known parsed RoutingNumberSummary
// can return to a string of the same value
func BenchmarkRoutingNumberSummaryString(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testRoutingNumberSummaryString(b)
}
}
// TestRoutingNumberSummaryRecordType validation
func TestRoutingNumberSummaryRecordType(t *testing.T) {
rns := mockRoutingNumberSummary()
rns.recordType = "00"
err := rns.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestRoutingNumberSummaryUserField validation
func TestRoutingNumberSummaryUserField(t *testing.T) {
rns := mockRoutingNumberSummary()
rns.UserField = "®©"
err := rns.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "UserField", e.FieldName)
}
// Field Inclusion
// TestRoutingNumberSummaryFIRecordType validation
func TestRoutingNumberSummaryFIRecordType(t *testing.T) {
rns := mockRoutingNumberSummary()
rns.recordType = ""
err := rns.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestRoutingNumberSummaryFICashLetterRoutingNumber validation
func TestRoutingNumberSummaryFICashLetterRoutingNumber(t *testing.T) {
rns := mockRoutingNumberSummary()
rns.CashLetterRoutingNumber = ""
err := rns.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CashLetterRoutingNumber", e.FieldName)
}