forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart-collection.test.js
More file actions
158 lines (118 loc) · 4.72 KB
/
smart-collection.test.js
File metadata and controls
158 lines (118 loc) · 4.72 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
describe('Shopify#smartCollection', () => {
'use strict';
const expect = require('chai').expect;
const qs = require('qs');
const fixtures = require('./fixtures/smart-collection');
const common = require('./common');
const shopify = common.shopify;
const scope = common.scope;
afterEach(() => expect(scope.isDone()).to.be.true);
it('gets a list of all smart collections (1/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/smart_collections.json').reply(200, output);
return shopify.smartCollection
.list()
.then((data) => expect(data).to.deep.equal(output.smart_collections));
});
it('gets a list of all smart collections (2/2)', () => {
const output = fixtures.res.list;
scope
.get('/admin/smart_collections.json?since_id=482865238')
.reply(200, output);
return shopify.smartCollection
.list({ since_id: 482865238 })
.then((data) => expect(data).to.deep.equal(output.smart_collections));
});
it('gets a count of all smart collections (1/2)', () => {
scope.get('/admin/smart_collections/count.json').reply(200, { count: 1 });
return shopify.smartCollection
.count()
.then((data) => expect(data).to.equal(1));
});
it('gets a count of all smart collections (2/2)', () => {
scope
.get('/admin/smart_collections/count.json?published_status=any')
.reply(200, { count: 1 });
return shopify.smartCollection
.count({ published_status: 'any' })
.then((data) => expect(data).to.equal(1));
});
it('gets a single smart collection by its ID (1/2)', () => {
const output = fixtures.res.get;
scope.get('/admin/smart_collections/482865238.json').reply(200, output);
return shopify.smartCollection
.get(482865238)
.then((data) => expect(data).to.deep.equal(output.smart_collection));
});
it('gets a single smart collection by its ID (2/2)', () => {
const output = fixtures.res.get;
scope
.get('/admin/smart_collections/482865238.json?foo=bar')
.reply(200, output);
return shopify.smartCollection
.get(482865238, { foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.smart_collection));
});
it('creates a new smart collection', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
scope.post('/admin/smart_collections.json', input).reply(201, output);
return shopify.smartCollection
.create(input.smart_collection)
.then((data) => expect(data).to.deep.equal(output.smart_collection));
});
it('updates a smart collection', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;
scope
.put('/admin/smart_collections/482865238.json', input)
.reply(200, output);
return shopify.smartCollection
.update(482865238, input.smart_collection)
.then((data) => expect(data).to.deep.equal(output.smart_collection));
});
it('sets the ordering type of products in a smart collection (1/2)', () => {
const query = { sort_order: 'alpha-desc' };
const search = '?' + qs.stringify(query);
scope
.put('/admin/smart_collections/482865238/order.json' + search, {})
.reply(200, {});
return shopify.smartCollection
.order(482865238, query)
.then((data) => expect(data).to.deep.equal({}));
});
it('sets the ordering type of products in a smart collection (2/2)', () => {
const query = { products: [921728736, 632910392] };
const search = '?' + qs.stringify(query, { arrayFormat: 'brackets' });
scope
.put('/admin/smart_collections/482865238/order.json' + search, {})
.reply(200, {});
return shopify.smartCollection
.order(482865238, query)
.then((data) => expect(data).to.deep.equal({}));
});
it('deletes a smart collection', () => {
scope.delete('/admin/smart_collections/482865238.json').reply(200, {});
return shopify.smartCollection
.delete(482865238)
.then((data) => expect(data).to.deep.equal({}));
});
it('retrieves a list of products in a smart collection (1/2)', () => {
const output = fixtures.res.products;
scope
.get('/admin/smart_collections/482865238/products.json')
.reply(200, output);
return shopify.smartCollection
.products(482865238)
.then((data) => expect(data).to.deep.equal(output.products));
});
it('retrieves a list of products in a smart collection (2/2)', () => {
const output = fixtures.res.products;
scope
.get('/admin/smart_collections/482865238/products.json?only_sorted=all')
.reply(200, output);
return shopify.smartCollection
.products(482865238, { only_sorted: 'all' })
.then((data) => expect(data).to.deep.equal(output.products));
});
});