forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_integration_test.go
128 lines (116 loc) · 3.16 KB
/
address_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// +build integration
package braintree
import (
"context"
"testing"
)
func TestAddress(t *testing.T) {
t.Parallel()
ctx := context.Background()
customer, err := testGateway.Customer().Create(ctx, &CustomerRequest{
FirstName: "Jenna",
LastName: "Smith",
})
if err != nil {
t.Fatal(err)
}
if customer.Id == "" {
t.Fatal("invalid customer id")
}
addr := &AddressRequest{
FirstName: "Jenna",
LastName: "Smith",
Company: "Braintree",
StreetAddress: "1 E Main St",
ExtendedAddress: "Suite 403",
Locality: "Chicago",
Region: "Illinois",
PostalCode: "60622",
CountryCodeAlpha2: "US",
CountryCodeAlpha3: "USA",
CountryCodeNumeric: "840",
CountryName: "United States of America",
}
addr2, err := testGateway.Address().Create(ctx, customer.Id, addr)
if err != nil {
t.Fatal(err)
}
t.Logf("%+v\n", addr)
t.Logf("%+v\n", addr2)
validateAddr(t, addr2, addr, customer)
addr3 := &AddressRequest{
FirstName: "Al",
LastName: "Fredidandes",
Company: "Paypal",
StreetAddress: "1 W Main St",
ExtendedAddress: "Suite 402",
Locality: "Montreal",
Region: "Quebec",
PostalCode: "H1A",
CountryCodeAlpha2: "CA",
CountryCodeAlpha3: "CAN",
CountryCodeNumeric: "124",
CountryName: "Canada",
}
addr4, err := testGateway.Address().Update(ctx, customer.Id, addr2.Id, addr3)
if err != nil {
t.Fatal(err)
}
t.Logf("%+v\n", addr3)
t.Logf("%+v\n", addr4)
validateAddr(t, addr4, addr3, customer)
err = testGateway.Address().Delete(ctx, customer.Id, addr2.Id)
if err != nil {
t.Fatal(err)
}
}
func validateAddr(t *testing.T, addr *Address, addrRequest *AddressRequest, customer *Customer) {
if addr.Id == "" {
t.Fatal("generated id is empty")
}
if addr.CustomerId != customer.Id {
t.Fatal("customer ids do not match")
}
if addr.FirstName != addrRequest.FirstName {
t.Fatal("first names do not match")
}
if addr.LastName != addrRequest.LastName {
t.Fatal("last names do not match")
}
if addr.Company != addrRequest.Company {
t.Fatal("companies do not match")
}
if addr.StreetAddress != addrRequest.StreetAddress {
t.Fatal("street addresses do not match")
}
if addr.ExtendedAddress != addrRequest.ExtendedAddress {
t.Fatal("extended addresses do not match")
}
if addr.Locality != addrRequest.Locality {
t.Fatal("localities do not match")
}
if addr.Region != addrRequest.Region {
t.Fatal("regions do not match")
}
if addr.PostalCode != addrRequest.PostalCode {
t.Fatal("postal codes do not match")
}
if addr.CountryCodeAlpha2 != addrRequest.CountryCodeAlpha2 {
t.Fatal("country alpha2 codes do not match")
}
if addr.CountryCodeAlpha3 != addrRequest.CountryCodeAlpha3 {
t.Fatal("country alpha3 codes do not match")
}
if addr.CountryCodeNumeric != addrRequest.CountryCodeNumeric {
t.Fatal("country numeric codes do not match")
}
if addr.CountryName != addrRequest.CountryName {
t.Fatal("country names do not match")
}
if addr.CreatedAt == nil {
t.Fatal("generated created at is empty")
}
if addr.UpdatedAt == nil {
t.Fatal("generated updated at is empty")
}
}