From 8ea820f309df6c9681f86ac8631db394b5c52875 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sun, 9 Apr 2017 07:22:57 -0400 Subject: [PATCH] Add tests for neglected InvTranList elements --- invstmt_test.go | 362 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 362 insertions(+) diff --git a/invstmt_test.go b/invstmt_test.go index 950beb9..247a92a 100644 --- a/invstmt_test.go +++ b/invstmt_test.go @@ -1,7 +1,9 @@ package ofxgo_test import ( + "github.com/aclindsa/go/src/encoding/xml" "github.com/aclindsa/ofxgo" + "reflect" "strings" "testing" "time" @@ -946,3 +948,363 @@ NEWFILEUID: NONE checkResponsesEqual(t, &expected, response) } + +func TestUnmarshalInvTranList(t *testing.T) { + input := ` + 20170101000000 + 20170331000000 + + + + 81818 + 20170203 + 20170207 + + + 78462F103 + CUSIP + + 100 + 229.00 + 9.00 + .26 + -22090.26 + CASH + CASH + + 101.2 + + + + + 81818 + 20170203 + Something to make a memo about + + + 78462F103 + CUSIP + + 100 + 229.00 + -22090.26 + CASH + CASH + + BUYTOOPEN + 100 + + + + 129837-1111 + 20170203 + + + 78462F103 + CUSIP + + 0.26 + CASH + CASH + + + + 129837-1112 + 20170203 + + + 78462F103 + CUSIP + + 2300 + CASH + CASH + + + + 129837-1112 + 20170203 + + 2300 + CASH + CASH + + + + + 81818 + 20170203 + + + 78462F103 + CUSIP + + 100 + 229.00 + -22090.26 + CASH + CASH + + + + + 129837-1112 + 20170203 + + 2300 + CASH + + + + + 129837-1111 + 20170203 + + + 78462F103 + CUSIP + + 100 + 229.00 + -22090.26 + CASH + CASH + + SELL + + + + 129837-1111 + 20170203 + + + 78462F103 + CUSIP + + 2300.00 + CASH + CASH + + + + 129837-1111 + 20170203 + + + 78462F103 + CUSIP + + CASH + 100 + 200 + 2 + 1 + + + + + 129837-1111 + 20170203 + + + 78462F103 + CUSIP + + 100 + 229.00 + -22090.26 + CASH + CASH + + +` + + var units1, unitprice1, commission1, fees1, total1, accrdint, total2, oldunits1, newunits1 ofxgo.Amount + units1.SetFrac64(100, 1) + unitprice1.SetFrac64(229, 1) + commission1.SetFrac64(9, 1) + fees1.SetFrac64(26, 100) + total1.SetFrac64(-2209026, 100) + accrdint.SetFrac64(1012, 10) + total2.SetFrac64(2300, 1) + oldunits1.SetFrac64(100, 1) + newunits1.SetFrac64(200, 1) + + expected := ofxgo.InvTranList{ + DtStart: *ofxgo.NewDateGMT(2017, 1, 1, 0, 0, 0, 0), + DtEnd: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0), + InvTransactions: []ofxgo.InvTransaction{ + ofxgo.BuyDebt{ + InvBuy: ofxgo.InvBuy{ + InvTran: ofxgo.InvTran{ + FiTId: "81818", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtSettle: ofxgo.NewDateGMT(2017, 2, 7, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Units: units1, + UnitPrice: unitprice1, + Commission: commission1, + Fees: fees1, + Total: total1, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + AccrdInt: accrdint, + }, + ofxgo.BuyOpt{ + InvBuy: ofxgo.InvBuy{ + InvTran: ofxgo.InvTran{ + FiTId: "81818", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + Memo: "Something to make a memo about", + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Units: units1, + UnitPrice: unitprice1, + Total: total1, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + OptBuyType: ofxgo.OptBuyTypeBuyToOpen, + ShPerCtrct: 100, + }, + ofxgo.InvExpense{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1111", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Total: fees1, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + ofxgo.JrnlSec{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1112", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Units: total2, + SubAcctTo: ofxgo.SubAcctTypeCash, + SubAcctFrom: ofxgo.SubAcctTypeCash, + }, + ofxgo.JrnlFund{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1112", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + Total: total2, + SubAcctTo: ofxgo.SubAcctTypeCash, + SubAcctFrom: ofxgo.SubAcctTypeCash, + }, + ofxgo.BuyOther{ + InvBuy: ofxgo.InvBuy{ + InvTran: ofxgo.InvTran{ + FiTId: "81818", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Units: units1, + UnitPrice: unitprice1, + Total: total1, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + }, + ofxgo.MarginInterest{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1112", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + Total: total2, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + ofxgo.SellDebt{ + InvSell: ofxgo.InvSell{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1111", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Units: units1, + UnitPrice: unitprice1, + Total: total1, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + SellReason: ofxgo.SellReasonSell, + }, + ofxgo.RetOfCap{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1111", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Total: total2, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + ofxgo.Split{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1111", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + SubAcctSec: ofxgo.SubAcctTypeCash, + OldUnits: oldunits1, + NewUnits: newunits1, + Numerator: 2, + Denominator: 1, + }, + ofxgo.SellOther{ + InvSell: ofxgo.InvSell{ + InvTran: ofxgo.InvTran{ + FiTId: "129837-1111", + DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + }, + SecId: ofxgo.SecurityId{ + UniqueId: "78462F103", + UniqueIdType: "CUSIP", + }, + Units: units1, + UnitPrice: unitprice1, + Total: total1, + SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctFund: ofxgo.SubAcctTypeCash, + }, + }, + }, + } + + var actual ofxgo.InvTranList + err := xml.Unmarshal([]byte(input), &actual) + if err != nil { + t.Fatalf("Unexpected error unmarshalling InvTranList: %s\n", err) + } + checkEqual(t, "InvTranList", reflect.ValueOf(&expected), reflect.ValueOf(&actual)) +}