From e8adec912d6dff15408b66f293d47be77de7a087 Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Thu, 30 Jan 2025 11:26:36 -0600 Subject: [PATCH] fix: set ValidateOpts on newly constructed Batches of merge --- merge.go | 12 ++++++++---- merge_test.go | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/merge.go b/merge.go index 8368002ce..a14950159 100644 --- a/merge.go +++ b/merge.go @@ -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) } @@ -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 @@ -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 @@ -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. diff --git a/merge_test.go b/merge_test.go index a58e697ad..1911f6da8 100644 --- a/merge_test.go +++ b/merge_test.go @@ -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) {