2020-03-31 00:19:18 -04:00
|
|
|
package ofxgo
|
2017-03-31 05:18:31 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMarshalAcctInfoRequest(t *testing.T) {
|
|
|
|
var expectedString string = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
|
<?OFX OFXHEADER="200" VERSION="203" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
|
|
|
|
<OFX>
|
|
|
|
<SIGNONMSGSRQV1>
|
|
|
|
<SONRQ>
|
|
|
|
<DTCLIENT>20160115112300.000[-5:EST]</DTCLIENT>
|
|
|
|
<USERID>myusername</USERID>
|
|
|
|
<USERPASS>Pa$$word</USERPASS>
|
|
|
|
<LANGUAGE>ENG</LANGUAGE>
|
|
|
|
<FI>
|
|
|
|
<ORG>BNK</ORG>
|
|
|
|
<FID>1987</FID>
|
|
|
|
</FI>
|
|
|
|
<APPID>OFXGO</APPID>
|
|
|
|
<APPVER>0001</APPVER>
|
|
|
|
</SONRQ>
|
|
|
|
</SIGNONMSGSRQV1>
|
|
|
|
<SIGNUPMSGSRQV1>
|
|
|
|
<ACCTINFOTRNRQ>
|
|
|
|
<TRNUID>e3ad9bda-38fa-4e5b-8099-1bd567ddef7a</TRNUID>
|
|
|
|
<ACCTINFORQ>
|
|
|
|
<DTACCTUP>20151221182945.000[-5:EST]</DTACCTUP>
|
|
|
|
</ACCTINFORQ>
|
|
|
|
</ACCTINFOTRNRQ>
|
|
|
|
</SIGNUPMSGSRQV1>
|
|
|
|
</OFX>`
|
|
|
|
|
|
|
|
EST := time.FixedZone("EST", -5*60*60)
|
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
var client = BasicClient{
|
2017-04-12 21:40:42 -04:00
|
|
|
AppID: "OFXGO",
|
2017-03-31 05:18:31 -04:00
|
|
|
AppVer: "0001",
|
2020-03-31 00:19:18 -04:00
|
|
|
SpecVersion: OfxVersion203,
|
2017-03-31 05:18:31 -04:00
|
|
|
}
|
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
var request Request
|
2017-04-12 21:40:42 -04:00
|
|
|
request.Signon.UserID = "myusername"
|
2017-03-31 05:18:31 -04:00
|
|
|
request.Signon.UserPass = "Pa$$word"
|
|
|
|
request.Signon.Org = "BNK"
|
|
|
|
request.Signon.Fid = "1987"
|
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
acctInfoRequest := AcctInfoRequest{
|
2017-03-31 05:18:31 -04:00
|
|
|
TrnUID: "e3ad9bda-38fa-4e5b-8099-1bd567ddef7a",
|
2020-03-31 00:19:18 -04:00
|
|
|
DtAcctUp: *NewDate(2015, 12, 21, 18, 29, 45, 0, EST),
|
2017-03-31 05:18:31 -04:00
|
|
|
}
|
|
|
|
request.Signup = append(request.Signup, &acctInfoRequest)
|
|
|
|
|
|
|
|
request.SetClientFields(&client)
|
|
|
|
// Overwrite the DtClient value set by SetClientFields to time.Now()
|
2020-03-31 00:19:18 -04:00
|
|
|
request.Signon.DtClient = *NewDate(2016, 1, 15, 11, 23, 0, 0, EST)
|
2017-03-31 05:18:31 -04:00
|
|
|
|
|
|
|
marshalCheckRequest(t, &request, expectedString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnmarshalAcctInfoResponse(t *testing.T) {
|
|
|
|
responseReader := strings.NewReader(`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
|
<?OFX OFXHEADER="200" VERSION="203" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
|
|
|
|
<OFX>
|
|
|
|
<SIGNONMSGSRSV1>
|
|
|
|
<SONRS>
|
|
|
|
<STATUS>
|
|
|
|
<CODE>0</CODE>
|
|
|
|
<SEVERITY>INFO</SEVERITY>
|
|
|
|
</STATUS>
|
|
|
|
<DTSERVER>20060115112303</DTSERVER>
|
|
|
|
<LANGUAGE>ENG</LANGUAGE>
|
|
|
|
<DTPROFUP>20050221091300</DTPROFUP>
|
|
|
|
<DTACCTUP>20060102160000</DTACCTUP>
|
|
|
|
<FI>
|
|
|
|
<ORG>BNK</ORG>
|
|
|
|
<FID>1987</FID>
|
|
|
|
</FI>
|
|
|
|
</SONRS>
|
|
|
|
</SIGNONMSGSRSV1>
|
|
|
|
<SIGNUPMSGSRSV1>
|
|
|
|
<ACCTINFOTRNRS>
|
|
|
|
<TRNUID>10938754</TRNUID>
|
|
|
|
<STATUS>
|
|
|
|
<CODE>0</CODE>
|
|
|
|
<SEVERITY>INFO</SEVERITY>
|
|
|
|
</STATUS>
|
|
|
|
<ACCTINFORS>
|
|
|
|
<DTACCTUP>20050228</DTACCTUP>
|
|
|
|
<ACCTINFO>
|
|
|
|
<DESC>Personal Checking</DESC>
|
|
|
|
<PHONE>888-222-5827</PHONE>
|
|
|
|
<BANKACCTINFO>
|
|
|
|
<BANKACCTFROM>
|
|
|
|
<BANKID>8367556009</BANKID>
|
|
|
|
<ACCTID>000999847</ACCTID>
|
|
|
|
<ACCTTYPE>MONEYMRKT</ACCTTYPE>
|
|
|
|
</BANKACCTFROM>
|
|
|
|
<SUPTXDL>Y</SUPTXDL>
|
|
|
|
<XFERSRC>Y</XFERSRC>
|
|
|
|
<XFERDEST>Y</XFERDEST>
|
|
|
|
<SVCSTATUS>ACTIVE</SVCSTATUS>
|
|
|
|
</BANKACCTINFO>
|
|
|
|
</ACCTINFO>
|
|
|
|
</ACCTINFORS>
|
|
|
|
</ACCTINFOTRNRS>
|
|
|
|
</SIGNUPMSGSRSV1>
|
|
|
|
</OFX>`)
|
2020-03-31 00:19:18 -04:00
|
|
|
var expected Response
|
2017-03-31 05:18:31 -04:00
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
expected.Version = OfxVersion203
|
2017-03-31 05:18:31 -04:00
|
|
|
expected.Signon.Status.Code = 0
|
|
|
|
expected.Signon.Status.Severity = "INFO"
|
2020-03-31 00:19:18 -04:00
|
|
|
expected.Signon.DtServer = *NewDateGMT(2006, 1, 15, 11, 23, 03, 0)
|
2017-03-31 05:18:31 -04:00
|
|
|
expected.Signon.Language = "ENG"
|
2020-03-31 00:19:18 -04:00
|
|
|
expected.Signon.DtProfUp = NewDateGMT(2005, 2, 21, 9, 13, 0, 0)
|
|
|
|
expected.Signon.DtAcctUp = NewDateGMT(2006, 1, 2, 16, 0, 0, 0)
|
2017-03-31 05:18:31 -04:00
|
|
|
expected.Signon.Org = "BNK"
|
|
|
|
expected.Signon.Fid = "1987"
|
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
bankacctinfo := BankAcctInfo{
|
|
|
|
BankAcctFrom: BankAcct{
|
2017-04-12 21:40:42 -04:00
|
|
|
BankID: "8367556009",
|
|
|
|
AcctID: "000999847",
|
2020-03-31 00:19:18 -04:00
|
|
|
AcctType: AcctTypeMoneyMrkt,
|
2017-03-31 05:18:31 -04:00
|
|
|
},
|
|
|
|
SupTxDl: true,
|
|
|
|
XferSrc: true,
|
|
|
|
XferDest: true,
|
2020-03-31 00:19:18 -04:00
|
|
|
SvcStatus: SvcStatusActive,
|
2017-03-31 05:18:31 -04:00
|
|
|
}
|
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
acctInfoResponse := AcctInfoResponse{
|
2017-03-31 05:18:31 -04:00
|
|
|
TrnUID: "10938754",
|
2020-03-31 00:19:18 -04:00
|
|
|
Status: Status{
|
2017-03-31 05:18:31 -04:00
|
|
|
Code: 0,
|
|
|
|
Severity: "INFO",
|
|
|
|
},
|
2020-03-31 00:19:18 -04:00
|
|
|
DtAcctUp: *NewDateGMT(2005, 2, 28, 0, 0, 0, 0),
|
|
|
|
AcctInfo: []AcctInfo{{
|
2017-03-31 05:18:31 -04:00
|
|
|
Desc: "Personal Checking",
|
|
|
|
Phone: "888-222-5827",
|
|
|
|
BankAcctInfo: &bankacctinfo,
|
|
|
|
}},
|
|
|
|
}
|
2017-03-31 11:54:43 -04:00
|
|
|
expected.Signup = append(expected.Signup, &acctInfoResponse)
|
2017-03-31 05:18:31 -04:00
|
|
|
|
2020-03-31 00:19:18 -04:00
|
|
|
response, err := ParseResponse(responseReader)
|
2017-03-31 05:18:31 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error unmarshalling response: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
checkResponsesEqual(t, &expected, response)
|
2019-03-01 22:40:49 -05:00
|
|
|
checkResponseRoundTrip(t, response)
|
2017-03-31 05:18:31 -04:00
|
|
|
}
|