package ofxgo import ( "strings" "testing" "time" ) func TestMarshalProfileRequest(t *testing.T) { var expectedString string = ` 20160614073400.000[-5:EST] anonymous00000000000000000000000 anonymous00000000000000000000000 ENG BNK 1987 OFXGO 0001 983373 NONE 20160101000000.000[-5:EST] ` var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", SpecVersion: OfxVersion203, } var request Request request.Signon.UserID = "anonymous00000000000000000000000" request.Signon.UserPass = "anonymous00000000000000000000000" request.Signon.Org = "BNK" request.Signon.Fid = "1987" EST := time.FixedZone("EST", -5*60*60) profileRequest := ProfileRequest{ TrnUID: "983373", DtProfUp: *NewDate(2016, 1, 1, 0, 0, 0, 0, EST), } request.Prof = append(request.Prof, &profileRequest) request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() request.Signon.DtClient = *NewDate(2016, 6, 14, 7, 34, 0, 0, EST) marshalCheckRequest(t, &request, expectedString) } func TestUnmarshalProfileResponse102(t *testing.T) { responseReader := strings.NewReader(`OFXHEADER:100 DATA:OFXSGML VERSION:102 SECURITY:NONE ENCODING:USASCII CHARSET:1252 COMPRESSION:NONE OLDFILEUID:NONE NEWFILEUID:NONE 0 INFO 20170403093458.000 ENG 20021119140000 0f94ce83-13b7-7568-e4fc-c02c7b47e7ab 0 INFO 1 https://ofx.example.com/cgi-ofx/exampleofx NONE Y Example Trade ENG LITE N 300 1 https://ofx.example.com/cgi-ofx/exampleofx NONE Y Example Trade ENG LITE N 300 Y N Y Y 1 https://ofx.example.com/cgi-ofx/exampleofx NONE Y Example Trade ENG LITE N 300 Y N Y Y N 1 https://ofx.example.com/cgi-ofx/exampleofx NONE Y Example Trade ENG LITE N 300 Y 1 https://ofx.example.com/cgi-ofx/exampleofx NONE Y Example Trade ENG LITE N 300 Example Trade 1 32 ALPHAORNUMERIC N Y N N N 20021119140000 Example Trade Financial 5555 Buhunkus Drive Someville NC 28801 USA 1-800-234-5678 1-800-234-5678 1-888-234-5678 http://www.example.com service@example.com example.com `) var expected Response expected.Version = OfxVersion102 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" expected.Signon.DtServer = *NewDateGMT(2017, 4, 3, 9, 34, 58, 0) expected.Signon.Language = "ENG" expected.Signon.DtProfUp = NewDateGMT(2002, 11, 19, 14, 0, 0, 0) profileResponse := ProfileResponse{ TrnUID: "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab", Status: Status{ Code: 0, Severity: "INFO", }, MessageSetList: MessageSetList{ MessageSet{ Name: "SIGNONMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", Language: []String{"ENG"}, SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, MessageSet{ Name: "SIGNUPMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", Language: []String{"ENG"}, SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, MessageSet{ Name: "INVSTMTMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", Language: []String{"ENG"}, SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, MessageSet{ Name: "SECLISTMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", Language: []String{"ENG"}, SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, MessageSet{ Name: "PROFMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", Language: []String{"ENG"}, SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, }, SignonInfoList: []SignonInfo{ { SignonRealm: "Example Trade", Min: 1, Max: 32, CharType: CharTypeAlphaOrNumeric, CaseSen: false, Special: true, Spaces: false, PinCh: false, ChgPinFirst: false, }, }, DtProfUp: *NewDateGMT(2002, 11, 19, 14, 0, 0, 0), FiName: "Example Trade Financial", Addr1: "5555 Buhunkus Drive", City: "Someville", State: "NC", PostalCode: "28801", Country: "USA", CsPhone: "1-800-234-5678", TsPhone: "1-800-234-5678", FaxPhone: "1-888-234-5678", URL: "http://www.example.com", Email: "service@example.com", // Ignored: example.com } expected.Prof = append(expected.Prof, &profileResponse) response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } checkResponsesEqual(t, &expected, response) checkResponseRoundTrip(t, response) }