8000 [pull] master from moov-io:master by pull[bot] · Pull Request #107 · wei/ach · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] master from moov-io:master #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions batchACK.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func NewBatchACK(bh *BatchHeader) *BatchACK {
//
// Validate will never modify the batch.
func (batch *BatchACK) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchADV.go < 10000 svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-copy">
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func NewBatchADV(bh *BatchHeader) *BatchADV {
//
// Validate will never modify the batch.
func (batch *BatchADV) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

if batch.Header.StandardEntryClassCode != ADV {
return batch.Error("StandardEntryClassCode", ErrBatchSECType, ADV)
}
Expand Down
4 changes: 4 additions & 0 deletions batchARC.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func NewBatchARC(bh *BatchHeader) *BatchARC {
//
// Validate will never modify the batch.
func (batch *BatchARC) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchATX.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func NewBatchATX(bh *BatchHeader) *BatchATX {
//
// Validate will never modify the batch.
func (batch *BatchATX) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchBOC.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func NewBatchBOC(bh *BatchHeader) *BatchBOC {
//
// Validate will never modify the batch.
func (batch *BatchBOC) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchCCD.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewBatchCCD(bh *BatchHeader) *BatchCCD {

// Validate ensures the batch meets NACHA rules specific to this batch type.
func (batch *BatchCCD) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchCIE.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func NewBatchCIE(bh *BatchHeader) *BatchCIE {
//
// Validate will never modify the batch.
func (batch *BatchCIE) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchCOR.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewBatchCOR(bh *BatchHeader) *BatchCOR {

// Validate ensures the batch meets NACHA rules specific to this batch type.
func (batch *BatchCOR) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchCTX.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func NewBatchCTX(bh *BatchHeader) *BatchCTX {
//
// Validate will never modify the batch.
func (batch *BatchCTX) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchDNE.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func NewBatchDNE(bh *BatchHeader) *BatchDNE {

// Validate ensures the batch meets NACHA rules specific to this batch type.
func (batch *BatchDNE) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

if err := batch.verify(); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions batchENR.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func NewBatchENR(bh *BatchHeader) *BatchENR {

// Validate ensures the batch meets NACHA rules specific to this batch type.
func (batch *BatchENR) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

if err := batch.verify(); err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions batchHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,27 @@ func (bh *BatchHeader) Validate() error {
if err := bh.isAlphanumeric(bh.CompanyName); err != nil {
return fieldError("CompanyName", err, bh.CompanyName)
}
if err := bh.isNonZero(bh.CompanyName); err != nil {
return fieldError("CompanyName", err, bh.CompanyName)
}

if err := bh.isAlphanumeric(bh.CompanyDiscretionaryData); err != nil {
return fieldError("CompanyDiscretionaryData", err, bh.CompanyDiscretionaryData)
}

if err := bh.isAlphanumeric(bh.CompanyIdentification); err != nil {
return fieldError("CompanyIdentification", err, bh.CompanyIdentification)
}
if err := bh.isNonZero(bh.CompanyIdentification); err != nil {
return fieldError("CompanyIdentification", err, bh.CompanyIdentification)
}

if err := bh.isAlphanumeric(bh.CompanyEntryDescription); err != nil {
return fieldError("CompanyEntryDescription", err, bh.CompanyEntryDescription)
}
if err := bh.isNonZero(bh.CompanyEntryDescription); err != nil {
return fieldError("CompanyEntryDescription", err, bh.CompanyEntryDescription)
}
}
return nil
}
Expand Down
21 changes: 21 additions & 0 deletions batchHeader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,27 @@ func BenchmarkBatchHeaderFieldInclusion(b *testing.B) {
}
}

func TestBatchHeader_CompanyIdentificationZeros(t *testing.T) {
bh := mockBatchHeader()
bh.CompanyIdentification = strings.Repeat("0", 10)
err := bh.Validate()
require.ErrorContains(t, err, "CompanyIdentification 0000000000 contains only spaces and zeros")
}

func TestBatchHeader_CompanyNameZeros(t *testing.T) {
bh := mockBatchHeader()
bh.CompanyName = "000 000"
err := bh.Validate()
require.ErrorContains(t, err, "CompanyName 000 000 contains only spaces and zeros")
}

func TestBatchHeader_CompanyEntryDescriptionZeros(t *testing.T) {
bh := mockBatchHeader()
bh.CompanyEntryDescription = " 000 "
err := bh.Validate()
require.ErrorContains(t, err, "CompanyEntryDescription 000 contains only spaces and zeros")
}

// testBatchHeaderCompanyNameAlphaNumeric validates batch header company name is alphanumeric
func testBatchHeaderCompanyNameAlphaNumeric(t testing.TB) {
bh := mockBatchHeader()
Expand Down
4 changes: 4 additions & 0 deletions batchMTE.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func NewBatchMTE(bh *BatchHeader) *BatchMTE {
//
// Validate will never modify the batch.
func (batch *BatchMTE) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchPOP.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func NewBatchPOP(bh *BatchHeader) *BatchPOP {
//
// Validate will never modify the batch.
func (batch *BatchPOP) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchPOS.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func NewBatchPOS(bh *BatchHeader) *BatchPOS {
//
// Validate will never modify the batch.
func (batch *BatchPOS) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchPPD.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func NewBatchPPD(bh *BatchHeader) *BatchPPD {
//
// Validate will never modify the batch.
func (batch *BatchPPD) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchRCK.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func NewBatchRCK(bh *BatchHeader) *BatchRCK {
//
// Validate will never modify the batch.
func (batch *BatchRCK) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchSHR.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func NewBatchSHR(bh *BatchHeader) *BatchSHR {
//
// Validate will never modify the batch.
func (batch *BatchSHR) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchTEL.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func NewBatchTEL(bh *BatchHeader) *BatchTEL {

// Validate ensures the batch meets NACHA rules specific to the SEC type TEL
func (batch *BatchTEL) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchTRC.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func NewBatchTRC(bh *BatchHeader) *BatchTRC {
//
// Validate will never modify the batch.
func (batch *BatchTRC) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchTRX.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func NewBatchTRX(bh *BatchHeader) *BatchTRX {
//
// Validate will never modify the batch.
func (batch *BatchTRX) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchWeb.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewBatchWEB(bh *BatchHeader) *BatchWEB {

// Validate ensures the batch meets NACHA rules specific to this batch type.
func (batch *BatchWEB) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions batchXCK.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func NewBatchXCK(bh *BatchHeader) *BatchXCK {
//
// Validate will never modify the batch.
func (batch *BatchXCK) Validate() error {
if batch.validateOpts != nil && batch.validateOpts.SkipAll {
return nil
}

// basic verification of the batch before we validate specific rules.
if err := batch.verify(); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions fileErrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
ErrFileHeader = errors.New("none or more than one file headers exists")
// ErrFileControl is the error given if there is the wrong number of file control records
ErrFileControl = errors.New("none or more than one file control exists")
// ErrMisplacedFileHeader is the error given when a file header is the non-first record
ErrMisplacedFileHeader = errors.New("file header is not the first record")
// ErrFileEntryOutsideBatch is the error given if an entry is outside of a batch
ErrFileEntryOutsideBatch = errors.New("entry outside of batch")
// ErrFileAddendaOutsideBatch is the error given if an addenda is outside of a batch
Expand Down
4 changes: 4 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ func (r *Reader) parseEDAddenda() error {

// parseFileHeader takes the input record string and parses the FileHeaderRecord values
func (r *Reader) parseFileHeader() error {
if r.currentBatch != nil || len(r.File.Batches) > 0 || len(r.File.IATBatches) > 0 {
return r.parseError(ErrMisplacedFileHeader)
}

r.recordName = "FileHeader"
// Pass through any ValidateOpts from the Reader for this comparison
// as we need to compare the other struct fields (e.g. origin, destination)
Expand Down
2 changes: 1 addition & 1 deletion reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ func TestReadFile_SkipValidation(t *testing.T) {
t.Errorf("got: %v, want: %v (batched length)", len(f.Batches), 3)
} else {
for _, batch := range f.Batches {
require.Error(t, batch.Validate())
require.NoError(t, batch.Validate())
}
}

Expand Down
Loading
Loading
0