mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package paypalsdk
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestStoreCreditCard(t *testing.T) {
|
|
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
|
c.GetAccessToken()
|
|
|
|
r1, e1 := c.StoreCreditCard(CreditCard{})
|
|
if e1 == nil || r1 != nil {
|
|
t.Errorf("Error is expected for invalid CC")
|
|
}
|
|
|
|
r2, e2 := c.StoreCreditCard(CreditCard{
|
|
Number: "4417119669820331",
|
|
Type: "visa",
|
|
ExpireMonth: "11",
|
|
ExpireYear: "2020",
|
|
CVV2: "874",
|
|
FirstName: "Foo",
|
|
LastName: "Bar",
|
|
})
|
|
if e2 != nil || r2 == nil {
|
|
t.Errorf("200 code expected for valid CC card. Error: %v", e2)
|
|
}
|
|
}
|
|
|
|
func TestDeleteCreditCard(t *testing.T) {
|
|
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
|
c.GetAccessToken()
|
|
|
|
r1, e1 := c.DeleteCreditCard("")
|
|
if e1 == nil || r1 != nil {
|
|
t.Errorf("Error is expected for invalid CC ID")
|
|
}
|
|
}
|
|
|
|
func TestGetCreditCard(t *testing.T) {
|
|
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
|
c.GetAccessToken()
|
|
|
|
r1, e1 := c.GetCreditCard("BBGGG")
|
|
if e1 == nil || r1 != nil {
|
|
t.Errorf("Error is expected for invalid CC, got CC %v", r1)
|
|
}
|
|
}
|
|
|
|
func TestGetCreditCards(t *testing.T) {
|
|
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
|
c.GetAccessToken()
|
|
|
|
r1, e1 := c.GetCreditCards(nil)
|
|
if e1 != nil || r1 == nil {
|
|
t.Errorf("200 code expected. Error: %v", e1)
|
|
}
|
|
if r1.TotalItems < 1 {
|
|
t.Errorf("Expected >0 CCs, got %d", r1.TotalItems)
|
|
}
|
|
if r1.TotalPages < 1 {
|
|
t.Errorf("Expected >0 CCs page")
|
|
}
|
|
|
|
r2, e2 := c.GetCreditCards(&CreditCardsFilter{
|
|
Page: 2,
|
|
PageSize: 7,
|
|
})
|
|
if e2 != nil || r2 == nil {
|
|
t.Errorf("200 code expected. Error: %v", e2)
|
|
}
|
|
if r2.TotalItems < 1 {
|
|
t.Errorf("Expected >0 CCs, got %d", r2.TotalItems)
|
|
}
|
|
if r2.TotalPages < 1 {
|
|
t.Errorf("Expected >0 CCs page")
|
|
}
|
|
}
|
|
|
|
func TestPatchCreditCard(t *testing.T) {
|
|
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
|
c.GetAccessToken()
|
|
|
|
r1, e1 := c.PatchCreditCard(testCardID, nil)
|
|
if e1 == nil || r1 != nil {
|
|
t.Errorf("Error is expected for empty update info")
|
|
}
|
|
}
|