forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer_apple_pay_integration_test.go
60 lines (50 loc) · 1.87 KB
/
customer_apple_pay_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// +build integration
package braintree
import (
"context"
"reflect"
"testing"
"github.com/dietdoctor/braintree-go/testhelpers"
)
func TestCustomerApplePayCard(t *testing.T) {
t.Parallel()
ctx := context.Background()
customer, err := testGateway.Customer().Create(ctx, &CustomerRequest{})
if err != nil {
t.Fatal(err)
}
paymentMethod, err := testGateway.PaymentMethod().Create(ctx, &PaymentMethodRequest{
CustomerId: customer.Id,
PaymentMethodNonce: FakeNonceApplePayVisa,
})
if err != nil {
t.Fatal(err)
}
applePayCard := paymentMethod.(*ApplePayCard)
customerFound, err := testGateway.Customer().Find(ctx, customer.Id)
if err != nil {
t.Fatal(err)
}
if customerFound.ApplePayCards == nil || len(customerFound.ApplePayCards.ApplePayCard) != 1 {
t.Fatalf("Customer %#v expected to have one ApplePayCard", customerFound)
}
if !reflect.DeepEqual(customerFound.ApplePayCards.ApplePayCard[0], applePayCard) {
t.Fatalf("Got Customer %#v ApplePayCard %#v, want %#v", customerFound, customerFound.ApplePayCards.ApplePayCard[0], applePayCard)
}
wantNonceCardType := "Apple Pay - Visa"
if applePayCard.CardType != wantNonceCardType {
t.Errorf("Got ApplePayCard.CardType %v, want %v", applePayCard.CardType, wantNonceCardType)
}
if !testhelpers.ValidExpiryMonth(applePayCard.ExpirationMonth) {
t.Errorf("ApplePayCard.ExpirationMonth (%s) does not conform expected value", applePayCard.ExpirationMonth)
}
if !testhelpers.ValidExpiryYear(applePayCard.ExpirationYear) {
t.Errorf("ApplePayCard.ExpirationYear (%s) does not conform expected value", applePayCard.ExpirationYear)
}
if !testhelpers.ValidBIN(applePayCard.BIN) {
t.Errorf("ApplePayCard.BIN (%s) does not conform expected value", applePayCard.BIN)
}
if !testhelpers.ValidLast4(applePayCard.Last4) {
t.Errorf("ApplePayCard.Last4 (%s) does not conform expected value", applePayCard.Last4)
}
}