forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfulfillment.test.js
More file actions
181 lines (137 loc) · 5.35 KB
/
fulfillment.test.js
File metadata and controls
181 lines (137 loc) · 5.35 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
describe('Shopify#fulfillment', () => {
'use strict';
const expect = require('chai').expect;
const fixtures = require('./fixtures/fulfillment');
const common = require('./common');
const Shopify = require('..');
const accessToken = common.accessToken;
const apiVersion = common.apiVersion;
const scope = common.scope;
const shopify = common.shopify;
const shopName = common.shopName;
afterEach(() => expect(scope.isDone()).to.be.true);
it('gets a list of all fulfillments for an order (1/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/orders/450789469/fulfillments.json').reply(200, output);
return shopify.fulfillment
.list(450789469)
.then((data) => expect(data).to.deep.equal(output.fulfillments));
});
it('gets a list of all fulfillments for an order (2/2)', () => {
const output = fixtures.res.list;
scope
.get('/admin/orders/450789469/fulfillments.json?since_id=255858045')
.reply(200, output);
return shopify.fulfillment
.list(450789469, { since_id: 255858045 })
.then((data) => expect(data).to.deep.equal(output.fulfillments));
});
it('gets a count of all fulfillments for an order (1/2)', () => {
scope
.get('/admin/orders/450789469/fulfillments/count.json')
.reply(200, { count: 1 });
return shopify.fulfillment
.count(450789469)
.then((data) => expect(data).to.equal(1));
});
it('gets a count of all fulfillments for an order (2/2)', () => {
scope
.get('/admin/orders/450789469/fulfillments/count.json?foo=bar')
.reply(200, { count: 1 });
return shopify.fulfillment
.count(450789469, { foo: 'bar' })
.then((data) => expect(data).to.equal(1));
});
it('gets a single fulfillment by its ID (1/2)', () => {
const output = fixtures.res.get;
scope
.get('/admin/orders/450789469/fulfillments/255858046.json')
.reply(200, output);
return shopify.fulfillment
.get(450789469, 255858046)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('gets a single fulfillment by its ID (2/2)', () => {
const output = fixtures.res.get;
scope
.get('/admin/orders/450789469/fulfillments/255858046.json?foo=bar')
.reply(200, output);
return shopify.fulfillment
.get(450789469, 255858046, { foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('creates a fulfillment for an order', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
scope
.post('/admin/orders/450789469/fulfillments.json', input)
.reply(201, output);
return shopify.fulfillment
.create(450789469, input.fulfillment)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('creates a fulfillment for one or many fulfillment orders', () => {
const input = fixtures.req.createV2;
const output = fixtures.res.createV2;
scope.post('/admin/fulfillments.json', input).reply(201, output);
return shopify.fulfillment
.createV2(input.fulfillment)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('updates a fulfillment', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;
scope
.put('/admin/orders/450789469/fulfillments/255858046.json', input)
.reply(200, output);
return shopify.fulfillment
.update(450789469, 255858046, input.fulfillment)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('completes a pending fulfillment', () => {
const output = fixtures.res.complete;
scope
.post('/admin/orders/450789469/fulfillments/255858046/complete.json', {})
.reply(201, output);
return shopify.fulfillment
.complete(450789469, 255858046)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('opens a pending fulfillment', () => {
const output = fixtures.res.open;
scope
.post('/admin/orders/450789469/fulfillments/255858046/open.json', {})
.reply(201, output);
return shopify.fulfillment
.open(450789469, 255858046)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('cancels a pending fulfillment', () => {
const output = fixtures.res.cancel;
scope
.post('/admin/orders/450789469/fulfillments/255858046/cancel.json', {})
.reply(201, output);
return shopify.fulfillment
.cancel(450789469, 255858046)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
it('injects the api version to the request path if provided', () => {
scope
.get(`/admin/api/${apiVersion}/orders/450789469/fulfillments/count.json`)
.reply(200, { count: 1 });
const shopify = new Shopify({ shopName, accessToken, apiVersion });
return shopify.fulfillment
.count(450789469)
.then((data) => expect(data).to.equal(1));
});
it('updates the tracking information for a fulfillment', () => {
const input = fixtures.req.updateTracking;
const output = fixtures.res.updateTracking;
scope
.post('/admin/fulfillments/1022782904/update_tracking.json', input)
.reply(200, output);
return shopify.fulfillment
.updateTracking(1022782904, input.fulfillment)
.then((data) => expect(data).to.deep.equal(output.fulfillment));
});
});