This commit is contained in:
Aliaksandr Pliutau 2015-12-22 11:31:12 +07:00
parent 0cc2e3fc52
commit 447b062aec
6 changed files with 76 additions and 73 deletions

View File

@ -6,57 +6,58 @@ import (
)
func TestGetAccessToken(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.GetAccessToken()
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
token, err := c.GetAccessToken()
if err != nil || token.Token == "" {
t.Errorf("Token is not returned by GetAccessToken")
}
}
func TestGetAuthorization(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.GetAuthorization("123")
a, err := c.GetAuthorization(testAuthID)
if err == nil {
t.Errorf("Error must be returned for invalid Auth ID")
} else {
fmt.Println(err.Error())
if err != nil || a.ID != testAuthID {
t.Errorf("GetAuthorization failed for ID=" + testAuthID)
}
}
func TestCaptureAuthorization(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.CaptureAuthorization("123", &Amount{Total: "200", Currency: "USD"}, true)
_, err := c.CaptureAuthorization(testAuthID, &Amount{Total: "200", Currency: "USD"}, true)
if err == nil {
t.Errorf("Error must be returned for invalid Auth ID")
t.Errorf("Auth is expired, 400 error must be returned")
} else {
fmt.Println(err.Error())
}
}
func TestVoidAuthorization(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.VoidAuthorization("123")
_, err := c.VoidAuthorization(testAuthID)
if err == nil {
t.Errorf("Error must be returned for invalid Auth ID")
t.Errorf("Auth is expired, 400 error must be returned")
} else {
fmt.Println(err.Error())
}
}
func TestReauthorizeAuthorization(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.ReauthorizeAuthorization("123", &Amount{Total: "200", Currency: "USD"})
_, err := c.ReauthorizeAuthorization(testAuthID, &Amount{Total: "200", Currency: "USD"})
if err == nil {
t.Errorf("Error must be returned for invalid Auth ID")
t.Errorf("Reauthorization not allowed for this product, 500 error must be returned")
} else {
fmt.Println(err.Error())
}

View File

@ -4,9 +4,23 @@ import (
"testing"
)
// All test values are defined here
var testClientID = "AZgwu4yt5Ba0gyTu1dGBH3txHCJbMuFNvrmQxBaQbfDncDiCs6W_rwJD8Ir-0pZrN-_eq7n9zVd8Y-5f"
var testSecret = "EBzA1wRl5t73OMugOieDj_tI3vihfJmGl47ukQT-cpctooIzDu0K7IPESNC0cKodlLSOXzwI8qXSM0rd"
var testAuthID = "2DC87612EK520411B"
var testOrderID = "O-4J082351X3132253H"
var testSaleID = "4CF18861HF410323U"
var testPaymentID = "PAY-5YK922393D847794YKER7MUI"
var testPayerID = "CR87QHB7JTRSC"
func TestNewClient(t *testing.T) {
_, err := NewClient("", "", "")
if err == nil {
t.Errorf("All arguments are required in NewClient()")
}
_, err = NewClient(testClientID, testSecret, APIBaseSandBox)
if err != nil {
t.Errorf("NewClient() must not return error for valid creds")
}
}

View File

@ -76,7 +76,7 @@ func main() {
}
fmt.Println("OK")
refund, err := client.RefundSale("1", &paypalsdk.Amount{Total: "100", Currency: "USD"})
refund, err := client.RefundSale("1", &paypalsdk.Amount{Total: "7.00", Currency: "USD"})
if err == nil {
fmt.Println("DEBUG: RefundID=" + refund.ID)
} else {
@ -100,7 +100,7 @@ func main() {
}
fmt.Println("OK")
auth, err := client.AuthorizeOrder("1", &paypalsdk.Amount{Total: "100", Currency: "USD"})
auth, err := client.AuthorizeOrder("1", &paypalsdk.Amount{Total: "7.00", Currency: "USD"})
if err == nil {
fmt.Println("DEBUG: AuthID=" + auth.ID)
} else {
@ -108,7 +108,7 @@ func main() {
}
fmt.Println("OK")
capture, err := client.CaptureOrder("1", &paypalsdk.Amount{Total: "100", Currency: "USD"}, true, nil)
capture, err := client.CaptureOrder("1", &paypalsdk.Amount{Total: "7.00", Currency: "USD"}, true, nil)
if err == nil {
fmt.Println("DEBUG: CaptureID=" + capture.ID)
} else {

View File

@ -6,49 +6,47 @@ import (
)
func TestGetOrder(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.GetOrder("1")
o, err := c.GetOrder(testOrderID)
if err == nil {
t.Errorf("GetOrder must be failed")
} else {
fmt.Println(err.Error())
if err != nil || o.ID != testOrderID {
t.Errorf("GetOrder failed for ID=" + testOrderID)
}
}
func TestAuthorizeOrder(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.AuthorizeOrder("1", &Amount{Total: "100", Currency: "USD"})
_, err := c.AuthorizeOrder(testOrderID, &Amount{Total: "7.00", Currency: "USD"})
if err == nil {
t.Errorf("AuthorizeOrder must be failed")
t.Errorf("Order is expired, 400 error must be returned")
} else {
fmt.Println(err.Error())
}
}
func TestCaptureOrder(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.CaptureOrder("1", &Amount{Total: "100", Currency: "USD"}, true, nil)
_, err := c.CaptureOrder(testOrderID, &Amount{Total: "100", Currency: "USD"}, true, nil)
if err == nil {
t.Errorf("CaptureOrder must be failed")
t.Errorf("Order is expired, 400 error must be returned")
} else {
fmt.Println(err.Error())
}
}
func TestVoidOrder(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.VoidOrder("1")
_, err := c.VoidOrder(testOrderID)
if err == nil {
t.Errorf("VoidOrder must be failed")
t.Errorf("Order is expired, 400 error must be returned")
} else {
fmt.Println(err.Error())
}

View File

@ -6,63 +6,53 @@ import (
)
func TestCreateDirectPaypalPayment(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
amount := Amount{
Total: "15.1111",
Total: "15.11",
Currency: "USD",
}
_, err := c.CreateDirectPaypalPayment(amount, "http://example.com", "http://example.com", "test payment")
p, err := c.CreateDirectPaypalPayment(amount, "http://example.com", "http://example.com", "test payment")
if err == nil {
t.Errorf("Error must be returned for invalid token")
} else {
fmt.Println(err.Error())
if err != nil || p.ID == "" {
t.Errorf("Test paypal payment is not created")
}
}
func TestGetPayment(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.GetPayment("PAY-TEST-123")
_, err := c.GetPayment(testPaymentID)
if err == nil {
t.Errorf("Error must be returned for invalid ID")
t.Errorf("404 for this payment ID")
} else {
fmt.Println(err.Error())
}
}
func TestGetPayments(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
payments, _ := c.GetPayments()
if len(payments) != 0 {
t.Errorf("0 payments must be returned for unautgorized request")
if len(payments) != 5 {
t.Errorf("5 payments must be returned for GetPayments")
}
}
func TestExecuteApprovedPayment(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.ExecuteApprovedPayment("PAY-6RV70583SB702805EKEYSZ6Y", "7E7MGXCWTTKK2")
_, err := c.ExecuteApprovedPayment(testPaymentID, testPayerID)
if err == nil {
t.Errorf("Error must be returned for invalid token")
t.Errorf("404 for this payment ID")
} else {
fmt.Println(err.Error())
}

View File

@ -6,43 +6,43 @@ import (
)
func TestGetSale(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.GetSale("1")
_, err := c.GetSale(testSaleID)
if err == nil {
t.Errorf("GetSale must be failed")
t.Errorf("404 must be returned for ID=" + testSaleID)
} else {
fmt.Println(err.Error())
}
}
func TestRefundSale(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.RefundSale("1", nil)
_, err := c.RefundSale(testSaleID, nil)
if err == nil {
t.Errorf("RefundSale must be failed")
t.Errorf("404 must be returned for ID=" + testSaleID)
} else {
fmt.Println(err.Error())
}
_, err = c.RefundSale("1", &Amount{Total: "100", Currency: "USD"})
_, err = c.RefundSale(testSaleID, &Amount{Total: "7.00", Currency: "USD"})
if err == nil {
t.Errorf("RefundSale must be failed")
t.Errorf("404 must be returned for ID=" + testSaleID)
} else {
fmt.Println(err.Error())
}
}
func TestGetRefund(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
_, err := c.GetRefund("1")
if err == nil {
t.Errorf("GetRefund must be failed")
t.Errorf("404 must be returned for ID=" + testSaleID)
} else {
fmt.Println(err.Error())
}