-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
204 lines (167 loc) · 5.4 KB
/
index.test.js
File metadata and controls
204 lines (167 loc) · 5.4 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
const { Store, Admin } = require("./dist/index.cjs.js");
describe("Store", () => {
let store;
beforeEach(() => {
store = new Store("my-shop");
});
test("constructor appends .myshopify.com and https", () => {
expect(String(store)).toBe("https://my-shop.myshopify.com");
});
test("constructor preserves existing domain", () => {
const s = new Store("my-shop.example.com");
expect(String(s)).toBe("https://my-shop.example.com");
});
test("constructor preserves existing protocol", () => {
const s = new Store("http://my-shop.example.com");
expect(String(s)).toBe("http://my-shop.example.com");
});
test("constructor throws when shop is empty", () => {
expect(() => new Store("")).toThrow("shop required");
expect(() => new Store(null)).toThrow("shop required");
});
test("product returns URL with id", () => {
expect(String(store.product(123))).toBe(
"https://my-shop.myshopify.com/products/123"
);
});
test("product with query params", () => {
expect(String(store.product(123, { limit: 10 }))).toBe(
"https://my-shop.myshopify.com/products/123?limit=10"
);
});
test("product throws when id is empty", () => {
expect(() => store.product("")).toThrow("id required");
});
test("products returns URL", () => {
expect(String(store.products())).toBe(
"https://my-shop.myshopify.com/products"
);
});
test("products with query params", () => {
expect(String(store.products({ page: 2 }))).toBe(
"https://my-shop.myshopify.com/products?page=2"
);
});
test("collection returns URL with id", () => {
expect(String(store.collection("summer"))).toBe(
"https://my-shop.myshopify.com/collections/summer"
);
});
test("collections returns URL", () => {
expect(String(store.collections())).toBe(
"https://my-shop.myshopify.com/collections"
);
});
test("page returns URL", () => {
expect(store.page("about")).toBe(
"https://my-shop.myshopify.com/pages/about"
);
});
test("blogs returns URL", () => {
expect(String(store.blogs("news"))).toBe(
"https://my-shop.myshopify.com/blogs/news"
);
});
test("blogs throws when category is empty", () => {
expect(() => store.blogs("")).toThrow("category required");
});
test("blogs entry returns URL", () => {
expect(store.blogs("news").entry("hello-world")).toBe(
"https://my-shop.myshopify.com/blogs/news/hello-world"
);
});
});
describe("Admin", () => {
let admin;
beforeEach(() => {
admin = new Admin("my-shop");
});
test("constructor appends /admin", () => {
expect(String(admin)).toBe("https://my-shop.myshopify.com/admin");
});
test("order returns URL with id", () => {
expect(String(admin.order(456))).toBe(
"https://my-shop.myshopify.com/admin/orders/456"
);
});
test("order shipping_labels returns URL", () => {
expect(String(admin.order(456).shippingLabels())).toBe(
"https://my-shop.myshopify.com/admin/orders/456/shipping_labels"
);
});
test("order shipping_labels new returns URL", () => {
expect(admin.order(456).shippingLabels().new()).toBe(
"https://my-shop.myshopify.com/admin/orders/456/shipping_labels/new"
);
});
test("orders returns URL", () => {
expect(String(admin.orders())).toBe(
"https://my-shop.myshopify.com/admin/orders"
);
});
test("customer returns URL with id", () => {
expect(String(admin.customer(789))).toBe(
"https://my-shop.myshopify.com/admin/customers/789"
);
});
test("customers returns URL", () => {
expect(String(admin.customers())).toBe(
"https://my-shop.myshopify.com/admin/customers"
);
});
test("product returns URL with id", () => {
expect(String(admin.product(101))).toBe(
"https://my-shop.myshopify.com/admin/products/101"
);
});
test("product variants returns URL", () => {
expect(admin.product(101).variants(5)).toBe(
"https://my-shop.myshopify.com/admin/products/101/variants/5"
);
});
test("products returns URL", () => {
expect(String(admin.products())).toBe(
"https://my-shop.myshopify.com/admin/products"
);
});
test("products inventory returns URL", () => {
expect(admin.products().inventory()).toBe(
"https://my-shop.myshopify.com/admin/products/inventory"
);
});
test("draft_order returns URL", () => {
expect(String(admin.draftOrder(10))).toBe(
"https://my-shop.myshopify.com/admin/draft_orders/10"
);
});
test("draft_order duplicate returns URL", () => {
expect(admin.draftOrder(10).duplicate()).toBe(
"https://my-shop.myshopify.com/admin/draft_orders/10/duplicate"
);
});
test("draft_orders returns URL", () => {
expect(String(admin.draftOrders())).toBe(
"https://my-shop.myshopify.com/admin/draft_orders"
);
});
test("draft_orders new returns URL", () => {
expect(admin.draftOrders().new()).toBe(
"https://my-shop.myshopify.com/admin/draft_orders/new"
);
});
test("themes returns URL", () => {
expect(admin.themes()).toBe(
"https://my-shop.myshopify.com/admin/themes"
);
});
test("theme returns URL with id", () => {
expect(String(admin.theme(55))).toBe(
"https://my-shop.myshopify.com/admin/themes/55"
);
});
test("theme editor returns URL", () => {
expect(admin.theme(55).editor()).toBe(
"https://my-shop.myshopify.com/admin/themes/55/editor"
);
});
});