Skip to content

Commit

Permalink
new test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbornsteinMOOV committed Aug 3, 2023
1 parent a3f9494 commit e72da18
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion pkg/response/file_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func TestFileTransformer(t *testing.T) {
require.Error(t, err)
})

t.Run("CopyAndDelayProcess", func(t *testing.T) {
t.Run("CopyAndDelayProcess - Return", func(t *testing.T) {
resp1 := service.Response{
Match: matchEntry1,
Action: actionCopy,
Expand Down Expand Up @@ -295,6 +295,53 @@ func TestFileTransformer(t *testing.T) {
require.NoError(t, err)
require.Less(t, fInfo.ModTime(), time.Now())
})

t.Run("CopyAndDelayProcess - Correction", func(t *testing.T) {
resp1 := service.Response{
Match: matchEntry1,
Action: actionCopy,
}
resp2 := service.Response{
Match: matchEntry1,
Action: actionDelayCorrection,
}
fileTransformer, dir := testFileTransformer(t, resp1, resp2)

achIn, err := ach.ReadFile(filepath.Join("..", "..", "testdata", "20210308-1806-071000301.ach"))
require.NoError(t, err)
require.NotNil(t, achIn)

// transform the file
err = fileTransformer.Transform(achIn)
require.NoError(t, err)

// verify the "returned" file created
retdir := filepath.Join(dir, "returned")
fds, err := os.ReadDir(retdir)
require.NoError(t, err)
require.Len(t, fds, 1)
found, err := ach.ReadFile(filepath.Join(retdir, fds[0].Name()))
require.NoError(t, err)
require.Equal(t, "C01", found.Batches[0].GetEntries()[0].Addenda98.ChangeCode)

// verify the timestamp on the file is in the future
fInfo, err := fds[0].Info()
require.NoError(t, err)
require.Greater(t, fInfo.ModTime(), time.Now())

// verify the "reconciliation" file created
recondir := filepath.Join(dir, "reconciliation")
fds, err = os.ReadDir(recondir)
require.NoError(t, err)
require.Len(t, fds, 1)
found, _ = ach.ReadFile(filepath.Join(recondir, fds[0].Name()))
require.Equal(t, matchEntry1.IndividualName, strings.Trim(found.Batches[0].GetEntries()[0].IndividualName, " "))

// verify the timestamp on the file is in the past
fInfo, err = fds[0].Info()
require.NoError(t, err)
require.Less(t, fInfo.ModTime(), time.Now())
})
}

func testFileTransformer(t *testing.T, resp ...service.Response) (*FileTransfomer, string) {
Expand Down

0 comments on commit e72da18

Please sign in to comment.