forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.test.js
More file actions
102 lines (73 loc) · 2.77 KB
/
webhook.test.js
File metadata and controls
102 lines (73 loc) · 2.77 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
describe('Shopify#webhook', () => {
'use strict';
const expect = require('chai').expect;
const qs = require('qs');
const fixtures = require('./fixtures/webhook');
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 webhooks (1/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/webhooks.json').reply(200, output);
return shopify.webhook
.list()
.then((data) => expect(data).to.deep.equal(output.webhooks));
});
it('gets a list of all webhooks (2/2)', () => {
const output = fixtures.res.list;
scope.get('/admin/webhooks.json?page=1').reply(200, output);
return shopify.webhook
.list({ page: 1 })
.then((data) => expect(data).to.deep.equal(output.webhooks));
});
it('gets a count of all webhooks (1/2)', () => {
scope.get('/admin/webhooks/count.json').reply(200, { count: 2 });
return shopify.webhook.count().then((data) => expect(data).to.equal(2));
});
it('gets a count of all webhooks (2/2)', () => {
const query = { topic: 'orders/create' };
scope
.get('/admin/webhooks/count.json?' + qs.stringify(query))
.reply(200, { count: 1 });
return shopify.webhook
.count(query)
.then((data) => expect(data).to.equal(1));
});
it('gets a single webhook by its ID (1/2)', () => {
const output = fixtures.res.get;
scope.get('/admin/webhooks/4759306.json').reply(200, output);
return shopify.webhook
.get(4759306)
.then((data) => expect(data).to.deep.equal(output.webhook));
});
it('gets a single webhook by its ID (2/2)', () => {
const output = fixtures.res.get;
scope.get('/admin/webhooks/4759306.json?foo=bar').reply(200, output);
return shopify.webhook
.get(4759306, { foo: 'bar' })
.then((data) => expect(data).to.deep.equal(output.webhook));
});
it('creates a new webhook', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
scope.post('/admin/webhooks.json', input).reply(201, output);
return shopify.webhook
.create(input.webhook)
.then((data) => expect(data).to.deep.equal(output.webhook));
});
it('updates a webhook', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;
scope.put('/admin/webhooks/4759306.json', input).reply(200, output);
return shopify.webhook
.update(4759306, input.webhook)
.then((data) => expect(data).to.deep.equal(output.webhook));
});
it('deletes a webhook', () => {
scope.delete('/admin/webhooks/4759306.json').reply(200, {});
return shopify.webhook
.delete(4759306)
.then((data) => expect(data).to.deep.equal({}));
});
});