-
Notifications
You must be signed in to change notification settings - Fork 152
/
addenda18_test.go
390 lines (345 loc) · 13.7 KB
/
addenda18_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
// 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"
)
// mockAddenda18 creates a mock Addenda18 record
func mockAddenda18() *Addenda18 {
addenda18 := NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of Germany"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "987987987654654"
addenda18.ForeignCorrespondentBankBranchCountryCode = "DE"
addenda18.SequenceNumber = 1
addenda18.EntryDetailSequenceNumber = 0000001
return addenda18
}
func mockAddenda18B() *Addenda18 {
addenda18 := NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of Spain"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "987987987123123"
addenda18.ForeignCorrespondentBankBranchCountryCode = "ES"
addenda18.SequenceNumber = 2
addenda18.EntryDetailSequenceNumber = 0000001
return addenda18
}
func mockAddenda18C() *Addenda18 {
addenda18 := NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of France"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "456456456987987"
addenda18.ForeignCorrespondentBankBranchCountryCode = "FR"
addenda18.SequenceNumber = 3
addenda18.EntryDetailSequenceNumber = 0000001
return addenda18
}
func mockAddenda18D() *Addenda18 {
addenda18 := NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of Turkey"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "12312345678910"
addenda18.ForeignCorrespondentBankBranchCountryCode = "TR"
addenda18.SequenceNumber = 4
addenda18.EntryDetailSequenceNumber = 0000001
return addenda18
}
func mockAddenda18E() *Addenda18 {
addenda18 := NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of United Kingdom"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "1234567890123456789012345678901234"
addenda18.ForeignCorrespondentBankBranchCountryCode = "GB"
addenda18.SequenceNumber = 5
addenda18.EntryDetailSequenceNumber = 0000001
return addenda18
}
func mockAddenda18F() *Addenda18 {
addenda18 := NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of Antarctica"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "123456789012345678901"
addenda18.ForeignCorrespondentBankBranchCountryCode = "AQ"
addenda18.SequenceNumber = 6
addenda18.EntryDetailSequenceNumber = 0000001
return addenda18
}
// TestMockAddenda18 validates mockAddenda18
func TestMockAddenda18(t *testing.T) {
addenda18 := mockAddenda18()
if err := addenda18.Validate(); err != nil {
t.Error("mockAddenda18 does not validate and will break other tests")
}
if addenda18.ForeignCorrespondentBankName != "Bank of Germany" {
t.Error("ForeignCorrespondentBankName dependent default value has changed")
}
if addenda18.ForeignCorrespondentBankIDNumberQualifier != "01" {
t.Error("ForeignCorrespondentBankIDNumberQualifier dependent default value has changed")
}
if addenda18.ForeignCorrespondentBankIDNumber != "987987987654654" {
t.Error("ForeignCorrespondentBankIDNumber dependent default value has changed")
}
if addenda18.ForeignCorrespondentBankBranchCountryCode != "DE" {
t.Error("ForeignCorrespondentBankBranchCountryCode dependent default value has changed")
}
if addenda18.EntryDetailSequenceNumber != 0000001 {
t.Error("EntryDetailSequenceNumber dependent default value has changed")
}
}
// testAddenda18Parse parses Addenda18 record
func testAddenda18Parse(t testing.TB) {
Addenda18 := NewAddenda18()
line := "718Bank of Germany 01987987987654654 DE 00010000001"
Addenda18.Parse(line)
// walk the Addenda18 struct
if Addenda18.TypeCode != "18" {
t.Errorf("expected %v got %v", "18", Addenda18.TypeCode)
}
if Addenda18.ForeignCorrespondentBankName != "Bank of Germany" {
t.Errorf("expected %v got %v", "Bank of Germany", Addenda18.ForeignCorrespondentBankName)
}
if Addenda18.ForeignCorrespondentBankIDNumberQualifier != "01" {
t.Errorf("expected: %v got: %v", "01", Addenda18.ForeignCorrespondentBankIDNumberQualifier)
}
if Addenda18.ForeignCorrespondentBankIDNumber != "987987987654654" {
t.Errorf("expected: %v got: %v", "987987987654654", Addenda18.ForeignCorrespondentBankIDNumber)
}
if Addenda18.ForeignCorrespondentBankBranchCountryCode != "DE" {
t.Errorf("expected: %s got: %s", "DE", Addenda18.ForeignCorrespondentBankBranchCountryCode)
}
if Addenda18.EntryDetailSequenceNumber != 0000001 {
t.Errorf("expected: %v got: %v", 0000001, Addenda18.EntryDetailSequenceNumber)
}
}
// TestAddenda18Parse tests parsing Addenda18 record
func TestAddenda18Parse(t *testing.T) {
testAddenda18Parse(t)
}
// BenchmarkAddenda18Parse benchmarks parsing Addenda18 record
func BenchmarkAddenda18Parse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18Parse(b)
}
}
// testAddenda18String validates that a known parsed file can be return to a string of the same value
func testAddenda18String(t testing.TB) {
addenda18 := NewAddenda18()
var line = "718Bank of United Kingdom 011234567890123456789012345678901234GB 00010000001"
addenda18.Parse(line)
if addenda18.String() != line {
t.Errorf("Strings do not match")
}
}
// TestAddenda18 String tests validating that a known parsed file can be return to a string of the same value
func TestAddenda18String(t *testing.T) {
testAddenda18String(t)
}
// BenchmarkAddenda18 String benchmarks validating that a known parsed file can be return to a string of the same value
func BenchmarkAddenda18String(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18String(b)
}
}
func TestAddenda18FieldInclusionTypeCode(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.TypeCode = ""
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda18FieldInclusion(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.EntryDetailSequenceNumber = 0
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda18FieldInclusionSequenceNumber(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.SequenceNumber = 0
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda18FieldInclusionFCBankName(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankName = ""
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda18FieldInclusionFCBankIDNumberQualifier(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankIDNumberQualifier = ""
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda18FieldInclusionFCBankIDNumber(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankIDNumber = ""
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
func TestAddenda18FieldInclusionFCBankBranchCountryCode(t *testing.T) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankBranchCountryCode = ""
err := addenda18.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// testAddenda18ForeignCorrespondentBankNameAlphaNumeric validates ForeignCorrespondentBankName is alphanumeric
func testAddenda18ForeignCorrespondentBankNameAlphaNumeric(t testing.TB) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankName = "®©"
err := addenda18.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda18ForeignCorrespondentBankNameAlphaNumeric tests validating ForeignCorrespondentBankName is alphanumeric
func TestAddenda18ForeignCorrespondentBankNameAlphaNumeric(t *testing.T) {
testAddenda18ForeignCorrespondentBankNameAlphaNumeric(t)
}
// BenchmarkAddenda18ForeignCorrespondentBankNameAlphaNumeric benchmarks ForeignCorrespondentBankName is alphanumeric
func BenchmarkAddenda18ForeignCorrespondentBankNameAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18ForeignCorrespondentBankNameAlphaNumeric(b)
}
}
// testAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric validates ForeignCorrespondentBankIDNumberQualifier is alphanumeric
func testAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric(t testing.TB) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankIDNumberQualifier = "®©"
err := addenda18.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric tests validating ForeignCorrespondentBankIDNumberQualifier is alphanumeric
func TestAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric(t *testing.T) {
testAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric(t)
}
// BenchmarkAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric benchmarks ForeignCorrespondentBankIDNumberQualifier is alphanumeric
func BenchmarkAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18ForeignCorrespondentBankIDQualifierAlphaNumeric(b)
}
}
// testAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric validates ForeignCorrespondentBankBranchCountryCode is alphanumeric
func testAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric(t testing.TB) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankBranchCountryCode = "®©"
err := addenda18.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda18ForeignCorrespondentBankBranchCountryCodeNumeric tests validating ForeignCorrespondentBankBranchCountryCode is alphanumeric
func TestAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric(t *testing.T) {
testAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric(t)
}
// BenchmarkAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric benchmarks ForeignCorrespondentBankBranchCountryCode is alphanumeric
func BenchmarkAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18ForeignCorrespondentBankBranchCountryCodeAlphaNumeric(b)
}
}
// testAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric validates ForeignCorrespondentBankIDNumber is alphanumeric
func testAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric(t testing.TB) {
addenda18 := mockAddenda18()
addenda18.ForeignCorrespondentBankIDNumber = "®©"
err := addenda18.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric tests validating ForeignCorrespondentBankIDNumber is alphanumeric
func TestAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric(t *testing.T) {
testAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric(t)
}
// BenchmarkAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric benchmarks ForeignCorrespondentBankIDNumber is alphanumeric
func BenchmarkAddendaForeignCorrespondentBankIDNumberAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18ForeignCorrespondentBankIDNumberAlphaNumeric(b)
}
}
// testAddenda18ValidTypeCode validates Addenda18 TypeCode
func testAddenda18ValidTypeCode(t testing.TB) {
addenda18 := mockAddenda18()
addenda18.TypeCode = "65"
err := addenda18.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda18ValidTypeCode tests validating Addenda18 TypeCode
func TestAddenda18ValidTypeCode(t *testing.T) {
testAddenda18ValidTypeCode(t)
}
// BenchmarkAddenda18ValidTypeCode benchmarks validating Addenda18 TypeCode
func BenchmarkAddenda18ValidTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18ValidTypeCode(b)
}
}
// testAddenda18TypeCode18 TypeCode is 18 if TypeCode is a valid TypeCode
func testAddenda18TypeCode18(t testing.TB) {
addenda18 := mockAddenda18()
addenda18.TypeCode = "05"
err := addenda18.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda18TypeCode18 tests TypeCode is 18 if TypeCode is a valid TypeCode
func TestAddenda18TypeCode18(t *testing.T) {
testAddenda18TypeCode18(t)
}
// BenchmarkAddenda18TypeCode18 benchmarks TypeCode is 18 if TypeCode is a valid TypeCode
func BenchmarkAddenda18TypeCode18(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda18TypeCode18(b)
}
}
// TestAddenda18RuneCountInString validates RuneCountInString
func TestAddenda18RuneCountInString(t *testing.T) {
addenda18 := NewAddenda18()
var line = "718Bank of United Kingdom "
addenda18.Parse(line)
if addenda18.ForeignCorrespondentBankBranchCountryCode != "" {
t.Error("Parsed with an invalid RuneCountInString not equal to 94")
}
}