1 | var assert = require('assert');
|
2 | var Builder = require('..').Builder;
|
3 |
|
4 | describe('ack hipchat builder', function () {
|
5 |
|
6 | describe('#key', function () {
|
7 |
|
8 | it('should accept a key value', function (done) {
|
9 | var descriptor;
|
10 | var builder = Builder({}, {
|
11 | addWebhook: function () {},
|
12 | ready: function (built) {
|
13 | descriptor = built;
|
14 | assert.equal(descriptor.key, 'test-key');
|
15 | done();
|
16 | }
|
17 | });
|
18 | builder.key('test-key');
|
19 | });
|
20 |
|
21 | });
|
22 |
|
23 | describe('#name', function () {
|
24 |
|
25 | it('should accept a name value', function (done) {
|
26 | var descriptor;
|
27 | var builder = Builder({}, {
|
28 | addWebhook: function () {},
|
29 | ready: function (built) {
|
30 | descriptor = built;
|
31 | assert.equal(descriptor.name, 'Test Name');
|
32 | done();
|
33 | }
|
34 | });
|
35 | builder.name('Test Name');
|
36 | });
|
37 |
|
38 | });
|
39 |
|
40 | describe('#description', function () {
|
41 |
|
42 | it('should accept a description value', function (done) {
|
43 | var descriptor;
|
44 | var builder = Builder({}, {
|
45 | addWebhook: function () {},
|
46 | ready: function (built) {
|
47 | descriptor = built;
|
48 | assert.equal(descriptor.description, 'Test description');
|
49 | done();
|
50 | }
|
51 | });
|
52 | builder.description('Test description');
|
53 | });
|
54 |
|
55 | });
|
56 |
|
57 | describe('#vendor', function () {
|
58 |
|
59 | it('should accept a vendor object', function (done) {
|
60 | var descriptor;
|
61 | var builder = Builder({}, {
|
62 | addWebhook: function () {},
|
63 | ready: function (built) {
|
64 | descriptor = built;
|
65 | assert.deepEqual(descriptor.vendor, {
|
66 | name: 'Vendor Name',
|
67 | url: 'http://example.com'
|
68 | });
|
69 | done();
|
70 | }
|
71 | });
|
72 | builder.vendor({
|
73 | name: 'Vendor Name',
|
74 | url: 'http://example.com'
|
75 | });
|
76 | });
|
77 |
|
78 | });
|
79 |
|
80 | describe('#vendorName', function () {
|
81 |
|
82 | it('should accept a vendor name', function (done) {
|
83 | var descriptor;
|
84 | var builder = Builder({}, {
|
85 | addWebhook: function () {},
|
86 | ready: function (built) {
|
87 | descriptor = built;
|
88 | assert.equal(descriptor.vendor.name, 'Vendor Name');
|
89 | done();
|
90 | }
|
91 | });
|
92 | builder.vendorName('Vendor Name');
|
93 | });
|
94 |
|
95 | });
|
96 |
|
97 | describe('#vendorUrl', function () {
|
98 |
|
99 | it('should accept a vendor url', function (done) {
|
100 | var descriptor;
|
101 | var builder = Builder({}, {
|
102 | addWebhook: function () {},
|
103 | ready: function (built) {
|
104 | descriptor = built;
|
105 | assert.equal(descriptor.vendor.url, 'http://example.com');
|
106 | done();
|
107 | }
|
108 | });
|
109 | builder.vendorUrl('http://example.com');
|
110 | });
|
111 |
|
112 | });
|
113 |
|
114 | describe('#avatarUrl', function () {
|
115 |
|
116 | it('should accept an avatar url', function (done) {
|
117 | var descriptor;
|
118 | var builder = Builder({}, {
|
119 | addWebhook: function () {},
|
120 | ready: function (built) {
|
121 | descriptor = built;
|
122 | assert.equal(descriptor.capabilities.hipchatApiConsumer.avatar.url, 'http://example.com/avatar.png');
|
123 | assert.equal(descriptor.capabilities.hipchatApiConsumer.avatar["url@2x"], 'http://example.com/avatar.png');
|
124 | done();
|
125 | }
|
126 | });
|
127 | builder.avatar('http://example.com/avatar.png');
|
128 | });
|
129 |
|
130 | });
|
131 |
|
132 | describe('#scopes', function () {
|
133 |
|
134 | it('should accept the param signature (scope)', function (done) {
|
135 | var descriptor;
|
136 | var builder = Builder({}, {
|
137 | addWebhook: function () {},
|
138 | ready: function (built) {
|
139 | descriptor = built;
|
140 | assert.deepEqual(descriptor.capabilities.hipchatApiConsumer.scopes, ['send_notification']);
|
141 | done();
|
142 | }
|
143 | });
|
144 | builder.scopes('send_notification');
|
145 | });
|
146 |
|
147 | it('should accept the param signature (scopes)', function (done) {
|
148 | var descriptor;
|
149 | var builder = Builder({}, {
|
150 | addWebhook: function () {},
|
151 | ready: function (built) {
|
152 | descriptor = built;
|
153 | assert.deepEqual(descriptor.capabilities.hipchatApiConsumer.scopes, ['send_notification', 'view_group']);
|
154 | done();
|
155 | }
|
156 | });
|
157 | builder.scopes(['send_notification', 'view_group']);
|
158 | });
|
159 |
|
160 | it('should accept the param signature (scope...)', function (done) {
|
161 | var descriptor;
|
162 | var builder = Builder({}, {
|
163 | addWebhook: function () {},
|
164 | ready: function (built) {
|
165 | descriptor = built;
|
166 | assert.deepEqual(descriptor.capabilities.hipchatApiConsumer.scopes, ['send_notification', 'view_group', 'admin_room']);
|
167 | done();
|
168 | }
|
169 | });
|
170 | builder.scopes('send_notification', 'view_group', 'admin_room');
|
171 | });
|
172 |
|
173 | });
|
174 |
|
175 | describe('#fromName', function () {
|
176 |
|
177 | it('should accept a fromName value', function (done) {
|
178 | var descriptor;
|
179 | var builder = Builder({}, {
|
180 | addWebhook: function () {},
|
181 | ready: function (built) {
|
182 | descriptor = built;
|
183 | assert.equal(descriptor.capabilities.hipchatApiConsumer.fromName, 'Test Name');
|
184 | done();
|
185 | }
|
186 | });
|
187 | builder.fromName('Test Name');
|
188 | });
|
189 |
|
190 | });
|
191 |
|
192 | describe('#allowGlobal', function () {
|
193 |
|
194 | it('should accept the param signature (boolean)', function (done) {
|
195 | var descriptor;
|
196 | var builder = Builder({}, {
|
197 | addWebhook: function () {},
|
198 | ready: function (built) {
|
199 | descriptor = built;
|
200 | assert.equal(descriptor.capabilities.installable.allowGlobal, true);
|
201 | done();
|
202 | }
|
203 | });
|
204 | builder.allowGlobal(true);
|
205 | });
|
206 |
|
207 | });
|
208 |
|
209 | describe('#allowRoom', function () {
|
210 |
|
211 | it('should accept the param signature (boolean)', function (done) {
|
212 | var descriptor;
|
213 | var builder = Builder({}, {
|
214 | addWebhook: function () {},
|
215 | ready: function (built) {
|
216 | descriptor = built;
|
217 | assert.equal(descriptor.capabilities.installable.allowRoom, true);
|
218 | done();
|
219 | }
|
220 | });
|
221 | builder.allowRoom(true);
|
222 | });
|
223 |
|
224 | });
|
225 |
|
226 | describe('#webhook', function () {
|
227 |
|
228 | it('should accept the param signature (event, url)', function () {
|
229 | var webhook, callback;
|
230 | var builder = Builder({}, {
|
231 | addWebhook: function (definition, cb) {
|
232 | webhook = definition;
|
233 | callback = cb;
|
234 | },
|
235 | ready: function () {}
|
236 | });
|
237 | builder.webhook('room_enter', '/room-enter');
|
238 | assert.equal(webhook.event, 'room_enter');
|
239 | assert.equal(webhook.url, '/room-enter');
|
240 | assert.ok(!callback);
|
241 | });
|
242 |
|
243 | it('should accept the param signature (event, callback)', function () {
|
244 | var webhook, callback;
|
245 | var builder = Builder({}, {
|
246 | addWebhook: function (definition, cb) {
|
247 | webhook = definition;
|
248 | callback = cb;
|
249 | },
|
250 | ready: function () {}
|
251 | });
|
252 | builder.webhook('room_enter', function *() {});
|
253 | assert.equal(webhook.event, 'room_enter');
|
254 | assert.ok(callback);
|
255 | });
|
256 |
|
257 | it('should reject the param signature (event, patternRe, url) when event != room_message', function () {
|
258 | var webhook, callback;
|
259 | var builder = Builder({}, {
|
260 | addWebhook: function (definition, cb) {
|
261 | webhook = definition;
|
262 | callback = cb;
|
263 | },
|
264 | ready: function () {}
|
265 | });
|
266 | try {
|
267 | builder.webhook('room_enter', /^\/foo(?:\s(.*)|$)/i, '/room-enter');
|
268 | assert.fail();
|
269 | } catch (e) {
|
270 | assert.ok(/pattern not supported/.test(e.message));
|
271 | }
|
272 | });
|
273 |
|
274 | it('should accept the param signature (event, patternRe, url)', function () {
|
275 | var webhook, callback;
|
276 | var builder = Builder({}, {
|
277 | addWebhook: function (definition, cb) {
|
278 | webhook = definition;
|
279 | callback = cb;
|
280 | },
|
281 | ready: function () {}
|
282 | });
|
283 | builder.webhook('room_message', /^\/foo(?:\s(.*)|$)/i, '/room-message');
|
284 | assert.equal(webhook.event, 'room_message');
|
285 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
286 | assert.equal(webhook.url, '/room-message');
|
287 | assert.ok(!callback);
|
288 | });
|
289 |
|
290 | it('should accept the param signature (event, patternRe, callback)', function () {
|
291 | var webhook, callback;
|
292 | var builder = Builder({}, {
|
293 | addWebhook: function (definition, cb) {
|
294 | webhook = definition;
|
295 | callback = cb;
|
296 | },
|
297 | ready: function () {}
|
298 | });
|
299 | builder.webhook('room_message', /^\/foo(?:\s(.*)|$)/i, function *() {});
|
300 | assert.equal(webhook.event, 'room_message');
|
301 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
302 | assert.ok(callback);
|
303 | });
|
304 |
|
305 | it('should accept the param signature (event, name, url)', function () {
|
306 | var webhook, callback;
|
307 | var builder = Builder({}, {
|
308 | addWebhook: function (definition, cb) {
|
309 | webhook = definition;
|
310 | callback = cb;
|
311 | },
|
312 | ready: function () {}
|
313 | });
|
314 | builder.webhook('room_enter', 'name', '/room-enter');
|
315 | assert.equal(webhook.event, 'room_enter');
|
316 | assert.equal(webhook.name, 'name');
|
317 | assert.equal(webhook.url, '/room-enter');
|
318 | assert.ok(!callback);
|
319 | });
|
320 |
|
321 | it('should accept the param signature (event, name, callback)', function () {
|
322 | var webhook, callback;
|
323 | var builder = Builder({}, {
|
324 | addWebhook: function (definition, cb) {
|
325 | webhook = definition;
|
326 | callback = cb;
|
327 | },
|
328 | ready: function () {}
|
329 | });
|
330 | builder.webhook('room_enter', 'name', function *() {});
|
331 | assert.equal(webhook.event, 'room_enter');
|
332 | assert.equal(webhook.name, 'name');
|
333 | assert.ok(callback);
|
334 | });
|
335 |
|
336 | it('should reject the param signature (event, name, patternRe, url) when event!=room_message', function () {
|
337 | var webhook, callback;
|
338 | var builder = Builder({}, {
|
339 | addWebhook: function (definition, cb) {
|
340 | webhook = definition;
|
341 | callback = cb;
|
342 | },
|
343 | ready: function () {}
|
344 | });
|
345 | try {
|
346 | builder.webhook('room_enter', 'name', /^\/foo(?:\s(.*)|$)/i, '/room-enter');
|
347 | assert.fail();
|
348 | } catch (e) {
|
349 | assert.ok(/pattern not supported/.test(e.message));
|
350 | }
|
351 | });
|
352 |
|
353 | it('should accept the param signature (event, name, patternRe, url)', function () {
|
354 | var webhook, callback;
|
355 | var builder = Builder({}, {
|
356 | addWebhook: function (definition, cb) {
|
357 | webhook = definition;
|
358 | callback = cb;
|
359 | },
|
360 | ready: function () {}
|
361 | });
|
362 | builder.webhook('room_message', 'name', /^\/foo(?:\s(.*)|$)/i, '/room-message');
|
363 | assert.equal(webhook.event, 'room_message');
|
364 | assert.equal(webhook.name, 'name');
|
365 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
366 | assert.equal(webhook.url, '/room-message');
|
367 | assert.ok(!callback);
|
368 | });
|
369 |
|
370 | it('should accept the param signature (event, name, patternRe, callback)', function () {
|
371 | var webhook, callback;
|
372 | var builder = Builder({}, {
|
373 | addWebhook: function (definition, cb) {
|
374 | webhook = definition;
|
375 | callback = cb;
|
376 | },
|
377 | ready: function () {}
|
378 | });
|
379 | builder.webhook('room_message', 'name', /^\/foo(?:\s(.*)|$)/i, function *() {});
|
380 | assert.equal(webhook.event, 'room_message');
|
381 | assert.equal(webhook.name, 'name');
|
382 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
383 | assert.ok(callback);
|
384 | });
|
385 |
|
386 | it('should accept the param signature (object)', function () {
|
387 | var webhook, callback;
|
388 | var builder = Builder({}, {
|
389 | addWebhook: function (definition, cb) {
|
390 | webhook = definition;
|
391 | callback = cb;
|
392 | },
|
393 | ready: function () {}
|
394 | });
|
395 | builder.webhook({
|
396 | event: 'room_message',
|
397 | name: 'name',
|
398 | pattern: /^\/foo(?:\s(.*)|$)/i,
|
399 | url: '/room-message'
|
400 | });
|
401 | assert.equal(webhook.event, 'room_message');
|
402 | assert.equal(webhook.name, 'name');
|
403 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
404 | assert.equal(webhook.url, '/room-message');
|
405 | assert.ok(!callback);
|
406 | });
|
407 |
|
408 | it('should reject the param signature (object) when pattern exists and event!=room_message', function () {
|
409 | var webhook, callback;
|
410 | var builder = Builder({}, {
|
411 | addWebhook: function (definition, cb) {
|
412 | webhook = definition;
|
413 | callback = cb;
|
414 | },
|
415 | ready: function () {}
|
416 | });
|
417 | try {
|
418 | builder.webhook({
|
419 | event: 'room_enter',
|
420 | name: 'name',
|
421 | pattern: /^\/foo(?:\s(.*)|$)/i,
|
422 | url: '/room-enter'
|
423 | });
|
424 | assert.fail();
|
425 | } catch (e) {
|
426 | assert.ok(/pattern not supported/.test(e.message));
|
427 | }
|
428 | });
|
429 |
|
430 | it('should accept the param signature (object, callback) and report the callback when no url is given', function () {
|
431 | var webhook, callback;
|
432 | var builder = Builder({}, {
|
433 | addWebhook: function (definition, cb) {
|
434 | webhook = definition;
|
435 | callback = cb;
|
436 | },
|
437 | ready: function () {}
|
438 | });
|
439 | builder.webhook({
|
440 | event: 'room_message',
|
441 | name: 'name',
|
442 | pattern: /^\/foo(?:\s(.*)|$)/i
|
443 | }, function *() {});
|
444 | assert.equal(webhook.event, 'room_message');
|
445 | assert.equal(webhook.name, 'name');
|
446 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
447 | assert.ok(callback);
|
448 | });
|
449 |
|
450 | it('should accept the param signature (object, callback) but not report the callback when a url is given', function () {
|
451 | var webhook, callback;
|
452 | var builder = Builder({}, {
|
453 | addWebhook: function (definition, cb) {
|
454 | webhook = definition;
|
455 | callback = cb;
|
456 | },
|
457 | ready: function () {}
|
458 | });
|
459 | builder.webhook({
|
460 | event: 'room_message',
|
461 | name: 'name',
|
462 | pattern: /^\/foo(?:\s(.*)|$)/i,
|
463 | url: '/room-message'
|
464 | }, function *() {});
|
465 | assert.equal(webhook.event, 'room_message');
|
466 | assert.equal(webhook.name, 'name');
|
467 | assert.equal(webhook.pattern.toString(), /^\/foo(?:\s(.*)|$)/i.toString());
|
468 | assert.ok(!callback);
|
469 | });
|
470 |
|
471 | });
|
472 |
|
473 | describe('#configurable', function () {
|
474 |
|
475 | it('should accept a path value', function (done) {
|
476 | var descriptor;
|
477 | var builder = Builder({}, {
|
478 | addWebhook: function () {},
|
479 | ready: function (built) {
|
480 | descriptor = built;
|
481 | assert.ok(descriptor.capabilities.configurable);
|
482 | assert.equal(descriptor.capabilities.configurable.url, '/configure');
|
483 | done();
|
484 | }
|
485 | });
|
486 | builder.configurable('/configure');
|
487 | });
|
488 |
|
489 | });
|
490 |
|
491 | });
|