Skip to content

Commit

Permalink
[parser] return all Details for an Account
Browse files Browse the repository at this point in the history
Previously, the Parser was only returning a single Detail for an Account no matter how many
Details defined for the Account in the originating file.
  • Loading branch information
wokkaflokka committed Mar 13, 2024
1 parent 3d8eee1 commit 23b024e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pkg/lib/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])

}

Expand Down
1 change: 1 addition & 0 deletions pkg/lib/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (r *Detail) Read(scan *Bai2Scanner, useCurrentLine bool) error {
case util.TransactionDetailCode:

if find {
isBreak = true
break
}

Expand Down
1 change: 1 addition & 0 deletions pkg/lib/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/`
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down
41 changes: 41 additions & 0 deletions pkg/service/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 23b024e

Please sign in to comment.