UNPKG

2.82 kBJavaScriptView Raw
1var assert = require('assert');
2var whExtractors = require('..').webhookExtractors;
3
4describe('ac hipchat webhook extractors', function () {
5
6 it('should extract normalized entities from a room_enter webhook', function () {
7 var ctx = whExtractors['room_enter']({
8 webhook_id: 10,
9 item: {
10 room: {
11 id: 1
12 },
13 sender: {
14 name: 'user'
15 }
16 }
17 });
18 assert.equal(ctx.webhookId, 10);
19 assert.ok(ctx.room);
20 assert.ok(ctx.sender);
21 assert.equal(ctx.room.id, 1);
22 assert.equal(ctx.sender.name, 'user');
23 });
24
25 it('should extract normalized entities from a room_exit webhook', function () {
26 var ctx = whExtractors['room_exit']({
27 webhook_id: 10,
28 item: {
29 room: {
30 id: 1
31 },
32 sender: {
33 name: 'user'
34 }
35 }
36 });
37 assert.equal(ctx.webhookId, 10);
38 assert.ok(ctx.room);
39 assert.ok(ctx.sender);
40 assert.equal(ctx.room.id, 1);
41 assert.equal(ctx.sender.name, 'user');
42 });
43
44 it('should extract normalized entities from a room_message webhook', function () {
45 var ctx = whExtractors['room_message']({
46 webhook_id: 10,
47 item: {
48 room: {
49 id: 1
50 },
51 message: {
52 id: 2,
53 from: {
54 name: 'user'
55 },
56 message: 'hello user'
57 }
58 }
59 });
60 assert.equal(ctx.webhookId, 10);
61 assert.ok(ctx.room);
62 assert.ok(ctx.sender);
63 assert.ok(ctx.message);
64 assert.equal(ctx.room.id, 1);
65 assert.equal(ctx.sender.name, 'user');
66 assert.equal(ctx.message.id, 2);
67 assert.equal(ctx.content, 'hello user');
68 });
69
70 it('should extract normalized entities from a room_notification webhook', function () {
71 var ctx = whExtractors['room_notification']({
72 webhook_id: 10,
73 item: {
74 room: {
75 id: 1
76 },
77 message: {
78 id: 2,
79 from: 'addon',
80 message: 'hello addon'
81 }
82 }
83 });
84 assert.equal(ctx.webhookId, 10);
85 assert.ok(ctx.room);
86 assert.ok(ctx.sender);
87 assert.ok(ctx.message);
88 assert.equal(ctx.room.id, 1);
89 assert.equal(ctx.sender.name, 'addon');
90 assert.equal(ctx.message.id, 2);
91 assert.equal(ctx.content, 'hello addon');
92 });
93
94 it('should extract normalized entities from a room_topic_change webhook', function () {
95 var ctx = whExtractors['room_topic_change']({
96 webhook_id: 10,
97 item: {
98 room: {
99 id: 1
100 },
101 sender: {
102 name: 'user'
103 },
104 topic: 'foo'
105 }
106 });
107 assert.equal(ctx.webhookId, 10);
108 assert.ok(ctx.room);
109 assert.ok(ctx.sender);
110 assert.equal(ctx.room.id, 1);
111 assert.equal(ctx.sender.name, 'user');
112 assert.equal(ctx.topic, 'foo');
113 });
114
115});