Skip to content

Commit

Permalink
Merge pull request #1542 from moov-io/set-batch-validate-opts-merge
Browse files Browse the repository at this point in the history
fix: set ValidateOpts on newly constructed Batches of merge
  • Loading branch information
adamdecaf authored Feb 3, 2025
2 parents 40c0bfe + e8adec9 commit cdcc200
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,9 @@ func (outf *outFile) add(incoming *File) error {
// No batch can hold this EntryDetail so create one
if b == nil {
b = &batch{
header: *bh,
entries: treemap.New[string, *EntryDetail](),
header: *bh,
entries: treemap.New[string, *EntryDetail](),
validateOpts: incoming.GetValidation(),
}
outFile.batches = append(outFile.batches, b)
}
Expand Down Expand Up @@ -531,6 +532,7 @@ func convertToFiles(sorted *outFile, conditions Conditions) ([]*File, error) {
if err != nil {
return nil, fmt.Errorf("creating batch from sorted.batches[%d] failed: %w", i, err)
}
batch.SetValidation(nextBatch.validateOpts)

currentFileLineCount += 2 // BatchHeader, BatchControl

Expand Down Expand Up @@ -600,6 +602,7 @@ func convertToFiles(sorted *outFile, conditions Conditions) ([]*File, error) {
if err != nil {
return nil, fmt.Errorf("problem creating overflow batch: %w", err)
}
batch.SetValidation(nextBatch.validateOpts)

merge:
// Add the entry to the current batch
Expand Down Expand Up @@ -634,8 +637,9 @@ func convertToFiles(sorted *outFile, conditions Conditions) ([]*File, error) {
// batch contains a BatcHeader and tree of entries sorted by TraceNumber, which allows for
// faster lookup and insertion into an ACH file
type batch struct {
header BatchHeader
entries *treemap.TreeMap[string, *EntryDetail]
header BatchHeader
entries *treemap.TreeMap[string, *EntryDetail]
validateOpts *ValidateOpts
}

// pickOutFile will search for an existing outFile matching the FileHeader Origin and Destination.
Expand Down
7 changes: 7 additions & 0 deletions merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ func TestMergeFiles__ValidateOpts(t *testing.T) {
require.False(t, opts.SkipAll)
require.True(t, opts.CustomReturnCodes)
require.True(t, opts.AllowInvalidAmounts)

// verify ValidateOpts are set on batches
b, ok := merged[0].Batches[0].(*BatchPPD)
require.True(t, ok)
require.NotNil(t, b.Batch.validateOpts)
require.False(t, b.Batch.validateOpts.SkipAll)
require.True(t, b.Batch.validateOpts.CustomReturnCodes)
}

func TestMergeDir__DefaultFileAcceptor(t *testing.T) {
Expand Down

0 comments on commit cdcc200

Please sign in to comment.