forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer_address_test.go
167 lines (129 loc) · 5.34 KB
/
customer_address_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package goshopify
import (
"context"
"fmt"
"testing"
"github.com/jarcoal/httpmock"
)
func verifyAddress(t *testing.T, address CustomerAddress) {
expectedId := uint64(1)
if address.Id != expectedId {
t.Errorf("CustomerAddress.Id returned %+v, expected %+v", address.Id, expectedId)
}
expectedCustomerId := uint64(1)
if address.CustomerId != expectedCustomerId {
t.Errorf("CustomerAddress.CustomerId returned %+v, expected %+v", address.CustomerId, expectedCustomerId)
}
expectedFirstName := "Test"
if address.FirstName != expectedFirstName {
t.Errorf("CustomerAddress.FirstName returned %+v, expected %+v", address.FirstName, expectedFirstName)
}
expectedLastName := "Citizen"
if address.LastName != expectedLastName {
t.Errorf("CustomerAddress.LastName returned %+v, expected %+v", address.LastName, expectedLastName)
}
expectedCompany := "TestCo"
if address.Company != expectedCompany {
t.Errorf("CustomerAddress.Company returned %+v, expected %+v", address.Company, expectedCompany)
}
expectedAddress1 := "1 Smith St"
if address.Address1 != expectedAddress1 {
t.Errorf("CustomerAddress.Address1 returned %+v, expected %+v", address.Address1, expectedAddress1)
}
expectedAddress2 := ""
if address.Address2 != expectedAddress2 {
t.Errorf("CustomerAddress.Address2 returned %+v, expected %+v", address.Address2, expectedAddress2)
}
expectedCity := "BRISBANE"
if address.City != expectedCity {
t.Errorf("CustomerAddress.City returned %+v, expected %+v", address.City, expectedCity)
}
expectedProvince := "Queensland"
if address.Province != expectedProvince {
t.Errorf("CustomerAddress.Province returned %+v, expected %+v", address.Province, expectedProvince)
}
expectedCountry := "Australia"
if address.Country != expectedCountry {
t.Errorf("CustomerAddress.Country returned %+v, expected %+v", address.Country, expectedCountry)
}
expectedZip := "4000"
if address.Zip != expectedZip {
t.Errorf("CustomerAddress.Zip returned %+v, expected %+v", address.Zip, expectedZip)
}
expectedPhone := "1111 111 111"
if address.Phone != expectedPhone {
t.Errorf("CustomerAddress.Phone returned %+v, expected %+v", address.Phone, expectedPhone)
}
expectedName := "Test Citizen"
if address.Name != expectedName {
t.Errorf("CustomerAddress.Name returned %+v, expected %+v", address.Name, expectedName)
}
expectedProvinceCode := "QLD"
if address.ProvinceCode != expectedProvinceCode {
t.Errorf("CustomerAddress.ProvinceCode returned %+v, expected %+v", address.ProvinceCode, expectedProvinceCode)
}
expectedCountryCode := "AU"
if address.CountryCode != expectedCountryCode {
t.Errorf("CustomerAddress.CountryCode returned %+v, expected %+v", address.CountryCode, expectedCountryCode)
}
expectedCountryName := "Australia"
if address.CountryName != expectedCountryName {
t.Errorf("CustomerAddress.CountryName returned %+v, expected %+v", address.CountryName, expectedCountryName)
}
expectedDefault := true
if address.Default != expectedDefault {
t.Errorf("CustomerAddress.Default returned %+v, expected %+v", address.Default, expectedDefault)
}
}
func TestList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses.json", client.pathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_addresses.json")))
addresses, err := client.CustomerAddress.List(context.Background(), 1, nil)
if err != nil {
t.Errorf("CustomerAddress.List returned error: %v", err)
}
if len(addresses) != 2 {
t.Errorf("CustomerAddress.List got %v addresses, expected 2", len(addresses))
}
verifyAddress(t, addresses[0])
}
func TestGet(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses/1.json", client.pathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_address.json")))
address, err := client.CustomerAddress.Get(context.Background(), 1, 1, nil)
if err != nil {
t.Errorf("CustomerAddress.Get returned error: %v", err)
}
verifyAddress(t, *address)
}
func TestCreate(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses.json", client.pathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_address.json")))
address, err := client.CustomerAddress.Create(context.Background(), 1, CustomerAddress{})
if err != nil {
t.Errorf("CustomerAddress.Create returned error: %v", err)
}
verifyAddress(t, *address)
}
func TestUpdate(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses/1.json", client.pathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_address.json")))
address, err := client.CustomerAddress.Update(context.Background(), 1, CustomerAddress{Id: 1})
if err != nil {
t.Errorf("CustomerAddress.Update returned error: %v", err)
}
verifyAddress(t, *address)
}
func TestDelete(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses/1.json", client.pathPrefix), httpmock.NewStringResponder(200, "{}"))
err := client.CustomerAddress.Delete(context.Background(), 1, 1)
if err != nil {
t.Errorf("CustomerAddress.Update returned error: %v", err)
}
}