-
Notifications
You must be signed in to change notification settings - Fork 153
/
batchCTX_test.go
596 lines (521 loc) · 18.1 KB
/
batchCTX_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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
// 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 (
"encoding/json"
"testing"
"github.com/moov-io/base"
"github.com/stretchr/testify/require"
)
// mockBatchCTXHeader creates a BatchCTX BatchHeader
func mockBatchCTXHeader() *BatchHeader {
bh := NewBatchHeader()
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = CTX
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "ACH CTX"
bh.ODFIIdentification = "12104288"
return bh
}
// mockCTXEntryDetail creates a BatchCTX EntryDetail
func mockCTXEntryDetail() *EntryDetail {
entry := NewEntryDetail()
entry.TransactionCode = CheckingCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchCTXHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
return entry
}
// mockBatchCTX creates a BatchCTX
func mockBatchCTX(t testing.TB) *BatchCTX {
t.Helper()
mockBatch := NewBatchCTX(mockBatchCTXHeader())
mockBatch.AddEntry(mockCTXEntryDetail())
mockBatch.GetEntries()[0].AddAddenda05(mockAddenda05())
mockBatch.Entries[0].AddendaRecordIndicator = 1
if err := mockBatch.Create(); err != nil {
t.Fatal(err)
}
return mockBatch
}
// testBatchCTXHeader creates a BatchCTX BatchHeader
func testBatchCTXHeader(t testing.TB) {
batch, _ := NewBatch(mockBatchCTXHeader())
err, ok := batch.(*BatchCTX)
if !ok {
t.Errorf("Expecting BatchCTX got %T", err)
}
}
// TestBatchCTXHeader tests validating BatchCTX BatchHeader
func TestBatchCTXHeader(t *testing.T) {
testBatchCTXHeader(t)
}
// BenchmarkBatchCTXHeader benchmarks validating BatchCTX BatchHeader
func BenchmarkBatchCTXHeader(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXHeader(b)
}
}
// testBatchCTXCreate validates BatchCTX create
func testBatchCTXCreate(t testing.TB) {
mockBatch := mockBatchCTX(t)
if err := mockBatch.Validate(); err != nil {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXCreate tests validating BatchCTX create
func TestBatchCTXCreate(t *testing.T) {
testBatchCTXCreate(t)
}
// BenchmarkBatchCTXCreate benchmarks validating BatchCTX create
func BenchmarkBatchCTXCreate(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXCreate(b)
}
}
// testBatchCTXStandardEntryClassCode validates BatchCTX create for an invalid StandardEntryClassCode
func testBatchCTXStandardEntryClassCode(t testing.TB) {
mockBatch := mockBatchCTX(t)
mockBatch.Header.StandardEntryClassCode = WEB
err := mockBatch.Create()
if !base.Match(err, ErrBatchSECType) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXStandardEntryClassCode tests validating BatchCTX create for an invalid StandardEntryClassCode
func TestBatchCTXStandardEntryClassCode(t *testing.T) {
testBatchCTXStandardEntryClassCode(t)
}
// BenchmarkBatchCTXStandardEntryClassCode benchmarks validating BatchCTX create for an invalid StandardEntryClassCode
func BenchmarkBatchCTXStandardEntryClassCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXStandardEntryClassCode(b)
}
}
// testBatchCTXServiceClassCodeEquality validates service class code equality
func testBatchCTXServiceClassCodeEquality(t testing.TB) {
mockBatch := mockBatchCTX(t)
mockBatch.GetControl().ServiceClassCode = MixedDebitsAndCredits
err := mockBatch.Validate()
if !base.Match(err, NewErrBatchHeaderControlEquality(220, MixedDebitsAndCredits)) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXServiceClassCodeEquality tests validating service class code equality
func TestBatchCTXServiceClassCodeEquality(t *testing.T) {
testBatchCTXServiceClassCodeEquality(t)
}
// BenchmarkBatchCTXServiceClassCodeEquality benchmarks validating service class code equality
func BenchmarkBatchCTXServiceClassCodeEquality(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXServiceClassCodeEquality(b)
}
}
// testBatchCTXAddendaCount validates BatchCTX Addendum count of 2
func testBatchCTXAddendaCount(t testing.TB) {
mockBatch := mockBatchCTX(t)
mockBatch.GetEntries()[0].AddAddenda05(mockAddenda05())
err := mockBatch.Create()
if !base.Match(err, NewErrBatchExpectedAddendaCount(0, 1)) {
t.Errorf("%T: %s", err, err)
}
mockBatch.SetValidation(&ValidateOpts{
UnequalAddendaCounts: true,
})
require.NoError(t, mockBatch.Create())
}
// TestBatchCTXAddendaCount tests validating BatchCTX Addendum count of 2
func TestBatchCTXAddendaCount(t *testing.T) {
testBatchCTXAddendaCount(t)
}
// BenchmarkBatchCTXAddendaCount benchmarks validating BatchCTX Addendum count of 2
func BenchmarkBatchCTXAddendaCount(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXAddendaCount(b)
}
}
// testBatchCTXAddendaCountZero validates Addendum count of 0
func testBatchCTXAddendaCountZero(t testing.TB) {
mockBatch := NewBatchCTX(mockBatchCTXHeader())
mockBatch.AddEntry(mockCTXEntryDetail())
err := mockBatch.Create()
if !base.Match(err, NewErrBatchExpectedAddendaCount(0, 1)) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXAddendaCountZero tests validating Addendum count of 0
func TestBatchCTXAddendaCountZero(t *testing.T) {
testBatchCTXAddendaCountZero(t)
}
// BenchmarkBatchCTXAddendaCountZero benchmarks validating Addendum count of 0
func BenchmarkBatchCTXAddendaCountZero(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXAddendaCountZero(b)
}
}
// testBatchCTXInvalidAddenda validates Addendum must be Addenda05 with type code 05
func testBatchCTXInvalidAddenda(t testing.TB) {
mockBatch := NewBatchCTX(mockBatchCTXHeader())
mockBatch.AddEntry(mockCTXEntryDetail())
addenda05 := mockAddenda05()
addenda05.TypeCode = "63"
mockBatch.GetEntries()[0].AddAddenda05(addenda05)
mockBatch.Entries[0].AddendaRecordIndicator = 1
err := mockBatch.Create()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXInvalidAddenda tests validating Addendum must be Addenda05 with record type 7
func TestBatchCTXInvalidAddenda(t *testing.T) {
testBatchCTXInvalidAddenda(t)
}
// BenchmarkBatchCTXInvalidAddenda benchmarks validating Addendum must be Addenda05 with record type 7
func BenchmarkBatchCTXInvalidAddenda(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXInvalidAddenda(b)
}
}
// testBatchCTXInvalidBuild validates an invalid batch build
func testBatchCTXInvalidBuild(t testing.TB) {
mockBatch := mockBatchCTX(t)
mockBatch.GetHeader().ServiceClassCode = 3
err := mockBatch.Create()
if !base.Match(err, ErrServiceClass) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXInvalidBuild tests validating an invalid batch build
func TestBatchCTXInvalidBuild(t *testing.T) {
testBatchCTXInvalidBuild(t)
}
// BenchmarkBatchCTXInvalidBuild benchmarks validating an invalid batch build
func BenchmarkBatchCTXInvalidBuild(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXInvalidBuild(b)
}
}
// testBatchCTXAddenda10000 validates error for 10000 Addenda
func testBatchCTXAddenda10000(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = CTX
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "ACH CTX"
bh.ODFIIdentification = "12104288"
entry := NewEntryDetail()
entry.TransactionCode = CheckingCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(9999)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchCTXHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
mockBatch := NewBatchCTX(bh)
mockBatch.AddEntry(entry)
for i := 0; i < 10000; i++ {
mockBatch.GetEntries()[0].AddAddenda05(mockAddenda05())
}
mockBatch.Entries[0].AddendaRecordIndicator = 1
err := mockBatch.Create()
if !base.Match(err, NewErrBatchAddendaCount(10000, 9999)) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXAddenda10000 tests validating error for 10000 Addenda
func TestBatchCTXAddenda10000(t *testing.T) {
testBatchCTXAddenda10000(t)
}
// BenchmarkBatchCTXAddenda10000 benchmarks validating error for 10000 Addenda
func BenchmarkBatchCTXAddenda10000(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXAddenda10000(b)
}
}
// testBatchCTXAddendaRecords validates error for AddendaRecords not equal to addendum
func testBatchCTXAddendaRecords(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = CTX
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "ACH CTX"
bh.ODFIIdentification = "12104288"
entry := NewEntryDetail()
entry.TransactionCode = CheckingCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(500)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchCTXHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
mockBatch := NewBatchCTX(bh)
mockBatch.AddEntry(entry)
for i := 0; i < 565; i++ {
mockBatch.GetEntries()[0].AddAddenda05(mockAddenda05())
}
mockBatch.Entries[0].AddendaRecordIndicator = 1
err := mockBatch.Create()
if !base.Match(err, NewErrBatchExpectedAddendaCount(0, 1)) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXAddendaRecords tests validating error for AddendaRecords not equal to addendum
func TestBatchCTXAddendaRecords(t *testing.T) {
testBatchCTXAddendaRecords(t)
}
// BenchmarkBatchAddendaRecords benchmarks validating error for AddendaRecords not equal to addendum
func BenchmarkBatchCTXAddendaRecords(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXAddendaRecords(b)
}
}
// testBatchCTXReceivingCompany validates CTXReceivingCompany
func testBatchCTXReceivingCompany(t testing.TB) {
mockBatch := mockBatchCTX(t)
mockBatch.GetEntries()[0].SetCATXReceivingCompany("Receiver Company")
require.Equal(t, "Receiver Company ", mockBatch.GetEntries()[0].CATXReceivingCompanyField())
}
// TestBatchCTXReceivingCompany tests validating CTXReceivingCompany
func TestBatchCTXReceivingCompany(t *testing.T) {
testBatchCTXReceivingCompany(t)
}
// BenchmarkBatchCTXReceivingCompany benchmarks validating CTXReceivingCompany
func BenchmarkBatchCTXReceivingCompany(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXReceivingCompany(b)
}
}
// testBatchCTXReserved validates CTXReservedField
func testBatchCTXReserved(t testing.TB) {
mockBatch := mockBatchCTX(t)
if mockBatch.GetEntries()[0].CATXReservedField() != " " {
t.Errorf("expected %v got %v", " ", mockBatch.GetEntries()[0].CATXReservedField())
}
}
// TestBatchCTXReserved tests validating CTXReservedField
func TestBatchCTXReserved(t *testing.T) {
testBatchCTXReserved(t)
}
// BenchmarkBatchCTXReserved benchmarks validating CTXReservedField
func BenchmarkBatchCTXReserved(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXReserved(b)
}
}
// testBatchCTXZeroAddendaRecords validates zero addenda records
func testBatchCTXZeroAddendaRecords(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = CTX
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "ACH CTX"
bh.ODFIIdentification = "12104288"
entry := NewEntryDetail()
entry.TransactionCode = CheckingCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchCTXHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
mockBatch := NewBatchCTX(bh)
mockBatch.AddEntry(entry)
err := mockBatch.Create()
if !base.Match(err, NewErrBatchExpectedAddendaCount(0, 1)) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXZeroAddendaRecords tests validating zero addenda records
func TestBatchCTXZeroAddendaRecords(t *testing.T) {
testBatchCTXZeroAddendaRecords(t)
}
// BenchmarkBatchZeroAddendaRecords benchmarks validating zero addenda records
func BenchmarkBatchCTXZeroAddendaRecords(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXZeroAddendaRecords(b)
}
}
// testBatchCTXPrenoteAddendaRecords validates prenote addenda records
func testBatchCTXPrenoteAddendaRecords(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = CTX
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "ACH CTX"
bh.ODFIIdentification = "12104288"
bh.OriginatorStatusCode = 2
entry := NewEntryDetail()
entry.TransactionCode = CheckingPrenoteCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchCTXHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
mockBatch := NewBatchCTX(bh)
mockBatch.AddEntry(entry)
mockBatch.GetEntries()[0].AddAddenda05(mockAddenda05())
mockBatch.Entries[0].AddendaRecordIndicator = 1
err := mockBatch.Create()
if err != nil {
t.Errorf("%T: %v", err, err)
}
}
// TestBatchCTXPrenoteAddendaRecords tests validating prenote addenda records
func TestBatchCTXPrenoteAddendaRecords(t *testing.T) {
testBatchCTXPrenoteAddendaRecords(t)
}
// testBatchCTXPrenoteAddendaRecordsErr validates prenote addenda records
func testBatchCTXPrenoteAddendaRecordsErr(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = CTX
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "ACH CTX"
bh.ODFIIdentification = "12104288"
bh.OriginatorStatusCode = 2
entry := NewEntryDetail()
entry.TransactionCode = CheckingPrenoteCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchCTXHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
mockBatch := NewBatchCTX(bh)
mockBatch.AddEntry(entry)
mockBatch.GetEntries()[0].AddAddenda05(mockAddenda05())
mockBatch.Entries[0].AddendaRecordIndicator = 1
err := mockBatch.Create()
if !base.Match(err, ErrBatchTransactionCode) {
t.Errorf("%T %s", err, err)
}
}
// TestBatchCTXPrenoteAddendaRecordsErr tests validating prenote addenda records
func TestBatchCTXPrenoteAddendaRecordsErr(t *testing.T) {
testBatchCTXPrenoteAddendaRecordsErr(t)
}
// BenchmarkBatchPrenoteAddendaRecords benchmarks validating prenote addenda records
func BenchmarkBatchCTXPrenoteAddendaRecords(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchCTXPrenoteAddendaRecords(b)
}
}
// TestBatchCTXAddendum98 validates Addenda98 returns an error
func TestBatchCTXAddendum98(t *testing.T) {
mockBatch := NewBatchCTX(mockBatchCTXHeader())
mockBatch.AddEntry(mockCTXEntryDetail())
mockAddenda98 := mockAddenda98()
mockAddenda98.TypeCode = "05"
mockBatch.GetEntries()[0].Category = CategoryNOC
mockBatch.GetEntries()[0].Addenda98 = mockAddenda98
err := mockBatch.Create()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXAddendum99 validates Addenda99 returns an error
func TestBatchCTXAddendum99(t *testing.T) {
mockBatch := NewBatchCTX(mockBatchCTXHeader())
mockBatch.AddEntry(mockCTXEntryDetail())
mockAddenda99 := mockAddenda99()
mockAddenda99.TypeCode = "05"
mockBatch.GetEntries()[0].Category = CategoryReturn
mockBatch.GetEntries()[0].Addenda99 = mockAddenda99
err := mockBatch.Create()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXValidTranCodeForServiceClassCode validates a transactionCode based on ServiceClassCode
func TestBatchCTXValidTranCodeForServiceClassCode(t *testing.T) {
mockBatch := mockBatchCTX(t)
mockBatch.GetHeader().ServiceClassCode = DebitsOnly
err := mockBatch.Create()
if !base.Match(err, NewErrBatchServiceClassTranCode(DebitsOnly, 22)) {
t.Errorf("%T: %s", err, err)
}
}
// TestBatchCTXAddenda02 validates BatchCTX cannot have Addenda02
func TestBatchCTXAddenda02(t *testing.T) {
mockBatch := mockBatchCTX(t)
mockBatch.Entries[0].AddendaRecordIndicator = 1
mockBatch.GetEntries()[0].Addenda02 = mockAddenda02()
err := mockBatch.Create()
if !base.Match(err, ErrBatchAddendaCategory) {
t.Errorf("%T: %s", err, err)
}
}
func TestBatchCTX_JSON_RoundTrip(t *testing.T) {
mockBatch := mockBatchCTX(t)
file := NewFile()
file.Header = staticFileHeader()
file.AddBatch(mockBatch)
bs, err := json.Marshal(file)
require.NoError(t, err)
read, err := FileFromJSON(bs)
require.NoError(t, err)
// Check both files against each other
require.Equal(t, len(file.Batches), len(read.Batches))
for i := range file.Batches {
ied := file.Batches[i].GetEntries()
red := read.Batches[i].GetEntries()
require.NotEmpty(t, ied)
require.ElementsMatch(t, ied, red, "batch[%d]", i)
}
}