diff --git a/pkg/lib/account.go b/pkg/lib/account.go index cb1b09b6..cd0c8b69 100644 --- a/pkg/lib/account.go +++ b/pkg/lib/account.go @@ -178,9 +178,8 @@ func (r *Account) Read(scan *Bai2Scanner, useCurrentLine bool) error { r.Details = append(r.Details, *detail) useCurrentLine = true - default: - return fmt.Errorf("ERROR parsing file on line %d (unabled to read record type %s)", scan.GetLineIndex(), line[0:2]) + return fmt.Errorf("ERROR parsing account on line %d (unable to read record type %s)", scan.GetLineIndex(), line[0:2]) } diff --git a/pkg/lib/detail.go b/pkg/lib/detail.go index cc39dc25..8a2e004f 100644 --- a/pkg/lib/detail.go +++ b/pkg/lib/detail.go @@ -54,6 +54,7 @@ func (r *Detail) Read(scan *Bai2Scanner, useCurrentLine bool) error { case util.TransactionDetailCode: if find { + isBreak = true break } diff --git a/pkg/lib/file_test.go b/pkg/lib/file_test.go index 74270bba..3851135d 100644 --- a/pkg/lib/file_test.go +++ b/pkg/lib/file_test.go @@ -59,6 +59,7 @@ func TestFileWithContinuationRecord(t *testing.T) { 88,047,+000000000000,,,048,+000000000000,,,049,+000000000000,,,050/ 88,+000000000000,,,051,+000000000000,,,052,+000000000000,,,053,+000000000000,,/ 16,409,000000000002500,V,060316,1300,,,RETURNED CHEQUE / +16,409,000000000090000,V,060316,1300,,,RTN-UNKNOWN / 49,+00000000000834000,14/ 98,+00000000001280000,2,25/ 99,+00000000001280000,1,27/` diff --git a/pkg/lib/group.go b/pkg/lib/group.go index bbf4ffc6..7c55aa2e 100644 --- a/pkg/lib/group.go +++ b/pkg/lib/group.go @@ -168,7 +168,7 @@ func (r *Group) Read(scan *Bai2Scanner, useCurrentLine bool) error { return nil default: - return fmt.Errorf("ERROR parsing file on line %d (unabled to read record type %s)", scan.GetLineIndex(), line[0:2]) + return fmt.Errorf("ERROR parsing group on line %d (unable to read record type %s)", scan.GetLineIndex(), line[0:2]) } } diff --git a/pkg/service/handlers_test.go b/pkg/service/handlers_test.go index 07c75bfe..be1a5c3f 100644 --- a/pkg/service/handlers_test.go +++ b/pkg/service/handlers_test.go @@ -91,6 +91,47 @@ func (suite *HandlersTest) TestPrint() { suite.testServer.ServeHTTP(recorder, request) assert.Equal(suite.T(), http.StatusOK, recorder.Code) + + // Verify that the printed file matches the input file. + path := filepath.Join("..", "..", "test", "testdata", testFileName) + fixture, err := os.ReadFile(path) + assert.Equal(suite.T(), nil, err) + + // NB. Account continuations are currently not written to file exactly as they were read. + // Because of this behavior, the returned body does NOT strictly match the file data. + // This test currently asserts on the shape of the file as created by the current return. + // The difference between this output and the sample file is that a subset of data provided on + // each account continuation (88) is instead output on the Account record (03). + assert.NotEqual(suite.T(), recorder.Body.String(), string(fixture)) + + expectedFileBody := `01,0004,12345,060321,0829,001,80,1,2/ +02,12345,0004,1,060317,,CAD,/ +03,10200123456,CAD,040,+000000000000,,,045,+000000000000,,,100,000000000208500/ +88,3,V,060316,,400,000000000208500,8,V,060316,/ +16,409,000000000002500,V,060316,,,,RETURNED CHEQUE / +16,409,000000000090000,V,060316,,,,RTN-UNKNOWN / +16,409,000000000000500,V,060316,,,,RTD CHQ SERVICE CHRG/ +16,108,000000000203500,V,060316,,,,TFR 1020 0345678 / +16,108,000000000002500,V,060316,,,,MACLEOD MALL / +16,108,000000000002500,V,060316,,,,MASCOUCHE QUE / +16,409,000000000020000,V,060316,,,,1000 ISLANDS MALL / +16,409,000000000090000,V,060316,,,,PENHORA MALL / +16,409,000000000002000,V,060316,,,,CAPILANO MALL / +16,409,000000000002500,V,060316,,,,GALERIES LA CAPITALE/ +16,409,000000000001000,V,060316,,,,PLAZA ROCK FOREST / +49,+00000000000834000,14/ +03,10200123456,CAD,040,+000000000000,,,045,+000000000000,,,100,000000000111500/ +88,2,V,060317,,400,000000000111500,4,V,060317,/ +16,108,000000000011500,V,060317,,,,TFR 1020 0345678 / +16,108,000000000100000,V,060317,,,,MONTREAL / +16,409,000000000100000,V,060317,,,,GRANDFALL NB / +16,409,000000000009000,V,060317,,,,HAMILTON ON / +16,409,000000000002000,V,060317,,,,WOODSTOCK NB / +16,409,000000000000500,V,060317,,,,GALERIES RICHELIEU / +49,+00000000000446000,9/ +98,+00000000001280000,2,25/ +99,+00000000001280000,1,27/` + assert.Equal(suite.T(), recorder.Body.String(), expectedFileBody) } func (suite *HandlersTest) TestParse() {