1 | var assert = require('assert');
|
2 | var MemoryStore = require('ac-node').MemoryStore;
|
3 | var MockHttpClient = require('./mock-http-client');
|
4 | var RestClient = require('..').RestClient;
|
5 | var WebhookManager = require('ac-node').WebhookManager;
|
6 | var HipchatWebhookManager = require('..').WebhookManager;
|
7 | var fixtures = require('./fixtures');
|
8 |
|
9 | describe('ac hipchat webhook manager', function () {
|
10 |
|
11 | var tenant = fixtures.load('tenant.json');
|
12 | var webhookStore;
|
13 | var manager;
|
14 |
|
15 | beforeEach(function () {
|
16 | var parent = WebhookManager();
|
17 | var store = MemoryStore();
|
18 | var tokenStore = store.narrow('token');
|
19 | webhookStore = store.narrow('webhook');
|
20 | var httpClient = MockHttpClient(10);
|
21 | var client = RestClient(httpClient).forTenant(tenant, tokenStore, [
|
22 | 'admin_group',
|
23 | 'admin_room',
|
24 | 'manage_rooms',
|
25 | 'send_message',
|
26 | 'send_notification',
|
27 | 'view_group'
|
28 | ]);
|
29 | var baseUrl = 'https://example.com';
|
30 | var webhookPath = '/webhook';
|
31 | manager = HipchatWebhookManager(parent, webhookStore, tenant, client, baseUrl, webhookPath);
|
32 | });
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | it('should return nothing when get is called with an unrecognized name', function *() {
|
38 | var output = yield manager.get('missing');
|
39 | assert.ok(!output);
|
40 | });
|
41 |
|
42 | it('should fail on add when the name is null', function *() {
|
43 | try {
|
44 | yield manager.add(null, {});
|
45 | assert.fail();
|
46 | } catch (err) {
|
47 | assert.equal(err.message, 'Invalid string');
|
48 | }
|
49 | });
|
50 |
|
51 | it('should generate a full webhook definition from basic inputs', function *() {
|
52 | var input = yield manager.add('room_enter');
|
53 | assert.deepEqual(input, {
|
54 | id: 123,
|
55 | event: 'room_enter',
|
56 | url: 'https://example.com/webhook?token=3632aafe93452c1e3a7ce1eccdf266003869bf81&name=5787ac6166cc875ffc3e482d91c12703df9362e8',
|
57 | name: '5787ac6166cc875ffc3e482d91c12703df9362e8'
|
58 | });
|
59 | });
|
60 |
|
61 | it('should successfully get previously added definitions', function *() {
|
62 | var input = yield manager.add('room_enter');
|
63 | var output = yield manager.get(input.name);
|
64 | assert.deepEqual(input, output);
|
65 | });
|
66 |
|
67 | it('should successfully remove previously added definitions', function *() {
|
68 | var input = yield manager.add('room_enter');
|
69 | var output = yield manager.get(input.name);
|
70 | assert.deepEqual(input, output);
|
71 | yield manager.remove(input.name);
|
72 | output = yield manager.get(input.name);
|
73 | assert.ok(!output);
|
74 | });
|
75 |
|
76 | });
|