Skip to content

Commit

Permalink
feat: Adding basic parse test
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Jan 4, 2024
1 parent 8bc0198 commit e332585
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
59 changes: 59 additions & 0 deletions fixtures/sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?OFX OFXHEADER="200" VERSION="211" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="12345678901234567890123456789012"?>
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
<MESSAGE>Successful Sign On</MESSAGE>
</STATUS>
<DTSERVER>20230510120000</DTSERVER>
<LANGUAGE>ENG</LANGUAGE>
<FI>
<ORG>BANK NAME</ORG>
<FID>123456789</FID>
</FI>
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>1000000001</TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
<MESSAGE>Successful Transaction</MESSAGE>
</STATUS>
<STMTRS>
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>987654321</BANKID>
<ACCTID>123456789</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20230501000000</DTSTART>
<DTEND>20230510000000</DTEND>
<STMTTRN>
<TRNTYPE>DEBIT</TRNTYPE>
<DTPOSTED>20230503000000</DTPOSTED>
<TRNAMT>-100.00</TRNAMT>
<FITID>1000000001</FITID>
<NAME>Grocery Store</NAME>
</STMTTRN>
<STMTTRN>
<TRNTYPE>CREDIT</TRNTYPE>
<DTPOSTED>20230505000000</DTPOSTED>
<TRNAMT>2000.00</TRNAMT>
<FITID>1000000002</FITID>
<NAME>Paycheck</NAME>
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>5000.00</BALAMT>
<DTASOF>20230510000000</DTASOF>
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/elliotcourant/gofx

go 1.21.1

require github.com/stretchr/testify v1.8.4

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
18 changes: 18 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gofx

import (
"embed"
"path"
"testing"

"github.com/stretchr/testify/require"
)

//go:embed fixtures/*.xml
var fixtureData embed.FS

func GetFixtures(t *testing.T, name string) []byte {
data, err := fixtureData.ReadFile(path.Join("fixtures", name))
require.NoError(t, err, "must be able to load fixture data for parsing")
return data
}
18 changes: 18 additions & 0 deletions ofx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gofx

import (
"encoding/xml"
"testing"

"github.com/stretchr/testify/assert"
)

func TestParse(t *testing.T) {
data := GetFixtures(t, "sample.xml")
var ofx OFX
err := xml.Unmarshal(data, &ofx)
assert.NoError(t, err, "must be able to unmarshal from xml")
assert.Nil(t, ofx.EMAILMSGSRSV1, "email message response should be nil")
assert.NotNil(t, ofx.SIGNONMSGSRSV1, "sign on message response should not be nil")
}

0 comments on commit e332585

Please sign in to comment.