Skip to content

Commit 21ae6ba

Browse files
authored
Merge pull request #1736 from moov-io/fix-issue1735
test/issues: add code from Issue 1735
2 parents f63053c + afca88f commit 21ae6ba

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

batch.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,15 @@ func (batch *Batch) SetValidation(opts *ValidateOpts) {
307307
if batch == nil {
308308
return
309309
}
310+
310311
batch.validateOpts = opts
312+
313+
if batch.Header != nil {
314+
batch.Header.SetValidation(opts)
315+
}
316+
if batch.Control != nil {
317+
batch.Control.SetValidation(opts)
318+
}
311319
}
312320

313321
// verify checks basic valid NACHA batch rules. Assumes properly parsed records. This does not mean it is a valid batch as validity is tied to each batch type

test/issues/issue1735_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package issues
2+
3+
import (
4+
"testing"
5+
6+
"github.com/moov-io/ach"
7+
)
8+
9+
func TestIssue1735_ValidateOptsNotPropagated(t *testing.T) {
10+
// Test that ValidateOpts are propagated when creating a file from JSON.
11+
jsonData := []byte(`{
12+
"fileHeader": {
13+
"immediateOrigin": "022083649",
14+
"immediateDestination": "011000015",
15+
"fileCreationDate": "260120",
16+
"fileCreationTime": "1030",
17+
"fileIDModifier": "A"
18+
},
19+
"batches": [{
20+
"batchHeader": {
21+
"serviceClassCode": 220,
22+
"companyName": "Test Company ©",
23+
"companyIdentification": "54321",
24+
"standardEntryClassCode": "WEB",
25+
"companyEntryDescription": "Payment",
26+
"effectiveEntryDate": "260127",
27+
"originatorStatusCode": 1,
28+
"ODFIIdentification": "123456780",
29+
"batchNumber": 1
30+
},
31+
"entryDetails": [{
32+
"transactionCode": 21,
33+
"RDFIIdentification": "98765432",
34+
"checkDigit": "0",
35+
"DFIAccountNumber": "665544",
36+
"amount": 111111,
37+
"identificationNumber": "Test",
38+
"individualName": "John Doe",
39+
"traceNumber": "12345678123456"
40+
}]
41+
}]
42+
}`)
43+
44+
// Create ValidateOpts with AllowSpecialCharacters
45+
validateOpts := &ach.ValidateOpts{
46+
AllowSpecialCharacters: true,
47+
}
48+
49+
// This should succeed but fails
50+
_, err := ach.FileFromJSONWith(jsonData, validateOpts)
51+
if err != nil {
52+
t.Fatalf("Expected success, got error: %v", err)
53+
}
54+
}

0 commit comments

Comments
 (0)