forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
location_test.go
105 lines (87 loc) · 2.9 KB
/
location_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
package goshopify
import (
"context"
"fmt"
"reflect"
"testing"
"time"
"github.com/jarcoal/httpmock"
)
func TestLocationServiceOp_List(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/locations.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("locations.json")))
products, err := client.Location.List(context.Background(), nil)
if err != nil {
t.Errorf("Location.List returned error: %v", err)
}
created, _ := time.Parse(time.RFC3339, "2018-02-19T16:18:59-05:00")
updated, _ := time.Parse(time.RFC3339, "2018-02-19T16:19:00-05:00")
expected := []Location{{
Id: 4688969785,
Name: "Bajkowa",
Address1: "Bajkowa",
Address2: "",
City: "Olsztyn",
Zip: "10-001",
Country: "PL",
Phone: "12312312",
CreatedAt: created,
UpdatedAt: updated,
CountryCode: "PL",
CountryName: "Poland",
Legacy: false,
Active: true,
AdminGraphqlApiId: "gid://shopify/Location/4688969785",
}}
if !reflect.DeepEqual(products, expected) {
t.Errorf("Location.List returned %+v, expected %+v", products, expected)
}
}
func TestLocationServiceOp_Get(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/locations/4688969785.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("location.json")))
product, err := client.Location.Get(context.Background(), 4688969785, nil)
if err != nil {
t.Errorf("Location.Get returned error: %v", err)
}
created, _ := time.Parse(time.RFC3339, "2018-02-19T16:18:59-05:00")
updated, _ := time.Parse(time.RFC3339, "2018-02-19T16:19:00-05:00")
expected := &Location{
Id: 4688969785,
Name: "Bajkowa",
Address1: "Bajkowa",
Address2: "",
City: "Olsztyn",
Zip: "10-001",
Country: "PL",
Phone: "12312312",
CreatedAt: created,
UpdatedAt: updated,
CountryCode: "PL",
CountryName: "Poland",
Legacy: false,
Active: true,
AdminGraphqlApiId: "gid://shopify/Location/4688969785",
}
if !reflect.DeepEqual(product, expected) {
t.Errorf("Location.Get returned %+v, expected %+v", product, expected)
}
}
func TestLocationServiceOp_Count(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/locations/count.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"count": 3}`))
cnt, err := client.Location.Count(context.Background(), nil)
if err != nil {
t.Errorf("Location.Count returned error: %v", err)
}
expected := 3
if cnt != expected {
t.Errorf("Location.Count returned %d, expected %d", cnt, expected)
}
}