forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addenda98_test.go
281 lines (240 loc) · 6.75 KB
/
addenda98_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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// Copyright 2018 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package ach
import (
"testing"
"github.com/moov-io/base"
)
func mockAddenda98() *Addenda98 {
addenda98 := NewAddenda98()
addenda98.ChangeCode = "C01"
addenda98.OriginalTrace = "12345"
addenda98.OriginalDFI = "9101298"
addenda98.CorrectedData = "1918171614"
addenda98.TraceNumber = "91012980000088"
return addenda98
}
func testAddenda98Parse(t testing.TB) {
addenda98 := NewAddenda98()
line := "798C01099912340000015 091012981918171614 091012980000088"
addenda98.Parse(line)
// walk the Addenda98 struct
if addenda98.recordType != "7" {
t.Errorf("expected %v got %v", "7", addenda98.recordType)
}
if addenda98.TypeCode != "98" {
t.Errorf("expected %v got %v", "98", addenda98.TypeCode)
}
if addenda98.ChangeCode != "C01" {
t.Errorf("expected %v got %v", "C01", addenda98.ChangeCode)
}
if addenda98.OriginalTrace != "099912340000015" {
t.Errorf("expected %v got %v", "099912340000015", addenda98.OriginalTrace)
}
if addenda98.OriginalDFI != "09101298" {
t.Errorf("expected %s got %s", "09101298", addenda98.OriginalDFI)
}
if addenda98.CorrectedData != "1918171614" {
t.Errorf("expected %v got %v", "1918171614", addenda98.CorrectedData)
}
if addenda98.TraceNumber != "091012980000088" {
t.Errorf("expected %v got %v", "091012980000088", addenda98.TraceNumber)
}
}
func TestAddenda98Parse(t *testing.T) {
testAddenda98Parse(t)
}
func BenchmarkAddenda98Parse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98Parse(b)
}
}
func testAddenda98String(t testing.TB) {
addenda98 := NewAddenda98()
line := "798C01099912340000015 091012981918171614 091012980000088"
addenda98.Parse(line)
if addenda98.String() != line {
t.Errorf("\n expected: %v\n got : %v", line, addenda98.String())
}
}
func TestAddenda98String(t *testing.T) {
testAddenda98String(t)
}
func BenchmarkAddenda98String(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98String(b)
}
}
func testAddenda98ValidRecordType(t testing.TB) {
addenda98 := mockAddenda98()
addenda98.recordType = "63"
err := addenda98.Validate()
if !base.Match(err, NewErrRecordType(7)) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda98ValidRecordType(t *testing.T) {
testAddenda98ValidRecordType(t)
}
func BenchmarkAddenda98ValidRecordType(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98ValidRecordType(b)
}
}
func testAddenda98ValidTypeCode(t testing.TB) {
addenda98 := mockAddenda98()
addenda98.TypeCode = "05"
err := addenda98.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda98ValidTypeCode(t *testing.T) {
testAddenda98ValidTypeCode(t)
}
func BenchmarkAddenda98ValidTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98ValidTypeCode(b)
}
}
func testAddenda98ValidCorrectedData(t testing.TB) {
addenda98 := mockAddenda98()
addenda98.CorrectedData = ""
err := addenda98.Validate()
if !base.Match(err, ErrAddenda98CorrectedData) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda98ValidCorrectedData(t *testing.T) {
testAddenda98ValidCorrectedData(t)
}
func BenchmarkAddenda98ValidCorrectedData(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98ValidCorrectedData(b)
}
}
func testAddenda98ValidateTrue(t testing.TB) {
addenda98 := mockAddenda98()
addenda98.ChangeCode = "C11"
err := addenda98.Validate()
// no error expected
if !base.Match(err, nil) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda98ValidateTrue(t *testing.T) {
testAddenda98ValidateTrue(t)
}
func BenchmarkAddenda98ValidateTrue(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98ValidateTrue(b)
}
}
func testAddenda98ValidateChangeCodeFalse(t testing.TB) {
addenda98 := mockAddenda98()
addenda98.ChangeCode = "C63"
err := addenda98.Validate()
if !base.Match(err, ErrAddenda98ChangeCode) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda98ValidateChangeCodeFalse(t *testing.T) {
testAddenda98ValidateChangeCodeFalse(t)
}
func BenchmarkAddenda98ValidateChangeCodeFalse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98ValidateChangeCodeFalse(b)
}
}
func testAddenda98OriginalTraceField(t testing.TB) {
addenda98 := mockAddenda98()
exp := "000000000012345"
if addenda98.OriginalTraceField() != exp {
t.Errorf("expected %v received %v", exp, addenda98.OriginalTraceField())
}
}
func TestAddenda98OriginalTraceField(t *testing.T) {
testAddenda98OriginalTraceField(t)
}
func BenchmarkAddenda98OriginalTraceField(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98OriginalTraceField(b)
}
}
func testAddenda98OriginalDFIField(t testing.TB) {
addenda98 := mockAddenda98()
exp := "09101298"
if addenda98.OriginalDFIField() != exp {
t.Errorf("expected %v received %v", exp, addenda98.OriginalDFIField())
}
}
func TestAddenda98OriginalDFIField(t *testing.T) {
testAddenda98OriginalDFIField(t)
}
func BenchmarkAddenda98OriginalDFIField(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98OriginalDFIField(b)
}
}
func testAddenda98CorrectedDataField(t testing.TB) {
addenda98 := mockAddenda98()
exp := "1918171614 " // 29 char
if addenda98.CorrectedDataField() != exp {
t.Errorf("expected %v received %v", exp, addenda98.CorrectedDataField())
}
}
func TestAddenda98CorrectedDataField(t *testing.T) {
testAddenda98CorrectedDataField(t)
}
func BenchmarkAddenda98CorrectedDataField(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98CorrectedDataField(b)
}
}
func testAddenda98TraceNumberField(t testing.TB) {
addenda98 := mockAddenda98()
exp := "091012980000088"
if addenda98.TraceNumberField() != exp {
t.Errorf("expected %v received %v", exp, addenda98.TraceNumberField())
}
}
func TestAddenda98TraceNumberField(t *testing.T) {
testAddenda98TraceNumberField(t)
}
func BenchmarkAddenda98TraceNumberField(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98TraceNumberField(b)
}
}
// testAddenda98TypeCodeNil validates TypeCode is ""
func testAddenda98TypeCodeNil(t testing.TB) {
addenda98 := mockAddenda98()
addenda98.TypeCode = ""
err := addenda98.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda98TypeCodeES tests TypeCode is ""
func TestAddenda98TypeCodeNil(t *testing.T) {
testAddenda98TypeCodeNil(t)
}
// BenchmarkAddenda98TypeCodeNil benchmarks TypeCode is ""
func BenchmarkAddenda98TypeCodeNil(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda98TypeCodeNil(b)
}
}