package ofxgo_test import ( "github.com/aclindsa/ofxgo" "math/big" "strings" "testing" "time" ) func TestMarshalBankStatementRequest(t *testing.T) { var expectedString string = ` 20060115112300.000[-5:EST] myusername Pa$$word ENG BNK 1987 OFXGO 0001 123 318398732 78346129 CHECKING Y ` var client = ofxgo.Client{ AppId: "OFXGO", AppVer: "0001", SpecVersion: "203", } var request ofxgo.Request request.Signon.UserId = "myusername" request.Signon.UserPass = "Pa$$word" request.Signon.Org = "BNK" request.Signon.Fid = "1987" statementRequest := ofxgo.StatementRequest{ TrnUID: "123", BankAcctFrom: ofxgo.BankAcct{ BankId: "318398732", AcctId: "78346129", AcctType: "CHECKING", }, Include: true, } request.Bank = append(request.Bank, &statementRequest) request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() EST := time.FixedZone("EST", -5*60*60) request.Signon.DtClient = ofxgo.Date(time.Date(2006, 1, 15, 11, 23, 0, 0, EST)) marshalCheckRequest(t, &request, expectedString) } func TestUnmarshalBankStatementResponse(t *testing.T) { responseReader := strings.NewReader(` 0 INFO 20060115112303 ENG 20050221091300 20060102160000 BNK 1987 1001 0 INFO USD 318398732 78346129 CHECKING 20060101 20060115 CHECK 20060104 -200.00 00592 2002 ATM 20060112 20060112 -300.00 00679 200.29 200601141600 200.29 200601141600 `) var expected ofxgo.Response GMT := time.FixedZone("GMT", 0) expected.Version = "203" expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" expected.Signon.DtServer = ofxgo.Date(time.Date(2006, 1, 15, 11, 23, 03, 0, GMT)) expected.Signon.Language = "ENG" dtprofup := ofxgo.Date(time.Date(2005, 2, 21, 9, 13, 0, 0, GMT)) expected.Signon.DtProfUp = &dtprofup dtacctup := ofxgo.Date(time.Date(2006, 1, 2, 16, 0, 0, 0, GMT)) expected.Signon.DtAcctUp = &dtacctup expected.Signon.Org = "BNK" expected.Signon.Fid = "1987" var trnamt1, trnamt2 big.Rat trnamt1.SetFrac64(-20000, 100) trnamt2.SetFrac64(-30000, 100) dtuser2 := ofxgo.Date(time.Date(2006, 1, 12, 0, 0, 0, 0, GMT)) banktranlist := ofxgo.TransactionList{ DtStart: ofxgo.Date(time.Date(2006, 1, 1, 0, 0, 0, 0, GMT)), DtEnd: ofxgo.Date(time.Date(2006, 1, 15, 0, 0, 0, 0, GMT)), Transactions: []ofxgo.Transaction{ { TrnType: "CHECK", DtPosted: ofxgo.Date(time.Date(2006, 1, 4, 0, 0, 0, 0, GMT)), TrnAmt: ofxgo.Amount(trnamt1), FiTId: "00592", CheckNum: "2002", }, { TrnType: "ATM", DtPosted: ofxgo.Date(time.Date(2006, 1, 12, 0, 0, 0, 0, GMT)), DtUser: &dtuser2, TrnAmt: ofxgo.Amount(trnamt2), FiTId: "00679", }, }, } var balamt, availbalamt big.Rat balamt.SetFrac64(20029, 100) availbalamt.SetFrac64(20029, 100) availdtasof := ofxgo.Date(time.Date(2006, 1, 14, 16, 0, 0, 0, GMT)) statementResponse := ofxgo.StatementResponse{ TrnUID: "1001", Status: ofxgo.Status{ Code: 0, Severity: "INFO", }, CurDef: "USD", BankAcctFrom: ofxgo.BankAcct{ BankId: "318398732", AcctId: "78346129", AcctType: "CHECKING", }, BankTranList: &banktranlist, BalAmt: ofxgo.Amount(balamt), DtAsOf: ofxgo.Date(time.Date(2006, 1, 14, 16, 0, 0, 0, GMT)), AvailBalAmt: (*ofxgo.Amount)(&availbalamt), AvailDtAsOf: &availdtasof, } expected.Bank = append(expected.Bank, &statementResponse) response, err := ofxgo.ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } checkResponsesEqual(t, &expected, response) }