forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
advBatchControl_test.go
329 lines (288 loc) · 10.2 KB
/
advBatchControl_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
// 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 (
"strings"
"testing"
"github.com/moov-io/base"
)
func mockADVBatchControl() *ADVBatchControl {
bc := NewADVBatchControl()
bc.ServiceClassCode = CreditsOnly
bc.ACHOperatorData = "T-BANK"
bc.ODFIIdentification = "12104288"
return bc
}
// testMockADVBatchControl tests mock batch control
func testMockADVBatchControl(t testing.TB) {
bc := mockADVBatchControl()
if err := bc.Validate(); err != nil {
t.Error("mockADVBatchControl does not validate and will break other tests")
}
if bc.ServiceClassCode != CreditsOnly {
t.Error("ServiceClassCode depedendent default value has changed")
}
if bc.ACHOperatorData != "T-BANK" {
t.Error("ACHOperatorData depedendent default value has changed")
}
if bc.ODFIIdentification != "12104288" {
t.Error("ODFIIdentification depedendent default value has changed")
}
}
// TestMockADVBatchControl test mock batch control
func TestMockADVBatchControl(t *testing.T) {
testMockADVBatchControl(t)
}
// BenchmarkMockADVBatchControl benchmarks mock batch control
func BenchmarkMockADVBatchControl(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testMockADVBatchControl(b)
}
}
// TestParseADVBatchControl parses a known Batch ControlRecord string.
func testParseADVBatchControl(t testing.TB) {
var line = "828000000100053200010000000000000001050000000000000000000000T-BANK 076401250000001"
r := NewReader(strings.NewReader(line))
r.line = line
bh := BatchHeader{BatchNumber: 1,
StandardEntryClassCode: ADV,
ServiceClassCode: AutomatedAccountingAdvices,
CompanyIdentification: "origid",
ODFIIdentification: "12104288"}
r.addCurrentBatch(NewBatchADV(&bh))
r.currentBatch.AddADVEntry(mockADVEntryDetail())
if err := r.parseBatchControl(); err != nil {
t.Errorf("%T: %s", err, err)
}
record := r.currentBatch.GetADVControl()
if record.recordType != "8" {
t.Errorf("RecordType Expected '8' got: %v", record.recordType)
}
if record.ServiceClassCode != AutomatedAccountingAdvices {
t.Errorf("ServiceClassCode Expected '280' got: %v", record.ServiceClassCode)
}
if record.EntryAddendaCountField() != "000001" {
t.Errorf("EntryAddendaCount Expected '000001' got: %v", record.EntryAddendaCountField())
}
if record.EntryHashField() != "0005320001" {
t.Errorf("EntryHash Expected '0005320001' got: %v", record.EntryHashField())
}
if record.TotalDebitEntryDollarAmountField() != "00000000000000010500" {
t.Errorf("TotalDebitEntryDollarAmount Expected '00000000000000010500' got: %v", record.TotalDebitEntryDollarAmountField())
}
if record.TotalCreditEntryDollarAmountField() != "00000000000000000000" {
t.Errorf("TotalCreditEntryDollarAmount Expected '00000000000000000000' got: %v", record.TotalCreditEntryDollarAmountField())
}
if record.ACHOperatorDataField() != "T-BANK " {
t.Errorf("ACHOperatorData Expected 'T-BANK ' got: %v", record.ACHOperatorDataField())
}
if record.ODFIIdentificationField() != "07640125" {
t.Errorf("OdfiIdentification Expected '07640125' got: %v", record.ODFIIdentificationField())
}
if record.BatchNumberField() != "0000001" {
t.Errorf("BatchNumber Expected '0000001' got: %v", record.BatchNumberField())
}
}
// TestParseADVBatchControl tests parsing a known Batch ControlRecord string.
func TestParseADVBatchControl(t *testing.T) {
testParseADVBatchControl(t)
}
// BenchmarkParseADVBatchControl benchmarks parsing a known Batch ControlRecord string.
func BenchmarkParseADVBatchControl(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testParseADVBatchControl(b)
}
}
// testADVBCString validates that a known parsed file can be return to a string of the same value
func testADVBCString(t testing.TB) {
var line = "822500000100053200010000000000000001050000000000000000000000T-BANK 076401250000001"
r := NewReader(strings.NewReader(line))
r.line = line
bh := BatchHeader{BatchNumber: 1,
StandardEntryClassCode: ADV,
ServiceClassCode: AutomatedAccountingAdvices,
CompanyIdentification: "origid",
ODFIIdentification: "12104288"}
r.addCurrentBatch(NewBatchADV(&bh))
r.currentBatch.AddADVEntry(mockADVEntryDetail())
if err := r.parseBatchControl(); err != nil {
t.Errorf("%T: %s", err, err)
}
record := r.currentBatch.GetADVControl()
if record.String() != line {
t.Errorf("Strings do not match")
}
}
// TestADVBCString tests validating that a known parsed file can be return to a string of the same value
func TestADVBCString(t *testing.T) {
testADVBCString(t)
}
// BenchmarkADVBCString benchmarks validating that a known parsed file can be return to a string of the same value
func BenchmarkADVBCString(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBCString(b)
}
}
// testValidateADVBCRecordType ensure error if recordType is not 8
func testValidateADVBCRecordType(t testing.TB) {
bc := mockADVBatchControl()
bc.recordType = "2"
err := bc.Validate()
if !base.Match(err, NewErrRecordType(7)) {
t.Errorf("%T: %s", err, err)
}
}
// TestValidateADVBCRecordType tests ensuring an error if recordType is not 8
func TestValidateADVBCRecordType(t *testing.T) {
testValidateADVBCRecordType(t)
}
// BenchmarkValidateADVBCRecordType benchmarks ensuring an error if recordType is not 8
func BenchmarkValidateADVBCRecordType(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testValidateBCRecordType(b)
}
}
// testADVisServiceClassErr verifies service class code
func testADVBCisServiceClassErr(t testing.TB) {
bc := mockADVBatchControl()
bc.ServiceClassCode = 123
err := bc.Validate()
if !base.Match(err, ErrServiceClass) {
t.Errorf("%T: %s", err, err)
}
}
// TestADVBCisServiceClassErr tests verifying service class code
func TestADVBCisServiceClassErr(t *testing.T) {
testADVBCisServiceClassErr(t)
}
// BenchmarkADVBCisServiceClassErr benchmarks verifying service class code
func BenchmarkADVBCisServiceClassErr(b *testing.B) {
for i := 0; i < b.N; i++ {
testADVBCisServiceClassErr(b)
}
}
// testADVBCBatchNumber verifies batch number
func testADVBCBatchNumber(t testing.TB) {
bc := mockADVBatchControl()
bc.BatchNumber = 0
err := bc.Validate()
// TODO: are we expecting there to be no errors here?
if !base.Match(err, nil) {
t.Errorf("%T: %s", err, err)
}
}
// TestADVBCBatchNumber tests verifying batch number
func TestADVBCBatchNumber(t *testing.T) {
testADVBCBatchNumber(t)
}
// BenchmarkADVBCBatchNumber benchmarks verifying batch number
func BenchmarkADVBCBatchNumber(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBCBatchNumber(b)
}
}
// testADVBCACHOperatorDataAlphaNumeric verifies Company Identification is AlphaNumeric
func testADVBCACHOperatorDataAlphaNumeric(t testing.TB) {
bc := mockADVBatchControl()
bc.ACHOperatorData = "®"
err := bc.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestADVBCACHOperatorDataAlphaNumeric tests verifying Company Identification is AlphaNumeric
func TestADVBCACHOperatorDataAlphaNumeric(t *testing.T) {
testADVBCACHOperatorDataAlphaNumeric(t)
}
// BenchmarkADVACHOperatorDataAlphaNumeric benchmarks verifying Company Identification is AlphaNumeric
func BenchmarkADVACHOperatorDataAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBCACHOperatorDataAlphaNumeric(b)
}
}
// testADVBCFieldInclusionRecordType verifies Record Type is included
func testADVBCFieldInclusionRecordType(t testing.TB) {
bc := mockADVBatchControl()
bc.recordType = ""
err := bc.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestADVBCFieldInclusionRecordType tests verifying Record Type is included
func TestADVBCFieldInclusionRecordType(t *testing.T) {
testADVBCFieldInclusionRecordType(t)
}
// BenchmarkADVBCFieldInclusionRecordType benchmarks verifying Record Type is included
func BenchmarkADVBCFieldInclusionRecordType(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBCFieldInclusionRecordType(b)
}
}
// testADVBCFieldInclusionServiceClassCode verifies Service Class Code is included
func testADVBCFieldInclusionServiceClassCode(t testing.TB) {
bc := mockADVBatchControl()
bc.ServiceClassCode = 0
err := bc.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestADVBCFieldInclusionServiceClassCode tests verifying Service Class Code is included
func TestADVBCFieldInclusionServiceClassCode(t *testing.T) {
testADVBCFieldInclusionServiceClassCode(t)
}
// BenchmarkADVBCFieldInclusionServiceClassCod benchmarks verifying Service Class Code is included
func BenchmarkADVBCFieldInclusionServiceClassCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBCFieldInclusionServiceClassCode(b)
}
}
// testADVBCFieldInclusionODFIIdentification verifies batch control ODFIIdentification
func testADVBCFieldInclusionODFIIdentification(t testing.TB) {
bc := mockADVBatchControl()
bc.ODFIIdentification = "000000000"
err := bc.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestADVBCFieldInclusionODFIIdentification tests verifying batch control ODFIIdentification
func TestADVBCFieldInclusionODFIIdentification(t *testing.T) {
testADVBCFieldInclusionODFIIdentification(t)
}
// BenchmarkADVBCFieldInclusionODFIIdentification benchmarks verifying batch control ODFIIdentification
func BenchmarkADVBCFieldInclusionODFIIdentification(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBCFieldInclusionODFIIdentification(b)
}
}
// testADVBatchControlLength verifies batch control length
func testADVBatchControlLength(t testing.TB) {
bc := NewADVBatchControl()
recordLength := len(bc.String())
if recordLength != 94 {
t.Errorf("Instantiated length of Batch Control string is not 94 but %v", recordLength)
}
}
// TestADVBatchControlLength tests verifying batch control length
func TestADVBatchControlLength(t *testing.T) {
testADVBatchControlLength(t)
}
// BenchmarkADVBatchControlLength benchmarks verifying batch control length
func BenchmarkADVBatchControlLength(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testADVBatchControlLength(b)
}
}