From 238809cd46a676bb589e99bc1998c619f8355b1e Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 28 Nov 2017 20:14:38 -0500 Subject: [PATCH] testing: Add initial OFX credit card import test --- .../handlers/handlers_testdata/creditcard.ofx | 11 ++++++++ internal/handlers/ofx_test.go | 25 ++++++++++++++++++- internal/handlers/testdata_test.go | 11 ++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 internal/handlers/handlers_testdata/creditcard.ofx diff --git a/internal/handlers/handlers_testdata/creditcard.ofx b/internal/handlers/handlers_testdata/creditcard.ofx new file mode 100644 index 0000000..e2ba6de --- /dev/null +++ b/internal/handlers/handlers_testdata/creditcard.ofx @@ -0,0 +1,11 @@ +OFXHEADER:100 +DATA:OFXSGML +VERSION:102 +SECURITY:NONE +ENCODING:USASCII +CHARSET:1252 +COMPRESSION:NONE +OLDFILEUID:NONE +NEWFILEUID:NONE + +0INFOSUCCESS20171128054239.013[-5:EST]ENGC2292921cc61e4b-1f74-7d9a-b143-b8c80d5fda580INFOUSD123412341234123420170731054239.277[-4:EDT]20171128054239.277[-5:EST]DEBIT20171016120000[0:GMT]-99.982017101624445727288300440999736KROGER #111DEBIT20170910120000[0:GMT]-1502017091024493987251438675718282CHARITY DONATIONDEBIT20170814120000[0:GMT]-44.992017081424692167225100642481235CABLECREDIT20171101120000[0:GMT]185.712017110123053057200000291455612Payment Thank You ElectroDEBIT20171016120000[0:GMT]-4.492017101624510727289100677772726CRAFTSCREDIT20170815120000[0:GMT]109.262017081574692167226100322807539Example.com-4.4920171128070000.000[-5:EST]995.5120171128070000.000[-5:EST] diff --git a/internal/handlers/ofx_test.go b/internal/handlers/ofx_test.go index 1e6a440..ddbdf6e 100644 --- a/internal/handlers/ofx_test.go +++ b/internal/handlers/ofx_test.go @@ -10,7 +10,7 @@ func importOFX(client *http.Client, accountid int64, filename string) error { return uploadFile(client, filename, "/v1/accounts/"+strconv.FormatInt(accountid, 10)+"/imports/ofxfile") } -func TestImportOFX(t *testing.T) { +func TestImportOFXChecking(t *testing.T) { RunWith(t, &data[0], func(t *testing.T, d *TestData) { // Ensure there's only one USD currency oldDefault, err := getSecurity(d.clients[0], d.users[0].DefaultCurrency) @@ -37,3 +37,26 @@ func TestImportOFX(t *testing.T) { accountBalanceHelper(t, d.clients[0], &d.accounts[1], "5336.27") }) } + +func TestImportOFXCreditCard(t *testing.T) { + RunWith(t, &data[0], func(t *testing.T, d *TestData) { + // Ensure there's only one USD currency + oldDefault, err := getSecurity(d.clients[0], d.users[0].DefaultCurrency) + if err != nil { + t.Fatalf("Error fetching default security: %s\n", err) + } + d.users[0].DefaultCurrency = d.securities[0].SecurityId + if _, err := updateUser(d.clients[0], &d.users[0]); err != nil { + t.Fatalf("Error updating user: %s\n", err) + } + if err := deleteSecurity(d.clients[0], oldDefault); err != nil { + t.Fatalf("Error removing default security: %s\n", err) + } + + // Import and ensure it didn't return a nasty error code + if err = importOFX(d.clients[0], d.accounts[7].AccountId, "handlers_testdata/creditcard.ofx"); err != nil { + t.Fatalf("Error importing OFX: %s\n", err) + } + accountBalanceHelper(t, d.clients[0], &d.accounts[7], "-4.49") + }) +} diff --git a/internal/handlers/testdata_test.go b/internal/handlers/testdata_test.go index 88303ba..db13381 100644 --- a/internal/handlers/testdata_test.go +++ b/internal/handlers/testdata_test.go @@ -295,6 +295,13 @@ var data = []TestData{ Type: handlers.Expense, Name: "Expenses", }, + { + UserId: 0, + SecurityId: 0, + ParentAccountId: -1, + Type: handlers.Liability, + Name: "Credit Card", + }, }, transactions: []handlers.Transaction{ { @@ -462,6 +469,10 @@ end`, }, }, }, + "Credit Card": { + Values: []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Series: map[string]*handlers.Series{}, + }, }, }, },