@webex/plugin-webhooks 2.59.2 → 2.59.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -6
- package/README.md +50 -50
- package/babel.config.js +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/webhooks.js +171 -171
- package/dist/webhooks.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +16 -15
- package/process +1 -1
- package/src/index.js +11 -11
- package/src/webhooks.js +240 -240
- package/test/integration/spec/webhooks.js +163 -163
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import '@webex/internal-plugin-device';
|
|
6
|
-
import '@webex/plugin-logger';
|
|
7
|
-
import '@webex/plugin-rooms';
|
|
8
|
-
import '@webex/plugin-webhooks';
|
|
9
|
-
import WebexCore, {WebexHttpError} from '@webex/webex-core';
|
|
10
|
-
import {assert} from '@webex/test-helper-chai';
|
|
11
|
-
import sinon from 'sinon';
|
|
12
|
-
import testUsers from '@webex/test-helper-test-users';
|
|
13
|
-
|
|
14
|
-
describe('plugin-webhooks', function () {
|
|
15
|
-
this.timeout(60000);
|
|
16
|
-
|
|
17
|
-
let webex;
|
|
18
|
-
|
|
19
|
-
before(() =>
|
|
20
|
-
testUsers.create({count: 1}).then(([user]) => {
|
|
21
|
-
webex = new WebexCore({credentials: user.token});
|
|
22
|
-
})
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
describe('#webhooks', () => {
|
|
26
|
-
let room;
|
|
27
|
-
|
|
28
|
-
before(() =>
|
|
29
|
-
webex.rooms
|
|
30
|
-
.create({
|
|
31
|
-
title: 'Webex Webhook Test Room',
|
|
32
|
-
})
|
|
33
|
-
.then((r) => {
|
|
34
|
-
room = r;
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
let webhook;
|
|
39
|
-
const webhooks = [];
|
|
40
|
-
|
|
41
|
-
beforeEach(() =>
|
|
42
|
-
webex.webhooks
|
|
43
|
-
.create({
|
|
44
|
-
resource: 'messages',
|
|
45
|
-
event: 'created',
|
|
46
|
-
filter: `roomId=${room.id}`,
|
|
47
|
-
targetUrl: 'https://example.com',
|
|
48
|
-
name: 'Test Webhook',
|
|
49
|
-
})
|
|
50
|
-
.then((w) => {
|
|
51
|
-
webhook = w;
|
|
52
|
-
webhooks.push(webhook);
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
after(() =>
|
|
57
|
-
Promise.all(
|
|
58
|
-
webhooks.map((webhook) =>
|
|
59
|
-
webex.webhooks.remove(webhook).catch((reason) => {
|
|
60
|
-
console.warn('failed to remove webhook', reason);
|
|
61
|
-
})
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
after(() =>
|
|
67
|
-
webex.rooms.remove(room).catch((reason) => {
|
|
68
|
-
console.warn('failed to remove room', reason);
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
describe('#create()', () => {
|
|
73
|
-
it('creates a webhook that listens for new messages', () =>
|
|
74
|
-
webex.webhooks
|
|
75
|
-
.create({
|
|
76
|
-
resource: 'messages',
|
|
77
|
-
event: 'created',
|
|
78
|
-
filter: `roomId=${room.id}`,
|
|
79
|
-
targetUrl: 'https://example.com',
|
|
80
|
-
name: 'Test Webhook',
|
|
81
|
-
})
|
|
82
|
-
.then((webhook) => {
|
|
83
|
-
webhooks.push(webhook);
|
|
84
|
-
assert.isWebhook(webhook);
|
|
85
|
-
}));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('#get()', () => {
|
|
89
|
-
it('retrieves a specific webhook', () =>
|
|
90
|
-
webex.webhooks.get(webhook.id).then((w) => {
|
|
91
|
-
assert.deepEqual(w, webhook);
|
|
92
|
-
}));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('#list()', () => {
|
|
96
|
-
it('retrieves all the webhooks to which I have access', () =>
|
|
97
|
-
webex.webhooks.list().then((webhooks) => {
|
|
98
|
-
assert.isAbove(webhooks.length, 0);
|
|
99
|
-
for (webhook of webhooks) {
|
|
100
|
-
assert.isWebhook(webhook);
|
|
101
|
-
}
|
|
102
|
-
assert.include(webhooks.items, webhook);
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
it('retrieves a bounded set of webhooks', () => {
|
|
106
|
-
const spy = sinon.spy();
|
|
107
|
-
|
|
108
|
-
return webex.webhooks
|
|
109
|
-
.list({max: 1})
|
|
110
|
-
.then((webhooks) => {
|
|
111
|
-
assert.lengthOf(webhooks, 1);
|
|
112
|
-
|
|
113
|
-
return (function f(page) {
|
|
114
|
-
for (const webhook of page) {
|
|
115
|
-
spy(webhook.id);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (page.hasNext()) {
|
|
119
|
-
return page.next().then(f);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return Promise.resolve();
|
|
123
|
-
})(webhooks);
|
|
124
|
-
})
|
|
125
|
-
.then(() => {
|
|
126
|
-
assert.isAbove(spy.callCount, 0);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe('#update()', () => {
|
|
132
|
-
it('updates the target url of the specified webhook', () => {
|
|
133
|
-
webhook.targetUrl = 'https://example.com/newpath';
|
|
134
|
-
|
|
135
|
-
return webex.webhooks.update(webhook).then((w) => {
|
|
136
|
-
assert.deepEqual(w, webhook);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('updates the name of the specified webhook', () => {
|
|
141
|
-
webhook.name = 'new name';
|
|
142
|
-
|
|
143
|
-
return webex.webhooks.update(webhook).then((w) => {
|
|
144
|
-
assert.deepEqual(w, webhook);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('#remove()', () => {
|
|
150
|
-
it('removes the specified webhook', () =>
|
|
151
|
-
webex.webhooks
|
|
152
|
-
.remove(webhook)
|
|
153
|
-
.then((body) => {
|
|
154
|
-
assert.notOk(body);
|
|
155
|
-
|
|
156
|
-
return assert.isRejected(webex.webhooks.get(webhook));
|
|
157
|
-
})
|
|
158
|
-
.then((reason) => {
|
|
159
|
-
assert.instanceOf(reason, WebexHttpError.NotFound);
|
|
160
|
-
}));
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import '@webex/internal-plugin-device';
|
|
6
|
+
import '@webex/plugin-logger';
|
|
7
|
+
import '@webex/plugin-rooms';
|
|
8
|
+
import '@webex/plugin-webhooks';
|
|
9
|
+
import WebexCore, {WebexHttpError} from '@webex/webex-core';
|
|
10
|
+
import {assert} from '@webex/test-helper-chai';
|
|
11
|
+
import sinon from 'sinon';
|
|
12
|
+
import testUsers from '@webex/test-helper-test-users';
|
|
13
|
+
|
|
14
|
+
describe('plugin-webhooks', function () {
|
|
15
|
+
this.timeout(60000);
|
|
16
|
+
|
|
17
|
+
let webex;
|
|
18
|
+
|
|
19
|
+
before(() =>
|
|
20
|
+
testUsers.create({count: 1}).then(([user]) => {
|
|
21
|
+
webex = new WebexCore({credentials: user.token});
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
describe('#webhooks', () => {
|
|
26
|
+
let room;
|
|
27
|
+
|
|
28
|
+
before(() =>
|
|
29
|
+
webex.rooms
|
|
30
|
+
.create({
|
|
31
|
+
title: 'Webex Webhook Test Room',
|
|
32
|
+
})
|
|
33
|
+
.then((r) => {
|
|
34
|
+
room = r;
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
let webhook;
|
|
39
|
+
const webhooks = [];
|
|
40
|
+
|
|
41
|
+
beforeEach(() =>
|
|
42
|
+
webex.webhooks
|
|
43
|
+
.create({
|
|
44
|
+
resource: 'messages',
|
|
45
|
+
event: 'created',
|
|
46
|
+
filter: `roomId=${room.id}`,
|
|
47
|
+
targetUrl: 'https://example.com',
|
|
48
|
+
name: 'Test Webhook',
|
|
49
|
+
})
|
|
50
|
+
.then((w) => {
|
|
51
|
+
webhook = w;
|
|
52
|
+
webhooks.push(webhook);
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
after(() =>
|
|
57
|
+
Promise.all(
|
|
58
|
+
webhooks.map((webhook) =>
|
|
59
|
+
webex.webhooks.remove(webhook).catch((reason) => {
|
|
60
|
+
console.warn('failed to remove webhook', reason);
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
after(() =>
|
|
67
|
+
webex.rooms.remove(room).catch((reason) => {
|
|
68
|
+
console.warn('failed to remove room', reason);
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
describe('#create()', () => {
|
|
73
|
+
it('creates a webhook that listens for new messages', () =>
|
|
74
|
+
webex.webhooks
|
|
75
|
+
.create({
|
|
76
|
+
resource: 'messages',
|
|
77
|
+
event: 'created',
|
|
78
|
+
filter: `roomId=${room.id}`,
|
|
79
|
+
targetUrl: 'https://example.com',
|
|
80
|
+
name: 'Test Webhook',
|
|
81
|
+
})
|
|
82
|
+
.then((webhook) => {
|
|
83
|
+
webhooks.push(webhook);
|
|
84
|
+
assert.isWebhook(webhook);
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('#get()', () => {
|
|
89
|
+
it('retrieves a specific webhook', () =>
|
|
90
|
+
webex.webhooks.get(webhook.id).then((w) => {
|
|
91
|
+
assert.deepEqual(w, webhook);
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('#list()', () => {
|
|
96
|
+
it('retrieves all the webhooks to which I have access', () =>
|
|
97
|
+
webex.webhooks.list().then((webhooks) => {
|
|
98
|
+
assert.isAbove(webhooks.length, 0);
|
|
99
|
+
for (webhook of webhooks) {
|
|
100
|
+
assert.isWebhook(webhook);
|
|
101
|
+
}
|
|
102
|
+
assert.include(webhooks.items, webhook);
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
it('retrieves a bounded set of webhooks', () => {
|
|
106
|
+
const spy = sinon.spy();
|
|
107
|
+
|
|
108
|
+
return webex.webhooks
|
|
109
|
+
.list({max: 1})
|
|
110
|
+
.then((webhooks) => {
|
|
111
|
+
assert.lengthOf(webhooks, 1);
|
|
112
|
+
|
|
113
|
+
return (function f(page) {
|
|
114
|
+
for (const webhook of page) {
|
|
115
|
+
spy(webhook.id);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (page.hasNext()) {
|
|
119
|
+
return page.next().then(f);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
})(webhooks);
|
|
124
|
+
})
|
|
125
|
+
.then(() => {
|
|
126
|
+
assert.isAbove(spy.callCount, 0);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('#update()', () => {
|
|
132
|
+
it('updates the target url of the specified webhook', () => {
|
|
133
|
+
webhook.targetUrl = 'https://example.com/newpath';
|
|
134
|
+
|
|
135
|
+
return webex.webhooks.update(webhook).then((w) => {
|
|
136
|
+
assert.deepEqual(w, webhook);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('updates the name of the specified webhook', () => {
|
|
141
|
+
webhook.name = 'new name';
|
|
142
|
+
|
|
143
|
+
return webex.webhooks.update(webhook).then((w) => {
|
|
144
|
+
assert.deepEqual(w, webhook);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('#remove()', () => {
|
|
150
|
+
it('removes the specified webhook', () =>
|
|
151
|
+
webex.webhooks
|
|
152
|
+
.remove(webhook)
|
|
153
|
+
.then((body) => {
|
|
154
|
+
assert.notOk(body);
|
|
155
|
+
|
|
156
|
+
return assert.isRejected(webex.webhooks.get(webhook));
|
|
157
|
+
})
|
|
158
|
+
.then((reason) => {
|
|
159
|
+
assert.instanceOf(reason, WebexHttpError.NotFound);
|
|
160
|
+
}));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|