forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.test.js
More file actions
150 lines (107 loc) · 4.11 KB
/
order.test.js
File metadata and controls
150 lines (107 loc) · 4.11 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
describe('Shopify#order', () => {
'use strict';
const expect = require('chai').expect;
const fixtures = require('./fixtures/order');
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 orders (1/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/orders.json').reply(200, output);
return shopify.order
.list()
.then((data) => expect(data).to.deep.equal(output.orders));
});
it('gets a list of all orders (2/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/orders.json?page=1').reply(200, output);
return shopify.order
.list({ page: 1 })
.then((data) => expect(data).to.deep.equal(output.orders));
});
it('gets a single order by its ID (1/2)', () => {
const output = fixtures.res.get;
scope.get('/admin/orders/450789469.json').reply(200, output);
return shopify.order
.get(450789469)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('gets a single order by its ID (2/2)', () => {
const output = fixtures.res.get;
scope.get('/admin/orders/450789469.json?foo=bar').reply(200, output);
return shopify.order
.get(450789469, { foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.order));
});
it('gets a count of all orders (1/2)', () => {
scope.get('/admin/orders/count.json').reply(200, { count: 1 });
return shopify.order.count().then((data) => expect(data).to.equal(1));
});
it('gets a count of all orders (2/2)', () => {
scope.get('/admin/orders/count.json?status=open').reply(200, { count: 1 });
return shopify.order
.count({ status: 'open' })
.then((data) => expect(data).to.equal(1));
});
it('closes an order', () => {
const output = fixtures.res.close;
scope.post('/admin/orders/450789469/close.json').reply(200, output);
return shopify.order
.close(450789469)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('re-opens a closed order', () => {
const output = fixtures.res.open;
scope.post('/admin/orders/450789469/open.json').reply(200, output);
return shopify.order
.open(450789469)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('cancels an order (1/2)', () => {
const output = fixtures.res.cancel;
scope.post('/admin/orders/450789469/cancel.json').reply(200, output);
return shopify.order
.cancel(450789469)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('cancels an order (2/2)', () => {
const input = { reason: 'fraud' };
const output = fixtures.res.cancel;
scope.post('/admin/orders/450789469/cancel.json', input).reply(200, output);
return shopify.order
.cancel(450789469, input)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('creates a new order', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
scope.post('/admin/orders.json', input).reply(201, output);
return shopify.order
.create(input.order)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('updates an order', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;
scope.put('/admin/orders/450789469.json', input).reply(200, output);
return shopify.order
.update(450789469, input.order)
.then((data) => expect(data).to.deep.equal(output.order));
});
it('deletes an order', () => {
scope.delete('/admin/orders/450789469.json').reply(200, {});
return shopify.order
.delete(450789469)
.then((data) => expect(data).to.deep.equal({}));
});
it('retrieves a list of fulfillment orders for a specific order', () => {
const output = fixtures.res.fulfillmentOrders;
scope
.get('/admin/orders/450789469/fulfillment_orders.json')
.reply(200, output);
return shopify.order
.fulfillmentOrders(450789469)
.then((data) => expect(data).to.deep.equal(output.fulfillment_orders));
});
});