mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-25 23:23:21 -05:00
testing: Add initial OFX investment import tests
Also fix up a "bug" caused by financial institutions not deciding on which sign to use for an OFX field...
This commit is contained in:
parent
238809cd46
commit
30d4515780
1
internal/handlers/handlers_testdata/401k_mutualfunds.ofx
Normal file
1
internal/handlers/handlers_testdata/401k_mutualfunds.ofx
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?OFX OFXHEADER="200" VERSION="203" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?><OFX><SIGNONMSGSRSV1> <SONRS> <STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY><MESSAGE>SUCCESS</MESSAGE></STATUS><DTSERVER>20171128203521.622[-5:EST]</DTSERVER><LANGUAGE>ENG</LANGUAGE><FI><ORG>ofx.bank.com</ORG><FID>9199</FID></FI></SONRS></SIGNONMSGSRSV1><INVSTMTMSGSRSV1> <INVSTMTTRNRS><TRNUID>d87db96a-c872-7f73-7637-7e9e2816c25a</TRNUID> <STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY><MESSAGE>SUCCESS</MESSAGE></STATUS><INVSTMTRS><DTASOF>20171128193521.926[-5:EST]</DTASOF><CURDEF>USD</CURDEF><INVACCTFROM><BROKERID>ofx.bank.com</BROKERID><ACCTID>12321</ACCTID></INVACCTFROM> <INVTRANLIST><DTSTART>20170829213521.814[-4:EDT]</DTSTART><DTEND>20171127203521.814[-5:EST]</DTEND><BUYMF><INVBUY><INVTRAN><FITID>20170901OAEL011</FITID><DTTRADE>20170901070000.000[-4:EDT]</DTTRADE><MEMO>CONTRIBUTION;VANGUARD TARGET 2045 OAEL;as of 09/01/2017</MEMO></INVTRAN><SECID><UNIQUEID>OAEL</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>1.756</UNITS><UNITPRICE>56.97</UNITPRICE><TOTAL>100.05</TOTAL><SUBACCTSEC>OTHER</SUBACCTSEC><SUBACCTFUND>OTHER</SUBACCTFUND></INVBUY><BUYTYPE>BUY</BUYTYPE> </BUYMF><BUYMF><INVBUY><INVTRAN><FITID>20170915OAEL011</FITID><DTTRADE>20170915070000.000[-4:EDT]</DTTRADE><MEMO>CONTRIBUTION;VANGUARD TARGET 2045 OAEL;as of 09/15/2017</MEMO></INVTRAN><SECID><UNIQUEID>OAEL</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>1.737</UNITS><UNITPRICE>57.59</UNITPRICE><TOTAL>100.05</TOTAL><SUBACCTSEC>OTHER</SUBACCTSEC><SUBACCTFUND>OTHER</SUBACCTFUND></INVBUY><BUYTYPE>BUY</BUYTYPE> </BUYMF><SELLMF><INVSELL><INVTRAN><FITID>20170901OAEL131</FITID><DTTRADE>20170901070000.000[-4:EDT]</DTTRADE><MEMO>FEES;VANGUARD TARGET 2045 OAEL;as of 09/01/2017</MEMO></INVTRAN><SECID><UNIQUEID>OAEL</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>0.07</UNITS><UNITPRICE>56.97</UNITPRICE><TOTAL>4.0</TOTAL><SUBACCTSEC>OTHER</SUBACCTSEC><SUBACCTFUND>OTHER</SUBACCTFUND></INVSELL><SELLTYPE>SELL</SELLTYPE> </SELLMF><SELLMF><INVSELL><INVTRAN><FITID>20171002OAEL131</FITID><DTTRADE>20171002070000.000[-4:EDT]</DTTRADE><MEMO>FEES;VANGUARD TARGET 2045 OAEL;as of 10/02/2017</MEMO></INVTRAN><SECID><UNIQUEID>OAEL</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>0.069</UNITS><UNITPRICE>58.1</UNITPRICE><TOTAL>4.0</TOTAL><SUBACCTSEC>OTHER</SUBACCTSEC><SUBACCTFUND>OTHER</SUBACCTFUND></INVSELL><SELLTYPE>SELL</SELLTYPE> </SELLMF></INVTRANLIST> <INVPOSLIST><POSMF><INVPOS><SECID><UNIQUEID>OAEL</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><HELDINACCT>OTHER</HELDINACCT><POSTYPE>LONG</POSTYPE><UNITS>2792.373</UNITS><UNITPRICE>59.64</UNITPRICE><MKTVAL>200.03</MKTVAL> <DTPRICEASOF>20171127160000.000[-5:EST]</DTPRICEASOF> <MEMO>Market close as of 11/27/2017;VANGUARD TARGET 2045</MEMO></INVPOS></POSMF></INVPOSLIST> <INVBAL><AVAILCASH>0</AVAILCASH><MARGINBALANCE>0</MARGINBALANCE><SHORTBALANCE>0</SHORTBALANCE><BALLIST><BAL><NAME>MarketValue</NAME><DESC>MarketValue</DESC><BALTYPE>DOLLAR</BALTYPE><VALUE>200.03</VALUE><DTASOF>20171128193521.926[-5:EST]</DTASOF></BAL><BAL><NAME>VestedValue</NAME><DESC>VestedValue</DESC><BALTYPE>DOLLAR</BALTYPE><VALUE>200.03</VALUE><DTASOF>20171128193521.926[-5:EST]</DTASOF></BAL><BAL><NAME>TotalAssetsValue</NAME><DESC>TotalAssetsValue</DESC><BALTYPE>DOLLAR</BALTYPE><VALUE>200.03</VALUE><DTASOF>20171128193521.926[-5:EST]</DTASOF></BAL></BALLIST></INVBAL><INV401K><EMPLOYERNAME>QC 401(K) PLAN</EMPLOYERNAME></INV401K><INV401KBAL><TOTAL>200.03</TOTAL><BALLIST><BAL><NAME>MarketValue</NAME><DESC>MarketValue</DESC><BALTYPE>DOLLAR</BALTYPE><VALUE>200.03</VALUE><DTASOF>20171128193521.926[-5:EST]</DTASOF></BAL><BAL><NAME>VestedValue</NAME><DESC>VestedValue</DESC><BALTYPE>DOLLAR</BALTYPE><VALUE>200.03</VALUE><DTASOF>20171128193521.926[-5:EST]</DTASOF></BAL><BAL><NAME>TotalAssetsValue</NAME><DESC>TotalAssetsValue</DESC><BALTYPE>DOLLAR</BALTYPE><VALUE>200.03</VALUE><DTASOF>20171128193521.926[-5:EST]</DTASOF></BAL></BALLIST></INV401KBAL></INVSTMTRS></INVSTMTTRNRS></INVSTMTMSGSRSV1> <SECLISTMSGSRSV1><SECLIST><MFINFO><SECINFO><SECID><UNIQUEID>OAEL</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><SECNAME>VANGUARD TARGET 2045</SECNAME><FIID>OAEL</FIID><UNITPRICE>59.64</UNITPRICE><DTASOF>20171127160000.000[-5:EST]</DTASOF><MEMO>Market close as of 11/27/2017;VANGUARD TARGET 2045</MEMO></SECINFO><MFTYPE>OTHER</MFTYPE></MFINFO></SECLIST></SECLISTMSGSRSV1></OFX>
|
@ -233,6 +233,9 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *Security, account *
|
|||||||
fees.Set(&buy.Fees.Rat)
|
fees.Set(&buy.Fees.Rat)
|
||||||
load.Set(&buy.Load.Rat)
|
load.Set(&buy.Load.Rat)
|
||||||
total.Set(&buy.Total.Rat)
|
total.Set(&buy.Total.Rat)
|
||||||
|
if total.Sign() > 0 {
|
||||||
|
total.Neg(&total)
|
||||||
|
}
|
||||||
|
|
||||||
tradingTotal.Neg(&total)
|
tradingTotal.Neg(&total)
|
||||||
tradingTotal.Sub(&tradingTotal, &commission)
|
tradingTotal.Sub(&tradingTotal, &commission)
|
||||||
@ -495,6 +498,9 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *Security,
|
|||||||
fees.Set(&reinvest.Fees.Rat)
|
fees.Set(&reinvest.Fees.Rat)
|
||||||
load.Set(&reinvest.Load.Rat)
|
load.Set(&reinvest.Load.Rat)
|
||||||
total.Set(&reinvest.Total.Rat)
|
total.Set(&reinvest.Total.Rat)
|
||||||
|
if total.Sign() > 0 {
|
||||||
|
total.Neg(&total)
|
||||||
|
}
|
||||||
|
|
||||||
tradingTotal.Neg(&total)
|
tradingTotal.Neg(&total)
|
||||||
tradingTotal.Sub(&tradingTotal, &commission)
|
tradingTotal.Sub(&tradingTotal, &commission)
|
||||||
@ -694,6 +700,9 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *Security, accoun
|
|||||||
fees.Set(&sell.Fees.Rat)
|
fees.Set(&sell.Fees.Rat)
|
||||||
load.Set(&sell.Load.Rat)
|
load.Set(&sell.Load.Rat)
|
||||||
total.Set(&sell.Total.Rat)
|
total.Set(&sell.Total.Rat)
|
||||||
|
if total.Sign() < 0 {
|
||||||
|
total.Neg(&total)
|
||||||
|
}
|
||||||
|
|
||||||
tradingTotal.Neg(&total)
|
tradingTotal.Neg(&total)
|
||||||
tradingTotal.Sub(&tradingTotal, &commission)
|
tradingTotal.Sub(&tradingTotal, &commission)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package handlers_test
|
package handlers_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/aclindsa/moneygo/internal/handlers"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
@ -60,3 +61,39 @@ func TestImportOFXCreditCard(t *testing.T) {
|
|||||||
accountBalanceHelper(t, d.clients[0], &d.accounts[7], "-4.49")
|
accountBalanceHelper(t, d.clients[0], &d.accounts[7], "-4.49")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImportOFX401kMutualFunds(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)
|
||||||
|
}
|
||||||
|
|
||||||
|
account := &handlers.Account{
|
||||||
|
SecurityId: d.securities[0].SecurityId,
|
||||||
|
UserId: d.users[0].UserId,
|
||||||
|
ParentAccountId: -1,
|
||||||
|
Type: handlers.Investment,
|
||||||
|
Name: "401k",
|
||||||
|
}
|
||||||
|
|
||||||
|
account, err = createAccount(d.clients[0], account)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error creating 401k account: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import and ensure it didn't return a nasty error code
|
||||||
|
if err = importOFX(d.clients[0], account.AccountId, "handlers_testdata/401k_mutualfunds.ofx"); err != nil {
|
||||||
|
t.Fatalf("Error importing OFX: %s\n", err)
|
||||||
|
}
|
||||||
|
accountBalanceHelper(t, d.clients[0], account, "-192.10")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user