forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.test.js
More file actions
144 lines (109 loc) · 4.3 KB
/
checkout.test.js
File metadata and controls
144 lines (109 loc) · 4.3 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
describe('Shopify#checkout', () => {
'use strict';
const expect = require('chai').expect;
const fixtures = require('./fixtures/checkout');
const common = require('./common');
const shopify = common.shopify;
const scope = common.scope;
afterEach(() => expect(scope.isDone()).to.be.true);
it('gets a count of all checkout (1/2)', () => {
scope.get('/admin/checkouts/count.json').reply(200, { count: 5 });
return shopify.checkout.count().then((data) => expect(data).to.equal(5));
});
it('gets a count of all checkout (2/2)', () => {
scope.get('/admin/checkouts/count.json?foo=bar').reply(200, { count: 5 });
return shopify.checkout
.count({ foo: 'bar' })
.then((data) => expect(data).to.equal(5));
});
it('gets a list of all checkout (1/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/checkouts.json').reply(200, output);
return shopify.checkout
.list()
.then((data) => expect(data).to.deep.equal(output.checkouts));
});
it('gets a list of all checkout (2/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/checkouts.json?foo=bar').reply(200, output);
return shopify.checkout
.list({ foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.checkouts));
});
it('creates a new checkout', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
scope.post('/admin/checkouts.json', input).reply(201, output);
return shopify.checkout
.create(input.checkout)
.then((data) => expect(data).to.deep.equal(output.checkout));
});
it('completes a free checkout', () => {
const token = 'b490a9220cd14d7344024f4874f640a6';
const output = fixtures.res.complete;
scope
.post(`/admin/checkouts/${token}/complete.json`, {})
.reply(200, output);
return shopify.checkout
.complete(token)
.then((data) => expect(data).to.deep.equal(output.checkout));
});
it('completes a free checkout and retries 202 response', () => {
const token = 'b490a9220cd14d7344024f4874f640a6';
const baseUrl = shopify.baseUrl;
const pathname = `/admin/checkouts/${token}`;
const href = `${baseUrl.protocol}//${baseUrl.hostname}${pathname}.json`;
const output = fixtures.res.complete;
scope
.post(`${pathname}/complete.json`, {})
.reply(202, '', { Location: href, 'Retry-After': 0 })
.get(`${pathname}.json`)
.reply(200, output);
return shopify.checkout
.complete(token)
.then((data) => expect(data).to.deep.equal(output.checkout));
});
it('gets a single checkout by its token', () => {
const output = fixtures.res.get;
scope
.get('/admin/checkouts/bd5a8aa1ecd019dd3520ff791ee3a24c.json')
.reply(200, output);
return shopify.checkout
.get('bd5a8aa1ecd019dd3520ff791ee3a24c')
.then((data) => expect(data).to.deep.equal(output.checkout));
});
it('updates an existing checkout', () => {
const token = 'exuw7apwoycchjuwtiqg8nytfhphr62a';
const input = fixtures.req.update;
const output = fixtures.res.update;
scope.put(`/admin/checkouts/${token}.json`, input).reply(200, output);
return shopify.checkout
.update(token, input.checkout)
.then((data) => expect(data).to.deep.equal(output.checkout));
});
it('gets a list of shipping rates', () => {
const token = 'exuw7apwoycchjuwtiqg8nytfhphr62a';
const output = fixtures.res.shippingRates;
scope
.get(`/admin/checkouts/${token}/shipping_rates.json`)
.reply(200, output);
return shopify.checkout
.shippingRates(token)
.then((data) => expect(data).to.deep.equal(output.shipping_rates));
});
it('gets a list of shipping rates and retries 202 response', () => {
const token = 'exuw7apwoycchjuwtiqg8nytfhphr62a';
const baseUrl = shopify.baseUrl;
const pathname = `/admin/checkouts/${token}/shipping_rates.json`;
const href = `${baseUrl.protocol}//${baseUrl.hostname}${pathname}?foo=bar`;
const output = fixtures.res.shippingRates;
scope
.get(pathname)
.reply(202, '', { Location: href, 'Retry-After': 0 })
.get(`${pathname}?foo=bar`)
.reply(200, output);
return shopify.checkout
.shippingRates(token)
.then((data) => expect(data).to.deep.equal(output.shipping_rates));
});
});