1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-25 07:13:20 -05:00

testing: Add another brokerage account OFX import test

This commit is contained in:
Aaron Lindsay 2017-12-01 21:21:55 -05:00
parent 05fdaaeb42
commit ffc8602336
3 changed files with 96 additions and 4 deletions

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?><?OFX OFXHEADER="200" VERSION="202" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?><OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY><MESSAGE>Successful Sign On</MESSAGE></STATUS><DTSERVER>20171130013742</DTSERVER><LANGUAGE>ENG</LANGUAGE><DTPROFUP>20160713012000</DTPROFUP><FI><ORG>Somewhere</ORG><FID>92772</FID></FI><SESSCOOKIE>01927017240917209172407124984652986</SESSCOOKIE></SONRS></SIGNONMSGSRSV1><INVSTMTMSGSRSV1><INVSTMTTRNRS><TRNUID>a59df4c3-9408-00bb-fd6d-0a06695885b1</TRNUID><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><INVSTMTRS><DTASOF>20171129160000.000[-5:EST]</DTASOF><CURDEF>USD</CURDEF><INVACCTFROM><BROKERID>investing.example.com</BROKERID><ACCTID>73728292</ACCTID></INVACCTFROM><INVTRANLIST><DTSTART>20160529160000.000[-5:EST]160000.000[-5:EST]</DTSTART><DTEND>20171130013742.000[-5:EST]</DTEND>
<BUYMF><INVBUY><INVTRAN><FITID>993971056</FITID><DTTRADE>20170315160000.000[-5:EST]</DTTRADE><DTSETTLE>20170316160000.000[-5:EST]</DTSETTLE><MEMO>BUY</MEMO></INVTRAN><SECID><UNIQUEID>921937108</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>37.700</UNITS><UNITPRICE>10.61</UNITPRICE><TOTAL>-400.0</TOTAL><SUBACCTSEC>CASH</SUBACCTSEC><SUBACCTFUND>CASH</SUBACCTFUND></INVBUY><BUYTYPE>BUY</BUYTYPE></BUYMF>
<BUYSTOCK><INVBUY><INVTRAN><FITID>206046941</FITID><DTTRADE>20160620160000.000[-5:EST]</DTTRADE><DTSETTLE>20160623160000.000[-5:EST]</DTSETTLE><MEMO>BUY</MEMO></INVTRAN><SECID><UNIQUEID>921909768</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>15.0</UNITS><UNITPRICE>45.17987</UNITPRICE><TOTAL>-677.70</TOTAL><SUBACCTSEC>CASH</SUBACCTSEC><SUBACCTFUND>CASH</SUBACCTFUND></INVBUY><BUYTYPE>BUY</BUYTYPE></BUYSTOCK>
<INCOME><INVTRAN><FITID>63590590</FITID><DTTRADE>20160729160000.000[-5:EST]</DTTRADE><DTSETTLE>20160729160000.000[-5:EST]</DTSETTLE><MEMO>DIVIDEND PAYMENTDIVIDEND PAYMENT</MEMO></INVTRAN><SECID><UNIQUEID>78462F103</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><INCOMETYPE>DIV</INCOMETYPE><TOTAL>1.08</TOTAL><SUBACCTSEC>CASH</SUBACCTSEC><SUBACCTFUND>CASH</SUBACCTFUND></INCOME>
<REINVEST><INVTRAN><FITID>769223517</FITID><DTTRADE>20160606160000.000[-5:EST]</DTTRADE><DTSETTLE>20160606160000.000[-5:EST]</DTSETTLE><MEMO>DIVIDEND REINVESTMENTDIVIDEND REINVESTMENT</MEMO></INVTRAN><SECID><UNIQUEID>049560105</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><INCOMETYPE>DIV</INCOMETYPE><TOTAL>-6.43</TOTAL><SUBACCTSEC>CASH</SUBACCTSEC><UNITS>0.086</UNITS><UNITPRICE>74.9777</UNITPRICE></REINVEST>
<SELLMF><INVSELL><INVTRAN><FITID>619689018</FITID><DTTRADE>20160627160000.000[-5:EST]</DTTRADE><DTSETTLE>20160627160000.000[-5:EST]</DTSETTLE><MEMO>MONEY FUND REDEMPTION</MEMO></INVTRAN><SECID><UNIQUEID>922906300</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>-21.57</UNITS><UNITPRICE>1.0</UNITPRICE><TOTAL>21.57</TOTAL><SUBACCTSEC>CASH</SUBACCTSEC><SUBACCTFUND>CASH</SUBACCTFUND></INVSELL><SELLTYPE>SELL</SELLTYPE></SELLMF>
<SELLSTOCK><INVSELL><INVTRAN><FITID>328444499</FITID><DTTRADE>20160708160000.000[-5:EST]</DTTRADE><DTSETTLE>20160713160000.000[-5:EST]</DTSETTLE><MEMO>SELL</MEMO></INVTRAN><SECID><UNIQUEID>921909768</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><UNITS>-10.0</UNITS><UNITPRICE>44.26013</UNITPRICE><FEES>0.07</FEES><TOTAL>442.53</TOTAL><SUBACCTSEC>CASH</SUBACCTSEC><SUBACCTFUND>CASH</SUBACCTFUND></INVSELL><SELLTYPE>SELL</SELLTYPE></SELLSTOCK>
<INVBANKTRAN><STMTTRN><TRNTYPE>OTHER</TRNTYPE><DTPOSTED>20160607160000.000[-5:EST]</DTPOSTED><TRNAMT>1000.0</TRNAMT><FITID>230048208</FITID></STMTTRN><SUBACCTFUND>CASH</SUBACCTFUND></INVBANKTRAN>
</INVTRANLIST>
<INVPOSLIST><POSSTOCK><INVPOS><SECID><UNIQUEID>049560105</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><HELDINACCT>CASH</HELDINACCT><POSTYPE>LONG</POSTYPE><UNITS>6.086</UNITS><UNITPRICE>90.51</UNITPRICE><MKTVAL>550.843</MKTVAL><DTPRICEASOF>20171128160000.000[-5:EST]</DTPRICEASOF><MEMO>Price as of date based on closing price</MEMO></INVPOS><REINVDIV>Y</REINVDIV></POSSTOCK><POSMF><INVPOS><SECID><UNIQUEID>921937108</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><HELDINACCT>CASH</HELDINACCT><POSTYPE>LONG</POSTYPE><UNITS>37.77</UNITS><UNITPRICE>10.75</UNITPRICE><MKTVAL>406.02</MKTVAL><DTPRICEASOF>20171128160000.000[-5:EST]</DTPRICEASOF><MEMO>Price as of date based on closing price</MEMO></INVPOS><REINVDIV>Y</REINVDIV><REINVCG>Y</REINVCG></POSMF><POSMF><INVPOS><SECID><UNIQUEID>922906300</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><HELDINACCT>CASH</HELDINACCT><POSTYPE>LONG</POSTYPE><UNITS>24.87</UNITS><UNITPRICE>1.0</UNITPRICE><MKTVAL>24.87</MKTVAL><DTPRICEASOF>20171128160000.000[-5:EST]</DTPRICEASOF><MEMO>Price as of date based on closing price</MEMO></INVPOS><REINVDIV>N</REINVDIV><REINVCG>N</REINVCG></POSMF></INVPOSLIST>
<INVBAL><AVAILCASH>387.48</AVAILCASH><MARGINBALANCE>0.0</MARGINBALANCE><SHORTBALANCE>0.0</SHORTBALANCE></INVBAL></INVSTMTRS></INVSTMTTRNRS></INVSTMTMSGSRSV1><SECLISTMSGSRSV1><SECLIST><STOCKINFO><SECINFO><SECID><UNIQUEID>049560105</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><SECNAME>ATMOS ENERGY CORP</SECNAME><TICKER>ATO</TICKER><UNITPRICE>90.51</UNITPRICE><MEMO>Price as of date based on closing price</MEMO></SECINFO><STOCKTYPE>COMMON</STOCKTYPE><YIELD>2.1491</YIELD></STOCKINFO><STOCKINFO><SECINFO><SECID><UNIQUEID>921909768</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><SECNAME>VANGUARD TOTAL INTL STOCK INDE</SECNAME><TICKER>921909768</TICKER><MEMO>BUY</MEMO></SECINFO></STOCKINFO><STOCKINFO><SECINFO><SECID><UNIQUEID>78462F103</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><SECNAME>20SPDR SP 500 ETF</SECNAME><TICKER>78462F103</TICKER><MEMO>SELL</MEMO></SECINFO></STOCKINFO><MFINFO><SECINFO><SECID><UNIQUEID>921937108</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><SECNAME>Vanguard Total Bond Market Index Fund Investor Shares</SECNAME><TICKER>VBMFX</TICKER><UNITPRICE>10.75</UNITPRICE><MEMO>Price as of date based on closing price</MEMO></SECINFO><MFTYPE>OPENEND</MFTYPE></MFINFO><MFINFO><SECINFO><SECID><UNIQUEID>922906300</UNIQUEID><UNIQUEIDTYPE>CUSIP</UNIQUEIDTYPE></SECID><SECNAME>Vanguard Federal Money Market Fund</SECNAME><TICKER>VMFXX</TICKER><UNITPRICE>1.0</UNITPRICE><MEMO>Price as of date based on closing price</MEMO></SECINFO><MFTYPE>OPENEND</MFTYPE></MFINFO></SECLIST></SECLISTMSGSRSV1></OFX>

View File

@ -705,10 +705,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *Security, accoun
load.Neg(&load)
tradingTotal.Neg(&total)
tradingTotal.Sub(&tradingTotal, &commission)
tradingTotal.Sub(&tradingTotal, &taxes)
tradingTotal.Sub(&tradingTotal, &fees)
tradingTotal.Sub(&tradingTotal, &load)
tradingTotal.Add(&tradingTotal, &commission)
tradingTotal.Add(&tradingTotal, &taxes)
tradingTotal.Add(&tradingTotal, &fees)
tradingTotal.Add(&tradingTotal, &load)
// Convert amounts to account's currency if Currency is set
if ok, _ := sell.Currency.Valid(); ok {

View File

@ -146,3 +146,84 @@ func TestImportOFX401kMutualFunds(t *testing.T) {
}
})
}
func TestImportOFXBrokerage(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)
}
// Create the brokerage account
account := &handlers.Account{
SecurityId: d.securities[0].SecurityId,
UserId: d.users[0].UserId,
ParentAccountId: -1,
Type: handlers.Investment,
Name: "Personal Brokerage",
}
account, err = createAccount(d.clients[0], account)
if err != nil {
t.Fatalf("Error creating 'Personal Brokerage' 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/brokerage.ofx"); err != nil {
t.Fatalf("Error importing OFX: %s\n", err)
}
accountBalanceHelper(t, d.clients[0], account, "387.48")
// Make sure the USD trading account was created and has the right
// value
usdtrading, err := findAccount(d.clients[0], "USD", handlers.Trading, d.users[0].DefaultCurrency)
if err != nil {
t.Fatalf("Error finding USD trading account: %s\n", err)
}
accountBalanceHelper(t, d.clients[0], usdtrading, "619.96")
// Check investment/trading balances for all securities traded
checks := []struct {
Ticker string
Name string
Balance string
TradingBalance string
}{
{"VBMFX", "Vanguard Total Bond Market Index Fund Investor Shares", "37.70000", "-37.70000"},
{"921909768", "VANGUARD TOTAL INTL STOCK INDE", "5.00000", "-5.00000"},
{"ATO", "ATMOS ENERGY CORP", "0.08600", "-0.08600"},
{"VMFXX", "Vanguard Federal Money Market Fund", "-21.57000", "21.57000"},
}
for _, check := range checks {
security, err := findSecurity(d.clients[0], check.Ticker, handlers.Stock)
if err != nil {
t.Fatalf("Error finding security: %s\n", err)
}
account, err := findAccount(d.clients[0], check.Name, handlers.Investment, security.SecurityId)
if err != nil {
t.Fatalf("Error finding trading account: %s\n", err)
}
accountBalanceHelper(t, d.clients[0], account, check.Balance)
tradingaccount, err := findAccount(d.clients[0], check.Name, handlers.Trading, security.SecurityId)
if err != nil {
t.Fatalf("Error finding trading account: %s\n", err)
}
accountBalanceHelper(t, d.clients[0], tradingaccount, check.TradingBalance)
}
// TODO check reinvestment/income to make sure they're registered as income?
})
}