Skip to content

Commit

Permalink
Merge pull request #1377 from ckbaum/ckbaum/fix-iat-entry-categories
Browse files Browse the repository at this point in the history
Correctly assign Category to IAT entries
  • Loading branch information
adamdecaf authored Feb 26, 2024
2 parents 35fe682 + 2238eac commit 3530815
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
2 changes: 2 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ func (r *Reader) nocIATAddenda(entryIndex int) error {
return err
}
r.IATCurrentBatch.Entries[entryIndex].Addenda98 = addenda98
r.IATCurrentBatch.Entries[entryIndex].Category = CategoryNOC
return nil
}

Expand All @@ -830,6 +831,7 @@ func (r *Reader) returnIATAddenda(entryIndex int) error {
return err
}
r.IATCurrentBatch.Entries[entryIndex].Addenda99 = addenda99
r.IATCurrentBatch.Entries[entryIndex].Category = CategoryReturn
return nil
}

Expand Down
70 changes: 68 additions & 2 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,41 @@ func TestACHFileIATAddenda18(t *testing.T) {
}
}

// TestACHFileIATAddenda98 validates error when reading an invalid IATAddenda98
// TestACHFileIATAddenda98 validates error when reading a valid IAT Addenda98
func TestACHFileIATAddenda98(t *testing.T) {
f, err := os.Open(filepath.Join("test", "testdata", "iat-addenda98.ach"))
if err != nil {
t.Errorf("%T: %s", err, err)
}
defer f.Close()
r := NewReader(f)
file, err := r.Read()

if err != nil {
t.Errorf("%T: %s", err, err)
}

if len(file.IATBatches) != 1 || len(file.IATBatches[0].Entries) != 1 {
t.Error("This file should contain a single IAT batch with a single entry")
}

entry := file.IATBatches[0].Entries[0]

if entry.Addenda98 == nil {
t.Error("This entry should have an Addenda 98")
}

if entry.Category != CategoryNOC {
t.Errorf(
"This entry has an Addenda98, so its category should be `%s`, but it's `%s`",
CategoryNOC,
entry.Category,
)
}
}

// TestACHFileIATInvalidAddenda98 validates error when reading an invalid IATAddenda98
func TestACHFileIATInvalidAddenda98(t *testing.T) {
f, err := os.Open(filepath.Join("test", "testdata", "iat-invalidAddenda98.ach"))
if err != nil {
t.Errorf("%T: %s", err, err)
Expand All @@ -1496,8 +1529,41 @@ func TestACHFileIATAddenda98(t *testing.T) {
}
}

// TestACHFileIATAddenda99 validates error when reading an invalid IATAddenda99
// TestACHFileIATAddenda99 validates error when reading a valid IAT Addenda99
func TestACHFileIATAddenda99(t *testing.T) {
f, err := os.Open(filepath.Join("test", "testdata", "iat-addenda99.ach"))
if err != nil {
t.Errorf("%T: %s", err, err)
}
defer f.Close()
r := NewReader(f)
file, err := r.Read()

if err != nil {
t.Errorf("%T: %s", err, err)
}

if len(file.IATBatches) != 1 || len(file.IATBatches[0].Entries) != 1 {
t.Error("This file should contain a single IAT batch with a single entry")
}

entry := file.IATBatches[0].Entries[0]

if entry.Addenda99 == nil {
t.Error("This entry should have an Addenda 99")
}

if entry.Category != CategoryReturn {
t.Errorf(
"This entry has an Addenda99, so its category should be `%s`, but it's `%s`",
CategoryReturn,
entry.Category,
)
}
}

// TestACHFileIATAddenda99 validates error when reading an invalid IATAddenda99
func TestACHFileIATInvalidAddenda99(t *testing.T) {
f, err := os.Open(filepath.Join("test", "testdata", "iat-invalidAddenda99.ach"))
if err != nil {
t.Errorf("%T: %s", err, err)
Expand Down
20 changes: 20 additions & 0 deletions test/testdata/iat-addenda98.ach
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
101 231380104 1210428821901160000A094101Federal Reserve Bank My Bank Name
5220IATCOR FF3 US123456789 CORTRADEPAYMTCADUSD000000 1231380100000001
6211210428820007 0000100000123456789 1231380100000001
710ANN000000000000100000928383-23938 BEK Enterprises 0000001
711BEK Solutions 15 West Place Street 0000001
712JacobsTown*PA\ US*19305\ 0000001
713Wells Fargo 01121042882 US 0000001
714Citadel Bank 01231380104 US 0000001
7159874654932139872121 Front Street 0000001
716LetterTown*AB\ CA*80014\ 0000001
798C01231380100000001 1210428889722-C3 121042880000001
82200000090012104288000000000000000000100000 231380100000001
9000001000002000000090012104288000000000000000000100000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
20 changes: 20 additions & 0 deletions test/testdata/iat-addenda99.ach
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
101 231380104 1210428821901160000A094101Federal Reserve Bank My Bank Name
5220 FF3 US123456789 IATTRADEPAYMTCADUSD000000 1231380100000001
6221210428820007 0000100000123456789 1231380100000001
710ANN000000000000100000928383-23938 BEK Enterprises 0000001
711BEK Solutions 15 West Place Street 0000001
712JacobsTown*PA\ US*19305\ 0000001
713Wells Fargo 01121042882 US 0000001
714Citadel Bank 01231380104 US 0000001
7159874654932139872121 Front Street 0000001
716LetterTown*AB\ CA*80014\ 0000001
799R01231380100000001 121042880000100000Authorization Revoked 000000000000000
82200000090012104288000000000000000000100000 231380100000001
9000001000002000000090012104288000000000000000000100000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

0 comments on commit 3530815

Please sign in to comment.