forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addenda14_test.go
399 lines (348 loc) · 12.9 KB
/
addenda14_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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// Licensed to The Moov Authors under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. The Moov Authors licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package ach
import (
"testing"
"github.com/moov-io/base"
)
// mockAddenda14 creates a mock Addenda14 record
func mockAddenda14() *Addenda14 {
addenda14 := NewAddenda14()
addenda14.RDFIName = "Citadel Bank"
addenda14.RDFIIDNumberQualifier = "01"
addenda14.RDFIIdentification = "231380104"
addenda14.RDFIBranchCountryCode = "US"
addenda14.EntryDetailSequenceNumber = 00000001
return addenda14
}
// TestMockAddenda14 validates mockAddenda14
func TestMockAddenda14(t *testing.T) {
addenda14 := mockAddenda14()
if err := addenda14.Validate(); err != nil {
t.Error("mockAddenda14 does not validate and will break other tests")
}
}
// testAddenda14Parse parses Addenda14 record
func testAddenda14Parse(t testing.TB) {
Addenda14 := NewAddenda14()
line := "714Citadel Bank 01231380104 US 0000001"
Addenda14.Parse(line)
// walk the Addenda14 struct
if Addenda14.TypeCode != "14" {
t.Errorf("expected %v got %v", "14", Addenda14.TypeCode)
}
if Addenda14.RDFIName != "Citadel Bank" {
t.Errorf("expected %v got %v", "Citadel Bank", Addenda14.RDFIName)
}
if Addenda14.RDFIIDNumberQualifier != "01" {
t.Errorf("expected: %v got: %v", "01", Addenda14.RDFIIDNumberQualifier)
}
if Addenda14.RDFIIdentification != "231380104" {
t.Errorf("expected: %v got: %v", "928383-23938", Addenda14.RDFIIdentification)
}
if Addenda14.RDFIBranchCountryCode != "US" {
t.Errorf("expected: %s got: %s", "US", Addenda14.RDFIBranchCountryCode)
}
if Addenda14.EntryDetailSequenceNumber != 0000001 {
t.Errorf("expected: %v got: %v", 0000001, Addenda14.EntryDetailSequenceNumber)
}
}
// TestAddenda14Parse tests parsing Addenda14 record
func TestAddenda14Parse(t *testing.T) {
testAddenda14Parse(t)
}
// BenchmarkAddenda14Parse benchmarks parsing Addenda14 record
func BenchmarkAddenda14Parse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14Parse(b)
}
}
// testAddenda14ValidTypeCode validates Addenda14 TypeCode
func testAddenda14ValidTypeCode(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.TypeCode = "65"
err := addenda14.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14ValidTypeCode tests validating Addenda14 TypeCode
func TestAddenda14ValidTypeCode(t *testing.T) {
testAddenda14ValidTypeCode(t)
}
// BenchmarkAddenda14ValidTypeCode benchmarks validating Addenda14 TypeCode
func BenchmarkAddenda14ValidTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14ValidTypeCode(b)
}
}
// testAddenda14TypeCode14 TypeCode is 14 if TypeCode is a valid TypeCode
func testAddenda14TypeCode14(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.TypeCode = "05"
err := addenda14.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14TypeCode14 tests TypeCode is 14 if TypeCode is a valid TypeCode
func TestAddenda14TypeCode14(t *testing.T) {
testAddenda14TypeCode14(t)
}
// BenchmarkAddenda14TypeCode14 benchmarks TypeCode is 14 if TypeCode is a valid TypeCode
func BenchmarkAddenda14TypeCode14(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14TypeCode14(b)
}
}
// testRDFINameAlphaNumeric validates RDFIName is alphanumeric
func testRDFINameAlphaNumeric(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIName = "Wells®Fargo"
err := addenda14.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestRDFINameAlphaNumeric tests validating RDFIName is alphanumeric
func TestRDFINameAlphaNumeric(t *testing.T) {
testRDFINameAlphaNumeric(t)
}
// BenchmarkRDFINameAlphaNumeric benchmarks validating RDFIName is alphanumeric
func BenchmarkRDFINameAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testRDFINameAlphaNumeric(b)
}
}
// testRDFIIDNumberQualifierValid validates RDFIIDNumberQualifier is valid
func testRDFIIDNumberQualifierValid(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIIDNumberQualifier = "®1"
err := addenda14.Validate()
if !base.Match(err, ErrIDNumberQualifier) {
t.Errorf("%T: %s", err, err)
}
}
// TestRDFIIDNumberQualifierValid tests validating RDFIIDNumberQualifier is valid
func TestRDFIIDNumberQualifierValid(t *testing.T) {
testRDFIIDNumberQualifierValid(t)
}
// BenchmarkRDFIIDNumberQualifierValid benchmarks validating RDFIIDNumberQualifier is valid
func BenchmarkRDFIIDNumberQualifierValid(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testRDFIIDNumberQualifierValid(b)
}
}
// testRDFIIdentificationAlphaNumeric validates RDFIIdentification is alphanumeric
func testRDFIIdentificationAlphaNumeric(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIIdentification = "®121042882"
err := addenda14.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestRDFIIdentificationAlphaNumeric tests validating RDFIIdentification is alphanumeric
func TestRDFIIdentificationAlphaNumeric(t *testing.T) {
testRDFIIdentificationAlphaNumeric(t)
}
// BenchmarkRDFIIdentificationAlphaNumeric benchmarks validating RDFIIdentification is alphanumeric
func BenchmarkRDFIIdentificationAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testRDFIIdentificationAlphaNumeric(b)
}
}
// testRDFIBranchCountryCodeAlphaNumeric validates RDFIBranchCountryCode is alphanumeric
func testRDFIBranchCountryCodeAlphaNumeric(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIBranchCountryCode = "U®"
err := addenda14.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestRDFIBranchCountryCodeAlphaNumeric tests validating RDFIBranchCountryCode is alphanumeric
func TestRDFIBranchCountryCodeAlphaNumeric(t *testing.T) {
testRDFIBranchCountryCodeAlphaNumeric(t)
}
// BenchmarkRDFIBranchCountryCodeAlphaNumeric benchmarks validating RDFIBranchCountryCode is alphanumeric
func BenchmarkRDFIBranchCountryCodeAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testRDFIBranchCountryCodeAlphaNumeric(b)
}
}
// testAddenda14FieldInclusionTypeCode validates TypeCode fieldInclusion
func testAddenda14FieldInclusionTypeCode(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.TypeCode = ""
err := addenda14.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14FieldInclusionTypeCode tests validating TypeCode fieldInclusion
func TestAddenda14FieldInclusionTypeCode(t *testing.T) {
testAddenda14FieldInclusionTypeCode(t)
}
// BenchmarkAddenda14FieldInclusionTypeCode benchmarks validating TypeCode fieldInclusion
func BenchmarkAddenda14FieldInclusionTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14FieldInclusionTypeCode(b)
}
}
// testAddenda14FieldInclusionRDFIName validates RDFIName fieldInclusion
func testAddenda14FieldInclusionRDFIName(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIName = ""
err := addenda14.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14FieldInclusionRDFIName tests validating RDFIName fieldInclusion
func TestAddenda14FieldInclusionRDFIName(t *testing.T) {
testAddenda14FieldInclusionRDFIName(t)
}
// BenchmarkAddenda14FieldInclusionRDFIName benchmarks validating RDFIName fieldInclusion
func BenchmarkAddenda14FieldInclusionRDFIName(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14FieldInclusionRDFIName(b)
}
}
// testAddenda14FieldInclusionRDFIIDNumberQualifier validates RDFIIDNumberQualifier fieldInclusion
func testAddenda14FieldInclusionRDFIIDNumberQualifier(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIIDNumberQualifier = ""
err := addenda14.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14FieldInclusionRDFIIdNumberQualifier tests validating RDFIIdNumberQualifier fieldInclusion
func TestAddenda14FieldInclusionRDFIIdNumberQualifier(t *testing.T) {
testAddenda14FieldInclusionRDFIIDNumberQualifier(t)
}
// BenchmarkAddenda14FieldInclusionRDFIIdNumberQualifier benchmarks validating RDFIIdNumberQualifier fieldInclusion
func BenchmarkAddenda14FieldInclusionRDFIIdNumberQualifier(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14FieldInclusionRDFIIDNumberQualifier(b)
}
}
// testAddenda14FieldInclusionRDFIIdentification validates RDFIIdentification fieldInclusion
func testAddenda14FieldInclusionRDFIIdentification(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIIdentification = ""
err := addenda14.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14FieldInclusionRDFIIdentification tests validating RDFIIdentification fieldInclusion
func TestAddenda14FieldInclusionRDFIIdentification(t *testing.T) {
testAddenda14FieldInclusionRDFIIdentification(t)
}
// BenchmarkAddenda14FieldInclusionRDFIIdentification benchmarks validating RDFIIdentification fieldInclusion
func BenchmarkAddenda14FieldInclusionRDFIIdentification(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14FieldInclusionRDFIIdentification(b)
}
}
// testAddenda14FieldInclusionRDFIBranchCountryCode validates RDFIBranchCountryCode fieldInclusion
func testAddenda14FieldInclusionRDFIBranchCountryCode(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.RDFIBranchCountryCode = ""
err := addenda14.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14FieldInclusionRDFIBranchCountryCode tests validating RDFIBranchCountryCode fieldInclusion
func TestAddenda14FieldInclusionRDFIBranchCountryCode(t *testing.T) {
testAddenda14FieldInclusionRDFIBranchCountryCode(t)
}
// BenchmarkAddenda14FieldInclusionRDFIBranchCountryCode benchmarks validating RDFIBranchCountryCode fieldInclusion
func BenchmarkAddenda14FieldInclusionRDFIBranchCountryCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14FieldInclusionRDFIBranchCountryCode(b)
}
}
// testAddenda14FieldInclusionEntryDetailSequenceNumber validates EntryDetailSequenceNumber fieldInclusion
func testAddenda14FieldInclusionEntryDetailSequenceNumber(t testing.TB) {
addenda14 := mockAddenda14()
addenda14.EntryDetailSequenceNumber = 0
err := addenda14.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda14FieldInclusionEntryDetailSequenceNumber tests validating
// EntryDetailSequenceNumber fieldInclusion
func TestAddenda14FieldInclusionEntryDetailSequenceNumber(t *testing.T) {
testAddenda14FieldInclusionEntryDetailSequenceNumber(t)
}
// BenchmarkAddenda14FieldInclusionEntryDetailSequenceNumber benchmarks validating
// EntryDetailSequenceNumber fieldInclusion
func BenchmarkAddenda14FieldInclusionEntryDetailSequenceNumber(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14FieldInclusionEntryDetailSequenceNumber(b)
}
}
// TestAddenda14String validates that a known parsed Addenda14 record can be return to a string of the same value
func testAddenda14String(t testing.TB) {
addenda14 := NewAddenda14()
var line = "714Citadel Bank 231380104 US 0000001"
addenda14.Parse(line)
if addenda14.String() != line {
t.Errorf("Strings do not match")
}
if addenda14.TypeCode != "14" {
t.Errorf("TypeCode Expected 14 got: %v", addenda14.TypeCode)
}
}
// TestAddenda14String tests validating that a known parsed Addenda14 record can be return to a string of the same value
func TestAddenda14String(t *testing.T) {
testAddenda14String(t)
}
// BenchmarkAddenda14String benchmarks validating that a known parsed Addenda14 record can be return to a string of the same value
func BenchmarkAddenda14String(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda14String(b)
}
}
// TestAddenda14RuneCountInString validates RuneCountInString
func TestAddenda14RuneCountInString(t *testing.T) {
addenda14 := NewAddenda14()
var line = "714Citadel Bank 231380104 US"
addenda14.Parse(line)
if addenda14.RDFIBranchCountryCode != "" {
t.Error("Parsed with an invalid RuneCountInString not equal to 94")
}
}