forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.test.js
More file actions
180 lines (134 loc) · 5.15 KB
/
product.test.js
File metadata and controls
180 lines (134 loc) · 5.15 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
describe('Shopify#product', () => {
'use strict';
const expect = require('chai').expect;
const fixtures = require('./fixtures/product');
const common = require('./common');
const shopify = common.shopify;
const shopifyWithPresenmentOption = common.shopifyWithPresentmentOption;
const standardScope = common.scope;
const presentmentApiScope = common.presentmentApiScope;
afterEach(() => {
expect(presentmentApiScope.isDone()).to.be.true;
expect(standardScope.isDone()).to.be.true;
});
it('gets a list of all products (1/4)', () => {
const output = fixtures.res.list;
standardScope.get('/admin/products.json').reply(200, output);
return shopify.product
.list()
.then((data) => expect(data).to.deep.equal(output.products));
});
it('gets a list of all products (2/4)', () => {
const output = fixtures.res.list;
standardScope
.get('/admin/products.json?published_status=any')
.reply(200, output);
return shopify.product
.list({ published_status: 'any' })
.then((data) => expect(data).to.deep.equal(output.products));
});
it('gets a list of all products (3/4)', () => {
const output = fixtures.res.list;
presentmentApiScope.get('/admin/products.json').reply(200, output);
return shopifyWithPresenmentOption.product
.list()
.then((data) => expect(data).to.deep.equal(output.products));
});
it('gets a list of all products (4/4)', () => {
const output = fixtures.res.list;
presentmentApiScope
.get('/admin/products.json?published_status=any')
.reply(200, output);
return shopifyWithPresenmentOption.product
.list({ published_status: 'any' })
.then((data) => expect(data).to.deep.equal(output.products));
});
it('gets a count of all products (1/2)', () => {
standardScope.get('/admin/products/count.json').reply(200, { count: 2 });
return shopify.product.count().then((data) => expect(data).to.equal(2));
});
it('gets a count of all products (2/2)', () => {
standardScope
.get('/admin/products/count.json?published_status=any')
.reply(200, { count: 2 });
return shopify.product
.count({ published_status: 'any' })
.then((data) => expect(data).to.equal(2));
});
it('gets a single product by its ID (1/4)', () => {
const output = fixtures.res.get;
standardScope.get('/admin/products/632910392.json').reply(200, output);
return shopify.product
.get(632910392)
.then((data) => expect(data).to.deep.equal(output.product));
});
it('gets a single product by its ID (2/4)', () => {
const output = fixtures.res.get;
standardScope
.get('/admin/products/632910392.json?foo=bar')
.reply(200, output);
return shopify.product
.get(632910392, { foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.product));
});
it('gets a single product by its ID (3/4)', () => {
const output = fixtures.res.get;
presentmentApiScope
.get('/admin/products/632910392.json')
.reply(200, output);
return shopifyWithPresenmentOption.product
.get(632910392)
.then((data) => expect(data).to.deep.equal(output.product));
});
it('gets a single product by its ID (4/4)', () => {
const output = fixtures.res.get;
presentmentApiScope
.get('/admin/products/632910392.json?foo=bar')
.reply(200, output);
return shopifyWithPresenmentOption.product
.get(632910392, { foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.product));
});
it('creates a new product', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
standardScope.post('/admin/products.json', input).reply(201, output);
return shopify.product
.create(input.product)
.then((data) => expect(data).to.deep.equal(output.product));
});
it('creates a new product with presentment option', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
presentmentApiScope.post('/admin/products.json', input).reply(201, output);
return shopifyWithPresenmentOption.product
.create(input.product)
.then((data) => expect(data).to.deep.equal(output.product));
});
it('updates a product', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;
standardScope
.put('/admin/products/632910392.json', input)
.reply(200, output);
return shopify.product
.update(632910392, input.product)
.then((data) => expect(data).to.deep.equal(output.product));
});
it('updates a product with presentment option', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;
presentmentApiScope
.put('/admin/products/632910392.json', input)
.reply(200, output);
return shopifyWithPresenmentOption.product
.update(632910392, input.product)
.then((data) => expect(data).to.deep.equal(output.product));
});
it('deletes a product', () => {
standardScope.delete('/admin/products/632910392.json').reply(200, {});
return shopify.product
.delete(632910392)
.then((data) => expect(data).to.deep.equal({}));
});
});