forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addenda16_test.go
332 lines (289 loc) · 10.7 KB
/
addenda16_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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// 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"
)
// mockAddenda16 creates a mock Addenda16 record
func mockAddenda16() *Addenda16 {
addenda16 := NewAddenda16()
addenda16.ReceiverCityStateProvince = "LetterTown*AB\\"
addenda16.ReceiverCountryPostalCode = "CA*80014\\"
addenda16.EntryDetailSequenceNumber = 00000001
return addenda16
}
// TestMockAddenda16 validates mockAddenda16
func TestMockAddenda16(t *testing.T) {
addenda16 := mockAddenda16()
if err := addenda16.Validate(); err != nil {
t.Error("mockAddenda16 does not validate and will break other tests")
}
}
// testAddenda16Parse parses Addenda16 record
func testAddenda16Parse(t testing.TB) {
Addenda16 := NewAddenda16()
line := "716LetterTown*AB\\ CA*80014\\ 0000001"
Addenda16.Parse(line)
// walk the Addenda16 struct
if Addenda16.recordType != "7" {
t.Errorf("expected %v got %v", "7", Addenda16.recordType)
}
if Addenda16.TypeCode != "16" {
t.Errorf("expected %v got %v", "16", Addenda16.TypeCode)
}
if Addenda16.ReceiverCityStateProvince != "LetterTown*AB\\" {
t.Errorf("expected %v got %v", "LetterTown*AB\\", Addenda16.ReceiverCityStateProvince)
}
if Addenda16.ReceiverCountryPostalCode != "CA*80014\\" {
t.Errorf("expected: %v got: %v", "CA*80014\\", Addenda16.ReceiverCountryPostalCode)
}
if Addenda16.reserved != " " {
t.Errorf("expected: %v got: %v", " ", Addenda16.reserved)
}
if Addenda16.EntryDetailSequenceNumber != 0000001 {
t.Errorf("expected: %v got: %v", 0000001, Addenda16.EntryDetailSequenceNumber)
}
}
// TestAddenda16Parse tests parsing Addenda16 record
func TestAddenda16Parse(t *testing.T) {
testAddenda16Parse(t)
}
// BenchmarkAddenda16Parse benchmarks parsing Addenda16 record
func BenchmarkAddenda16Parse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16Parse(b)
}
}
// testAddenda16ValidRecordType validates Addenda16 recordType
func testAddenda16ValidRecordType(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.recordType = "63"
err := addenda16.Validate()
if !base.Match(err, NewErrRecordType(7)) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16ValidRecordType tests validating Addenda16 recordType
func TestAddenda16ValidRecordType(t *testing.T) {
testAddenda16ValidRecordType(t)
}
// BenchmarkAddenda16ValidRecordType benchmarks validating Addenda16 recordType
func BenchmarkAddenda16ValidRecordType(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16ValidRecordType(b)
}
}
// testAddenda16ValidTypeCode validates Addenda16 TypeCode
func testAddenda16ValidTypeCode(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.TypeCode = "65"
err := addenda16.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16ValidTypeCode tests validating Addenda16 TypeCode
func TestAddenda16ValidTypeCode(t *testing.T) {
testAddenda16ValidTypeCode(t)
}
// BenchmarkAddenda16ValidTypeCode benchmarks validating Addenda16 TypeCode
func BenchmarkAddenda16ValidTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16ValidTypeCode(b)
}
}
// testAddenda16TypeCode16 TypeCode is 16 if TypeCode is a valid TypeCode
func testAddenda16TypeCode16(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.TypeCode = "05"
err := addenda16.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16TypeCode16 tests TypeCode is 16 if TypeCode is a valid TypeCode
func TestAddenda16TypeCode16(t *testing.T) {
testAddenda16TypeCode16(t)
}
// BenchmarkAddenda16TypeCode16 benchmarks TypeCode is 16 if TypeCode is a valid TypeCode
func BenchmarkAddenda16TypeCode16(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16TypeCode16(b)
}
}
// testReceiverCityStateProvinceAlphaNumeric validates ReceiverCityStateProvince is alphanumeric
func testReceiverCityStateProvinceAlphaNumeric(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.ReceiverCityStateProvince = "Jacobs®Town*PA"
err := addenda16.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestReceiverCityStateProvinceAlphaNumeric tests validating ReceiverCityStateProvince is alphanumeric
func TestReceiverCityStateProvinceAlphaNumeric(t *testing.T) {
testReceiverCityStateProvinceAlphaNumeric(t)
}
// BenchmarkReceiverCityStateProvinceAlphaNumeric benchmarks validating ReceiverCityStateProvince is alphanumeric
func BenchmarkReceiverCityStateProvinceAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testReceiverCityStateProvinceAlphaNumeric(b)
}
}
// testReceiverCountryPostalCodeAlphaNumeric validates ReceiverCountryPostalCode is alphanumeric
func testReceiverCountryPostalCodeAlphaNumeric(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.ReceiverCountryPostalCode = "US19®305"
err := addenda16.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestReceiverCountryPostalCodeAlphaNumeric tests validating ReceiverCountryPostalCode is alphanumeric
func TestReceiverCountryPostalCodeAlphaNumeric(t *testing.T) {
testReceiverCountryPostalCodeAlphaNumeric(t)
}
// BenchmarkReceiverCountryPostalCodeAlphaNumeric benchmarks validating ReceiverCountryPostalCode is alphanumeric
func BenchmarkReceiverCountryPostalCodeAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testReceiverCountryPostalCodeAlphaNumeric(b)
}
}
// testAddenda16FieldInclusionRecordType validates recordType fieldInclusion
func testAddenda16FieldInclusionRecordType(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.recordType = ""
err := addenda16.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16FieldInclusionRecordType tests validating recordType fieldInclusion
func TestAddenda16FieldInclusionRecordType(t *testing.T) {
testAddenda16FieldInclusionRecordType(t)
}
// BenchmarkAddenda16FieldInclusionRecordType benchmarks validating recordType fieldInclusion
func BenchmarkAddenda16FieldInclusionRecordType(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16FieldInclusionRecordType(b)
}
}
// testAddenda16FieldInclusionTypeCode validates TypeCode fieldInclusion
func testAddenda16FieldInclusionTypeCode(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.TypeCode = ""
err := addenda16.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16FieldInclusionTypeCode tests validating TypeCode fieldInclusion
func TestAddenda16FieldInclusionTypeCode(t *testing.T) {
testAddenda16FieldInclusionTypeCode(t)
}
// BenchmarkAddenda16FieldInclusionTypeCode benchmarks validating TypeCode fieldInclusion
func BenchmarkAddenda16FieldInclusionTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16FieldInclusionTypeCode(b)
}
}
// testAddenda16FieldInclusionReceiverCityStateProvince validates ReceiverCityStateProvince fieldInclusion
func testAddenda16FieldInclusionReceiverCityStateProvince(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.ReceiverCityStateProvince = ""
err := addenda16.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16FieldInclusionReceiverCityStateProvince tests validating ReceiverCityStateProvince fieldInclusion
func TestAddenda16FieldInclusionReceiverCityStateProvince(t *testing.T) {
testAddenda16FieldInclusionReceiverCityStateProvince(t)
}
// BenchmarkAddenda16FieldInclusionReceiverCityStateProvince benchmarks validating ReceiverCityStateProvince fieldInclusion
func BenchmarkAddenda16FieldInclusionReceiverCityStateProvince(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16FieldInclusionReceiverCityStateProvince(b)
}
}
// testAddenda16FieldInclusionReceiverCountryPostalCode validates ReceiverCountryPostalCode fieldInclusion
func testAddenda16FieldInclusionReceiverCountryPostalCode(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.ReceiverCountryPostalCode = ""
err := addenda16.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16FieldInclusionReceiverCountryPostalCode tests validating ReceiverCountryPostalCode fieldInclusion
func TestAddenda16FieldInclusionReceiverCountryPostalCode(t *testing.T) {
testAddenda16FieldInclusionReceiverCountryPostalCode(t)
}
// BenchmarkAddenda16FieldInclusionReceiverCountryPostalCode benchmarks validating ReceiverCountryPostalCode fieldInclusion
func BenchmarkAddenda16FieldInclusionReceiverCountryPostalCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16FieldInclusionReceiverCountryPostalCode(b)
}
}
// testAddenda16FieldInclusionEntryDetailSequenceNumber validates EntryDetailSequenceNumber fieldInclusion
func testAddenda16FieldInclusionEntryDetailSequenceNumber(t testing.TB) {
addenda16 := mockAddenda16()
addenda16.EntryDetailSequenceNumber = 0
err := addenda16.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda16FieldInclusionEntryDetailSequenceNumber tests validating
// EntryDetailSequenceNumber fieldInclusion
func TestAddenda16FieldInclusionEntryDetailSequenceNumber(t *testing.T) {
testAddenda16FieldInclusionEntryDetailSequenceNumber(t)
}
// BenchmarkAddenda16FieldInclusionEntryDetailSequenceNumber benchmarks validating
// EntryDetailSequenceNumber fieldInclusion
func BenchmarkAddenda16FieldInclusionEntryDetailSequenceNumber(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16FieldInclusionEntryDetailSequenceNumber(b)
}
}
// TestAddenda16String validates that a known parsed Addenda16 record can be return to a string of the same value
func testAddenda16String(t testing.TB) {
addenda16 := NewAddenda16()
// Backslash logic
var line = "716" +
"LetterTown*AB\\ " +
"CA*80014\\ " +
" " +
"0000001"
addenda16.Parse(line)
if addenda16.String() != line {
t.Errorf("Strings do not match")
}
if addenda16.TypeCode != "16" {
t.Errorf("TypeCode Expected 16 got: %v", addenda16.TypeCode)
}
}
// TestAddenda16String tests validating that a known parsed Addenda16 record can be return to a string of the same value
func TestAddenda16String(t *testing.T) {
testAddenda16String(t)
}
// BenchmarkAddenda16String benchmarks validating that a known parsed Addenda16 record can be return to a string of the same value
func BenchmarkAddenda16String(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda16String(b)
}
}