From 674aac9dba9666d96265d67a752fefdce0dfd83e Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Mon, 10 Apr 2017 05:27:47 -0400 Subject: [PATCH] Add tests for list of positions --- invstmt.go | 2 +- invstmt_test.go | 173 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 1 deletion(-) diff --git a/invstmt.go b/invstmt.go index d1e2cd6..6b29000 100644 --- a/invstmt.go +++ b/invstmt.go @@ -590,7 +590,7 @@ type MFPosition struct { UnitsStreet Amount `xml:"UNITSSTREET,omitempty"` // Units in the FI’s street name UnitsUser Amount `xml:"UNITSUSER,omitempty"` // Units in the user's name directly ReinvDiv Boolean `xml:"REINVDIV,omitempty"` // Reinvest dividends - ReinCG Boolean `xml:"REINVCG,omitempty"` // Reinvest capital gains + ReinvCG Boolean `xml:"REINVCG,omitempty"` // Reinvest capital gains } func (p MFPosition) PositionType() string { diff --git a/invstmt_test.go b/invstmt_test.go index 247a92a..50727e6 100644 --- a/invstmt_test.go +++ b/invstmt_test.go @@ -1308,3 +1308,176 @@ func TestUnmarshalInvTranList(t *testing.T) { } checkEqual(t, "InvTranList", reflect.ValueOf(&expected), reflect.ValueOf(&actual)) } + +func TestUnmarshalPositionList(t *testing.T) { + input := ` + + + + 78462F103 + CUSIP + + CASH + LONG + 1 + 3 + 300 + 20170331160000 + + + + + + 78462F103 + CUSIP + + CASH + SHORT + 200 + 235.74 + 47148.00 + 20170331160000 + Price as of previous close + + Y + + + + + 129887339 + CUSIP + + CASH + LONG + 1 + 3 + 300 + 20170331160000 + + + + + + 129887339 + CUSIP + + CASH + LONG + 1 + 3 + 300 + 20170331160000 + + + + + + 78462F103 + CUSIP + + CASH + LONG + 200 + 235.74 + 47148.00 + 20170331160000 + Price as of previous close + + Y + N + +` + + var posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2 ofxgo.Amount + posunits1.SetFrac64(200, 1) + posunitprice1.SetFrac64(23574, 100) + posmktval1.SetFrac64(47148, 1) + posunits2.SetFrac64(1, 1) + posunitprice2.SetFrac64(3, 1) + posmktval2.SetFrac64(300, 1) + + expected := ofxgo.PositionList{ + ofxgo.OtherPosition{ + InvPos: ofxgo.InvPosition{ + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + HeldInAcct: ofxgo.SubAcctTypeCash, + PosType: ofxgo.PosTypeLong, + Units: posunits2, + UnitPrice: posunitprice2, + MktVal: posmktval2, + DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + }, + }, + ofxgo.StockPosition{ + InvPos: ofxgo.InvPosition{ + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + HeldInAcct: ofxgo.SubAcctTypeCash, + PosType: ofxgo.PosTypeShort, + Units: posunits1, + UnitPrice: posunitprice1, + MktVal: posmktval1, + DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + Memo: "Price as of previous close", + }, + ReinvDiv: true, + }, + ofxgo.DebtPosition{ + InvPos: ofxgo.InvPosition{ + SecId: ofxgo.SecurityId{ + UniqueId: "129887339", + UniqueIdType: "CUSIP", + }, + HeldInAcct: ofxgo.SubAcctTypeCash, + PosType: ofxgo.PosTypeLong, + Units: posunits2, + UnitPrice: posunitprice2, + MktVal: posmktval2, + DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + }, + }, + ofxgo.OptPosition{ + InvPos: ofxgo.InvPosition{ + SecId: ofxgo.SecurityId{ + UniqueId: "129887339", + UniqueIdType: "CUSIP", + }, + HeldInAcct: ofxgo.SubAcctTypeCash, + PosType: ofxgo.PosTypeLong, + Units: posunits2, + UnitPrice: posunitprice2, + MktVal: posmktval2, + DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + }, + }, + ofxgo.MFPosition{ + InvPos: ofxgo.InvPosition{ + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + HeldInAcct: ofxgo.SubAcctTypeCash, + PosType: ofxgo.PosTypeLong, + Units: posunits1, + UnitPrice: posunitprice1, + MktVal: posmktval1, + DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + Memo: "Price as of previous close", + }, + ReinvDiv: true, + ReinvCG: false, + }, + } + + var actual ofxgo.PositionList + err := xml.Unmarshal([]byte(input), &actual) + if err != nil { + t.Fatalf("Unexpected error unmarshalling PositionList: %s\n", err) + } + checkEqual(t, "PositionList", reflect.ValueOf(&expected), reflect.ValueOf(&actual)) +}