UNPKG

6.26 kBJavaScriptView Raw
1var assert = require('assert');
2var MockHttpClient = require('./mock-http-client');
3var MemoryStore = require('ac-node').MemoryStore;
4var RestClient = require('..').RestClient;
5var tenantFactory = require('..').tenantFactory;
6var fixtures = require('./fixtures');
7var wait = require('co-wait');
8
9describe('ac hipchat tenant client', function () {
10
11 var store = MemoryStore();
12 var installablePayload = fixtures.load('tenant-installable.json');
13 var capabilities = fixtures.load('tenant-capabilities.json');
14 var tenant = tenantFactory(installablePayload, capabilities);
15 var cache = store.narrow(tenant.id).narrow('token');
16 var httpClient;
17 var restClient;
18
19 beforeEach(function *() {
20 httpClient = MockHttpClient(61);
21 restClient = RestClient(httpClient).forTenant(tenant, cache, [
22 'admin_group',
23 'admin_room',
24 'manage_rooms',
25 'send_message',
26 'send_notification',
27 'view_group',
28 'view_messages'
29 ]);
30 });
31
32 afterEach(function *() {
33 yield store.clear();
34 });
35
36 if (!/\bfast\b/.test(process.env.NODE_TEST)) {
37 it('should get tokens, and refresh them when they expire', function *() {
38 var token = yield restClient.getToken('send_notification');
39 assert.equal(token, '1a2b3c4d5e6f');
40 yield wait(100);
41 token = yield restClient.getToken('send_notification');
42 assert.equal(token, '1a2b3c4d5e6f');
43 yield wait(1000);
44 token = yield restClient.getToken('send_notification');
45 assert.equal(token, '2b3c4d5e6f7g');
46 });
47 }
48
49 it('should get all emoticons', function *() {
50 yield restClient.getEmoticons();
51 });
52
53 it('should get one emoticon', function *() {
54 yield restClient.getEmoticon('foo');
55 });
56
57 it('should delete an oauth session', function *() {
58 yield restClient.deleteSession('1a2b3c4d5e6f');
59 });
60
61 it('should get an oauth session', function *() {
62 yield restClient.getSession('1a2b3c4d5e6f');
63 });
64
65 it('should get a room message', function *() {
66 yield restClient.getRoomMessage('room-id', 'message-id');
67 });
68
69 it('should create a room', function *() {
70 yield restClient.createRoom({
71 name: 'foo',
72 topic: 'bar',
73 guestAccess: true,
74 ownerUserId: 'user-id',
75 privacy: 'public'
76 });
77 });
78
79 it('should get all rooms', function *() {
80 yield restClient.getRooms();
81 });
82
83 it('should get recent room history', function *() {
84 yield restClient.getRecentRoomHistory('foo');
85 });
86
87 it('should send a room notification', function *() {
88 yield restClient.sendNotification(1, 'This is a test message');
89 });
90
91 it('should update a room', function *() {
92 yield restClient.updateRoom('foo', {
93 name: 'foo',
94 privacy: 'public',
95 is_archived: false,
96 is_guest_accessible: true,
97 topic: 'bar',
98 owner: {
99 id: 'user-id'
100 }
101 });
102 });
103
104 it('should get a room', function *() {
105 yield restClient.getRoom('foo');
106 });
107
108 it('should delete a room', function *() {
109 yield restClient.deleteRoom('foo');
110 });
111
112 it('should create a room webhook', function *() {
113 yield restClient.createRoomWebhook(1, {event: 'room_enter', name: 'abcdef1234567890', url: 'https://example.com/webhook'});
114 // deprecated
115 yield restClient.createWebhook(1, {event: 'room_enter', name: 'abcdef1234567890', url: 'https://example.com/webhook'});
116 });
117
118 it('should get all room webhooks', function *() {
119 yield restClient.getRoomWebhooks('foo');
120 // deprecated
121 yield restClient.getWebhooks('foo');
122 });
123
124 it('should get room statistics', function *() {
125 yield restClient.getRoomStatistics('foo');
126 });
127
128 it('should get room members', function *() {
129 yield restClient.getRoomMembers('foo');
130 });
131
132 it('should reply to a message', function *() {
133 yield restClient.replyToMessage('foo', 'parentId', 'message');
134 });
135
136 it('should get room members', function *() {
137 yield restClient.getRoomMembers('foo');
138 });
139
140 it('should set a room topic', function *() {
141 yield restClient.setRoomTopic('foo', 'topic');
142 });
143
144 it('should share a link with a room', function *() {
145 yield restClient.shareLinkWithRoom('foo', 'link', 'message');
146 });
147
148 it('should add a room member', function *() {
149 yield restClient.addRoomMember('foo', 'user-id');
150 });
151
152 it('should remove a room member', function *() {
153 yield restClient.removeRoomMember('foo', 'user-id');
154 });
155
156 it('should delete a room webhook', function *() {
157 yield restClient.deleteRoomWebhook('foo', 1234);
158 // deprecated
159 yield restClient.deleteWebhook('foo', 1234);
160 });
161
162 it('should get a room webhook', function *() {
163 yield restClient.getRoomWebhook('foo', 1234);
164 });
165
166 it('should get room history', function *() {
167 yield restClient.getRoomHistory('foo');
168 });
169
170 it('should get a private chat message', function *() {
171 yield restClient.getPrivateChatMessage('foo', 'message-id');
172 });
173
174 it('should get recent private chat history', function *() {
175 yield restClient.getRecentPrivateChatHistory('foo');
176 });
177
178 it('should update a user photo', function *() {
179 yield restClient.updateUserPhoto('user-id', 'base64');
180 });
181
182 it('should delete a user photo', function *() {
183 yield restClient.deleteUserPhoto('user-id');
184 });
185
186 it('should update a user', function *() {
187 yield restClient.updateUser('user-id', {
188 name: 'foo',
189 title: 'tester',
190 presence: {},
191 mention_name: 'foo',
192 is_group_admin: true,
193 timezone: 'mst',
194 password: 'password',
195 email: 'foo@bar.com'
196 });
197 });
198
199 it('should delete a user', function *() {
200 yield restClient.deleteUser('user-id');
201 });
202
203 it('should get a user', function *() {
204 yield restClient.getUser('user-id');
205 });
206
207 it('should create a user', function *() {
208 yield restClient.createUser({
209 name: 'user-id',
210 title: 'title',
211 mention_name: 'mention-name',
212 is_group_admin: true,
213 timezone: 'mst',
214 password: 'password',
215 email: 'user-id@foo.com'
216 });
217 });
218
219 it('should get all users', function *() {
220 yield restClient.getUsers();
221 });
222
223 it('should share a link with a user', function *() {
224 yield restClient.shareLinkWithUser('user-id', 'link', 'message');
225 });
226
227});