-
Notifications
You must be signed in to change notification settings - Fork 44
/
shipping_addresses_test.go
111 lines (96 loc) · 3.29 KB
/
shipping_addresses_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
package recurly_test
import (
"context"
"encoding/xml"
"net/http"
"testing"
"github.com/blacklightcms/recurly"
"github.com/google/go-cmp/cmp"
)
func TestShippingAddresses_ListAccount(t *testing.T) {
client, s := recurly.NewTestServer()
defer s.Close()
var invocations int
s.HandleFunc("GET", "/v2/accounts/1/shipping_addresses", func(w http.ResponseWriter, r *http.Request) {
invocations++
w.WriteHeader(http.StatusOK)
w.Write(MustOpenFile("shipping_addresses.xml"))
}, t)
pager := client.ShippingAddresses.ListAccount("1", nil)
for pager.Next() {
var addresses []recurly.ShippingAddress
if err := pager.Fetch(context.Background(), &addresses); err != nil {
t.Fatal(err)
} else if !s.Invoked {
t.Fatal("expected s to be invoked")
} else if diff := cmp.Diff(addresses, []recurly.ShippingAddress{*NewTestShippingAddress()}); diff != "" {
t.Fatal(diff)
}
}
if invocations != 1 {
t.Fatalf("unexpected number of invocations: %d", invocations)
}
}
func TestShippingAddresses_Create(t *testing.T) {
client, s := recurly.NewTestServer()
defer s.Close()
s.HandleFunc("POST", "/v2/accounts/1/shipping_addresses", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
w.Write(MustOpenFile("shipping_address.xml"))
}, t)
if a, err := client.ShippingAddresses.Create(context.Background(), "1", recurly.ShippingAddress{}); !s.Invoked {
t.Fatal("expected fn invocation")
} else if err != nil {
t.Fatal(err)
} else if diff := cmp.Diff(a, NewTestShippingAddress()); diff != "" {
t.Fatal(diff)
}
}
func TestShippingAddresses_Update(t *testing.T) {
client, s := recurly.NewTestServer()
defer s.Close()
s.HandleFunc("PUT", "/v2/accounts/1/shipping_addresses/2438622711411416831", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(MustOpenFile("shipping_address.xml"))
}, t)
if a, err := client.ShippingAddresses.Update(context.Background(), "1", 2438622711411416831, recurly.ShippingAddress{}); !s.Invoked {
t.Fatal("expected fn invocation")
} else if err != nil {
t.Fatal(err)
} else if diff := cmp.Diff(a, NewTestShippingAddress()); diff != "" {
t.Fatal(diff)
}
}
func TestShippingAddresses_Delete(t *testing.T) {
client, s := recurly.NewTestServer()
defer s.Close()
s.HandleFunc("DELETE", "/v2/accounts/1/shipping_addresses/2438622711411416831", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}, t)
if err := client.ShippingAddresses.Delete(context.Background(), "1", 2438622711411416831); !s.Invoked {
t.Fatal("expected fn invocation")
} else if err != nil {
t.Fatal(err)
}
}
// Returns a ShippingAddress corresponding to testdata/shipping_address.xml.
func NewTestShippingAddress() *recurly.ShippingAddress {
return &recurly.ShippingAddress{
XMLName: xml.Name{Local: "shipping_address"},
ID: 2438622711411416831,
Nickname: "Work",
FirstName: "Verena",
LastName: "Example",
Company: "Recurly Inc",
Email: "[email protected]",
Address: "123 Main St.",
Address2: "Suite 101",
City: "San Francisco",
State: "CA",
Zip: "94105",
Country: "US",
Phone: "555-222-1212",
CreatedAt: recurly.NewTime(MustParseTime("2018-03-19T15:48:00Z")),
UpdatedAt: recurly.NewTime(MustParseTime("2018-03-19T15:48:00Z")),
}
}