package ofxgo_test
import (
"github.com/aclindsa/ofxgo"
"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 = ofxgo.Client{
AppId: "OFXGO",
AppVer: "0001",
SpecVersion: "203",
}
var request ofxgo.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 := ofxgo.ProfileRequest{
TrnUID: "983373",
DtProfUp: *ofxgo.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 = *ofxgo.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 ofxgo.Response
expected.Version = "102"
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 3, 9, 34, 58, 0)
expected.Signon.Language = "ENG"
expected.Signon.DtProfUp = ofxgo.NewDateGMT(2002, 11, 19, 14, 0, 0, 0)
profileResponse := ofxgo.ProfileResponse{
TrnUID: "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab",
Status: ofxgo.Status{
Code: 0,
Severity: "INFO",
},
MessageSetList: ofxgo.MessageSetList{
ofxgo.MessageSet{
Name: "SIGNONMSGSETV1",
Ver: 1,
Url: "https://ofx.example.com/cgi-ofx/exampleofx",
OfxSec: "NONE",
TranspSec: true,
SignonRealm: "Example Trade",
Language: []ofxgo.String{"ENG"},
SyncMode: "LITE",
RespFileER: false,
// Ignored: 300
},
ofxgo.MessageSet{
Name: "SIGNUPMSGSETV1",
Ver: 1,
Url: "https://ofx.example.com/cgi-ofx/exampleofx",
OfxSec: "NONE",
TranspSec: true,
SignonRealm: "Example Trade",
Language: []ofxgo.String{"ENG"},
SyncMode: "LITE",
RespFileER: false,
// Ignored: 300
},
ofxgo.MessageSet{
Name: "INVSTMTMSGSETV1",
Ver: 1,
Url: "https://ofx.example.com/cgi-ofx/exampleofx",
OfxSec: "NONE",
TranspSec: true,
SignonRealm: "Example Trade",
Language: []ofxgo.String{"ENG"},
SyncMode: "LITE",
RespFileER: false,
// Ignored: 300
},
ofxgo.MessageSet{
Name: "SECLISTMSGSETV1",
Ver: 1,
Url: "https://ofx.example.com/cgi-ofx/exampleofx",
OfxSec: "NONE",
TranspSec: true,
SignonRealm: "Example Trade",
Language: []ofxgo.String{"ENG"},
SyncMode: "LITE",
RespFileER: false,
// Ignored: 300
},
ofxgo.MessageSet{
Name: "PROFMSGSETV1",
Ver: 1,
Url: "https://ofx.example.com/cgi-ofx/exampleofx",
OfxSec: "NONE",
TranspSec: true,
SignonRealm: "Example Trade",
Language: []ofxgo.String{"ENG"},
SyncMode: "LITE",
RespFileER: false,
// Ignored: 300
},
},
SignonInfoList: []ofxgo.SignonInfo{
ofxgo.SignonInfo{
SignonRealm: "Example Trade",
Min: 1,
Max: 32,
CharType: "ALPHAORNUMERIC",
CaseSen: false,
Special: true,
Spaces: false,
PinCh: false,
ChgPinFirst: false,
},
},
DtProfUp: *ofxgo.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 := ofxgo.ParseResponse(responseReader)
if err != nil {
t.Fatalf("Unexpected error unmarshalling response: %s\n", err)
}
checkResponsesEqual(t, &expected, response)
}