mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 07:33:21 -05:00
testing: Add initial OFX credit card import test
This commit is contained in:
parent
d656f15e84
commit
238809cd46
11
internal/handlers/handlers_testdata/creditcard.ofx
Normal file
11
internal/handlers/handlers_testdata/creditcard.ofx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
OFXHEADER:100
|
||||||
|
DATA:OFXSGML
|
||||||
|
VERSION:102
|
||||||
|
SECURITY:NONE
|
||||||
|
ENCODING:USASCII
|
||||||
|
CHARSET:1252
|
||||||
|
COMPRESSION:NONE
|
||||||
|
OLDFILEUID:NONE
|
||||||
|
NEWFILEUID:NONE
|
||||||
|
|
||||||
|
<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0<SEVERITY>INFO<MESSAGE>SUCCESS</STATUS><DTSERVER>20171128054239.013[-5:EST]<LANGUAGE>ENG<FI><ORG>C2<FID>29292</FI></SONRS></SIGNONMSGSRSV1><CREDITCARDMSGSRSV1><CCSTMTTRNRS><TRNUID>1cc61e4b-1f74-7d9a-b143-b8c80d5fda58<STATUS><CODE>0<SEVERITY>INFO</STATUS><CCSTMTRS><CURDEF>USD<CCACCTFROM><ACCTID>1234123412341234</CCACCTFROM><BANKTRANLIST><DTSTART>20170731054239.277[-4:EDT]<DTEND>20171128054239.277[-5:EST]<STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20171016120000[0:GMT]<TRNAMT>-99.98<FITID>2017101624445727288300440999736<NAME>KROGER #111</STMTTRN><STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20170910120000[0:GMT]<TRNAMT>-150<FITID>2017091024493987251438675718282<NAME>CHARITY DONATION</STMTTRN><STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20170814120000[0:GMT]<TRNAMT>-44.99<FITID>2017081424692167225100642481235<NAME>CABLE</STMTTRN><STMTTRN><TRNTYPE>CREDIT<DTPOSTED>20171101120000[0:GMT]<TRNAMT>185.71<FITID>2017110123053057200000291455612<NAME>Payment Thank You Electro</STMTTRN><STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20171016120000[0:GMT]<TRNAMT>-4.49<FITID>2017101624510727289100677772726<NAME>CRAFTS</STMTTRN><STMTTRN><TRNTYPE>CREDIT<DTPOSTED>20170815120000[0:GMT]<TRNAMT>109.26<FITID>2017081574692167226100322807539<NAME>Example.com</STMTTRN></BANKTRANLIST><LEDGERBAL><BALAMT>-4.49<DTASOF>20171128070000.000[-5:EST]</LEDGERBAL><AVAILBAL><BALAMT>995.51<DTASOF>20171128070000.000[-5:EST]</AVAILBAL></CCSTMTRS></CCSTMTTRNRS></CREDITCARDMSGSRSV1></OFX>
|
@ -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")
|
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) {
|
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
|
||||||
// Ensure there's only one USD currency
|
// Ensure there's only one USD currency
|
||||||
oldDefault, err := getSecurity(d.clients[0], d.users[0].DefaultCurrency)
|
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")
|
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")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -295,6 +295,13 @@ var data = []TestData{
|
|||||||
Type: handlers.Expense,
|
Type: handlers.Expense,
|
||||||
Name: "Expenses",
|
Name: "Expenses",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
UserId: 0,
|
||||||
|
SecurityId: 0,
|
||||||
|
ParentAccountId: -1,
|
||||||
|
Type: handlers.Liability,
|
||||||
|
Name: "Credit Card",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
transactions: []handlers.Transaction{
|
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{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user