paypale/auth_test.go

69 lines
1.6 KiB
Go
Raw Normal View History

2015-10-15 10:47:36 +02:00
package paypalsdk
import (
2015-12-17 08:50:25 +01:00
"fmt"
2015-10-30 08:02:32 +01:00
"testing"
2015-10-15 10:47:36 +02:00
)
2015-10-30 08:02:32 +01:00
func TestGetAccessToken(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
token, err := c.GetAccessToken()
if err != nil || token.Token == "" {
t.Errorf("Token is not returned by GetAccessToken")
}
2015-10-16 12:00:57 +02:00
}
func TestGetAuthorization(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-12-22 05:31:12 +01:00
a, err := c.GetAuthorization(testAuthID)
if err != nil || a.ID != testAuthID {
t.Errorf("GetAuthorization failed for ID=" + testAuthID)
}
2015-12-22 06:09:57 +01:00
a, err = c.GetAuthorization(testFakeAuthID)
if err == nil {
t.Errorf("GetAuthorization must return error for ID=" + testFakeAuthID)
}
}
func TestCaptureAuthorization(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-12-22 05:31:12 +01:00
_, err := c.CaptureAuthorization(testAuthID, &Amount{Total: "200", Currency: "USD"}, true)
if err == nil {
2015-12-22 05:31:12 +01:00
t.Errorf("Auth is expired, 400 error must be returned")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
}
}
func TestVoidAuthorization(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-12-22 05:31:12 +01:00
_, err := c.VoidAuthorization(testAuthID)
if err == nil {
2015-12-22 05:31:12 +01:00
t.Errorf("Auth is expired, 400 error must be returned")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
}
}
func TestReauthorizeAuthorization(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-12-22 05:31:12 +01:00
_, err := c.ReauthorizeAuthorization(testAuthID, &Amount{Total: "200", Currency: "USD"})
if err == nil {
2015-12-22 05:31:12 +01:00
t.Errorf("Reauthorization not allowed for this product, 500 error must be returned")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
}
}