@tellescope/sdk 0.0.96 → 0.0.97

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.
@@ -49,15 +49,17 @@ var get_sha256 = function (s) {
49
49
  };
50
50
  exports.get_sha256 = get_sha256;
51
51
  var VERBOSE = true;
52
- var AWAIT_SOCKET_DURATION = 150; // 25ms was generally passing for Redis, 1000ms should be upper limit of performance
52
+ var AWAIT_SOCKET_DURATION = 250; // 25ms was generally passing for Redis, 1000ms should be upper limit of performance
53
53
  var host = process.env.TEST_URL || 'http://localhost:8080';
54
54
  var _a = [process.env.TEST_EMAIL, process.env.TEST_PASSWORD], email = _a[0], password = _a[1];
55
55
  var _b = [process.env.TEST_EMAIL_2, process.env.TEST_PASSWORD_2], email2 = _b[0], password2 = _b[1];
56
+ var _c = [process.env.NON_ADMIN_EMAIL, process.env.NON_ADMIN_PASSWORD], nonAdminEmail = _c[0], nonAdminPassword = _c[1];
56
57
  var businessId = '60398b1131a295e64f084ff6';
57
58
  var user1 = new sdk_1.Session({ host: host, enableSocketLogging: VERBOSE });
58
59
  var user2 = new sdk_1.Session({ host: host, enableSocketLogging: VERBOSE });
60
+ var sdkNonAdmin = new sdk_1.Session({ host: host });
59
61
  var enduserSDK = new enduser_1.EnduserSession({ host: host, businessId: businessId, enableSocketLogging: VERBOSE });
60
- if (!(email && password && email2 && password2)) {
62
+ if (!(email && password && email2 && password2 && nonAdminEmail && nonAdminPassword)) {
61
63
  console.error("Set TEST_EMAIL and TEST_PASSWORD");
62
64
  process.exit(1);
63
65
  }
@@ -69,7 +71,7 @@ var basic_tests = function () { return __awaiter(void 0, void 0, void 0, functio
69
71
  switch (_e.label) {
70
72
  case 0:
71
73
  socket_events = [];
72
- user2.subscribe({ 'endusers': 'endusers' }, {
74
+ user2.handle_events({
73
75
  'created-endusers': function (es) { return socket_events.push(es); },
74
76
  'updated-endusers': function (es) { return socket_events.push(es); },
75
77
  'deleted-endusers': function (es) { return socket_events.push(es); },
@@ -110,106 +112,223 @@ var basic_tests = function () { return __awaiter(void 0, void 0, void 0, functio
110
112
  });
111
113
  }); };
112
114
  var access_tests = function () { return __awaiter(void 0, void 0, void 0, function () {
113
- var user1Events, user2Events, user1Id, user2Id, room, sharedRoom, sharedChat, sharedChat2;
114
- var _a, _b, _c, _d;
115
- return __generator(this, function (_e) {
116
- switch (_e.label) {
115
+ var user1Events, nonAdminEvents, enduserEvents, user1Id, user2Id, room, sharedRoom, sharedChat, sharedChat2, unassignedEnduser, assignedEnduser, roomUnassigned, roomUnassignedWithUser, roomAssigned, userMessage, enduserMessage, nonAdminMessage, _a, _b, _c;
116
+ return __generator(this, function (_d) {
117
+ switch (_d.label) {
117
118
  case 0:
118
119
  user1Events = [];
119
- user2Events = [];
120
- // const user1Deletions: string[] = []
121
- // const user2Deletions: string[] = []
122
- user1.handle_events({
123
- 'created-chat_rooms': function (rs) { return user1Events.push.apply(user1Events, rs); },
124
- // 'updated-chat_rooms': rs => user1Events.push(...rs), sent message will create update event as cached messagepreview/sender updated
125
- // 'deleted-chat_rooms': rs => user1Events.push(...rs),
126
- });
127
- user2.handle_events({
128
- 'created-chat_rooms': function (rs) { return user2Events.push.apply(user2Events, rs); },
129
- // 'updated-chat_rooms': rs => user2Events.push(...rs),
130
- // 'deleted-chat_rooms': rs => user2Events.push(...rs),
131
- });
120
+ nonAdminEvents = [];
121
+ enduserEvents = [];
122
+ user1.handle_events({ 'created-chat_rooms': function (rs) { return user1Events.push.apply(user1Events, rs); } });
123
+ sdkNonAdmin.handle_events({ 'created-chat_rooms': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); } });
132
124
  user1Id = user1.userInfo.id;
133
- user2Id = user2.userInfo.id;
125
+ user2Id = sdkNonAdmin.userInfo.id;
134
126
  return [4 /*yield*/, user1.api.chat_rooms.createOne({ type: 'internal', userIds: [user1Id] })];
135
127
  case 1:
136
- room = _e.sent();
128
+ room = _d.sent();
137
129
  return [4 /*yield*/, user1.api.chat_rooms.createOne({ type: 'internal', userIds: [user1Id, user2Id] })];
138
130
  case 2:
139
- sharedRoom = _e.sent();
131
+ sharedRoom = _d.sent();
140
132
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
141
133
  case 3:
142
- _e.sent();
143
- (0, testing_1.assert)(user1Events.length === 0, 'bad event distribution for filter', 'verify filter socket no self');
144
- (0, testing_1.assert)(user2Events.length === 1 && sharedRoom.id === user2Events[0].id, 'bad event distribution for filter', 'verify filter socket push');
145
- user1.removeAllSocketListeners('created-chat_rooms');
146
- user1.removeAllSocketListeners('update-chat_rooms');
147
- user1.removeAllSocketListeners('deleted-chat_rooms');
148
- user2.removeAllSocketListeners('created-chat_rooms');
149
- user2.removeAllSocketListeners('update-chat_rooms');
150
- user2.removeAllSocketListeners('deleted-chat_rooms');
151
- user1.subscribe((_a = {}, _a[room.id] = 'chats', _a));
152
- user2.subscribe((_b = {}, _b[room.id] = 'chats', _b)); // connection should be rejected
153
- user1.subscribe((_c = {}, _c[sharedRoom.id] = 'chats', _c));
154
- user2.subscribe((_d = {}, _d[sharedRoom.id] = 'chats', _d));
134
+ _d.sent();
135
+ (0, testing_1.assert)(user1Events.length === 2, 'bad event distribution for filter', 'creator gets socket notifications');
136
+ (0, testing_1.assert)(nonAdminEvents.length === 1 && sharedRoom.id === nonAdminEvents[0].id, 'bad event distribution for filter', 'verify filter socket push');
155
137
  user1.handle_events({
138
+ 'created-chat_rooms': function (rs) { return user1Events.push.apply(user1Events, rs); },
156
139
  'created-chats': function (rs) { return user1Events.push.apply(user1Events, rs); },
140
+ 'created-tickets': function (rs) { return user1Events.push.apply(user1Events, rs); },
141
+ 'created-endusers': function (rs) { return user1Events.push.apply(user1Events, rs); },
157
142
  'updated-chats': function (rs) { return user1Events.push.apply(user1Events, rs); },
158
143
  'deleted-chats': function (rs) { return user1Events.push.apply(user1Events, rs); },
159
144
  });
160
- user2.handle_events({
161
- 'created-chats': function (rs) { return user2Events.push.apply(user2Events, rs); },
162
- 'updated-chats': function (rs) { return user2Events.push.apply(user2Events, rs); },
163
- 'deleted-chats': function (rs) { return user2Events.push.apply(user2Events, rs); },
145
+ sdkNonAdmin.handle_events({
146
+ 'created-chat_rooms': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); },
147
+ 'created-chats': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); },
148
+ 'created-tickets': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); },
149
+ 'created-endusers': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); },
150
+ 'updated-chats': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); },
151
+ 'deleted-chats': function (rs) { return nonAdminEvents.push.apply(nonAdminEvents, rs); },
164
152
  });
165
153
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
166
154
  case 4:
167
- _e.sent();
155
+ _d.sent();
168
156
  return [4 /*yield*/, user1.api.chats.createOne({ roomId: room.id, message: "Hello!", })];
169
157
  case 5:
170
- _e.sent();
158
+ _d.sent();
171
159
  return [4 /*yield*/, user1.api.chats.createOne({ roomId: room.id, message: "Hello...", })];
172
160
  case 6:
173
- _e.sent();
161
+ _d.sent();
174
162
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
175
163
  case 7:
176
- _e.sent();
177
- (0, testing_1.assert)(user1Events.length === 0, 'bad chats subscription', 'verify chats no self');
178
- (0, testing_1.assert)(user2Events.length === 1, 'bad chats subscription', 'push only for valid subscribers');
179
- return [4 /*yield*/, user1.api.chats.createOne({ roomId: sharedRoom.id, message: "Hello!", })];
164
+ _d.sent();
165
+ (0, testing_1.assert)(user1Events.length === 4, 'bad chats self', 'chats to self');
166
+ (0, testing_1.assert)(nonAdminEvents.length === 1, 'non-admin got chats', 'non admin doesnt get chats for unassigned room');
167
+ return [4 /*yield*/, user1.api.chats.createOne({ roomId: sharedRoom.id, message: "Hello from admin on shared", })];
180
168
  case 8:
181
- sharedChat = _e.sent();
182
- return [4 /*yield*/, user2.api.chats.createOne({ roomId: sharedRoom.id, message: "Hello there!", })];
169
+ sharedChat = _d.sent();
170
+ return [4 /*yield*/, sdkNonAdmin.api.chats.createOne({ roomId: sharedRoom.id, message: "Hello from nonadmin on shared", })];
183
171
  case 9:
184
- sharedChat2 = _e.sent();
172
+ sharedChat2 = _d.sent();
185
173
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
186
174
  case 10:
187
- _e.sent();
188
- (0, testing_1.assert)(user1Events.length === 1 && user1Events[0].id === sharedChat2.id, 'bad chats subscription', 'verify chat received');
189
- (0, testing_1.assert)(user2Events.length === 2 && user2Events[1].id === sharedChat.id, 'bad chats subscription', 'push only for valid subscribers shared');
175
+ _d.sent();
176
+ (0, testing_1.assert)(user1Events.length === 6 && !!user1Events.find(function (r) { return (r === null || r === void 0 ? void 0 : r.id) === sharedChat2.id; }), 'bad chats other', 'verify chat received');
177
+ (0, testing_1.assert)(nonAdminEvents.length === 3 && !!nonAdminEvents.find(function (e) { return e.id === sharedChat.id; }), 'bad chats self, non-admin', 'push valid for non-admin default access');
178
+ return [4 /*yield*/, user1.api.endusers.createOne({ email: 'unassigned@tellescope.com' })];
179
+ case 11:
180
+ unassignedEnduser = _d.sent();
181
+ return [4 /*yield*/, user1.api.endusers.createOne({ email: 'assigned@tellescope.com', assignedTo: [user2Id] })];
182
+ case 12:
183
+ assignedEnduser = _d.sent();
184
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
185
+ case 13:
186
+ _d.sent();
187
+ (0, testing_1.assert)(!!user1Events.find(function (e) { return e.id === unassignedEnduser.id; }) && !!user1Events.find(function (e) { return e.id === assignedEnduser.id; }), 'admin did not get endusers', 'admin got assigned and unassigned endusers');
188
+ (0, testing_1.assert)(!nonAdminEvents.find(function (e) { return e.id === unassignedEnduser.id; }) && !!nonAdminEvents.find(function (e) { return e.id === assignedEnduser.id; }), 'non-admin got incorrect endusers', 'non-admin got assigned enduser');
189
+ return [4 /*yield*/, user1.api.endusers.set_password({ id: unassignedEnduser.id, password: 'enduserPassword!' })];
190
+ case 14:
191
+ _d.sent();
192
+ return [4 /*yield*/, enduserSDK.authenticate(unassignedEnduser.email, 'enduserPassword!')];
193
+ case 15:
194
+ _d.sent();
195
+ return [4 /*yield*/, enduserSDK.authenticate_socket()];
196
+ case 16:
197
+ _d.sent();
198
+ enduserSDK.handle_events({
199
+ 'created-chat_rooms': function (rs) { return enduserEvents.push.apply(enduserEvents, rs); },
200
+ 'created-chats': function (rs) { return enduserEvents.push.apply(enduserEvents, rs); },
201
+ 'created-tickets': function (rs) { return enduserEvents.push.apply(enduserEvents, rs); },
202
+ });
203
+ return [4 /*yield*/, user1.api.chat_rooms.createOne({ enduserIds: [unassignedEnduser.id] })
204
+ // test non-admin user in userIds gets message
205
+ ];
206
+ case 17:
207
+ roomUnassigned = _d.sent();
208
+ return [4 /*yield*/, user1.api.chat_rooms.createOne({ enduserIds: [unassignedEnduser.id], userIds: [user2Id] })
209
+ // test non-admin user who is assigned to enduser gets messages
210
+ ];
211
+ case 18:
212
+ roomUnassignedWithUser = _d.sent();
213
+ return [4 /*yield*/, user1.api.chat_rooms.createOne({ enduserIds: [assignedEnduser.id] })];
214
+ case 19:
215
+ roomAssigned = _d.sent();
216
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
217
+ case 20:
218
+ _d.sent();
219
+ (0, testing_1.assert)((!!user1Events.find(function (e) { return e.id === roomUnassigned.id; })
220
+ && !!user1Events.find(function (e) { return e.id === roomUnassignedWithUser.id; })
221
+ && !!user1Events.find(function (e) { return e.id === roomAssigned.id; })), 'enduser did not get chat rooms', 'enduser got chat rooms');
222
+ (0, testing_1.assert)((!nonAdminEvents.find(function (e) { return e.id === roomUnassigned.id; }) // shouldn't get as non-admin
223
+ && !!nonAdminEvents.find(function (e) { return e.id === roomUnassignedWithUser.id; }) // gets for in room
224
+ && !!nonAdminEvents.find(function (e) { return e.id === roomAssigned.id; }) // gets for enduser assignment
225
+ ), 'non-admin did not get chat rooms', 'non-admin got chat rooms');
226
+ (0, testing_1.assert)((!!enduserEvents.find(function (e) { return e.id === roomUnassigned.id; })
227
+ && !!enduserEvents.find(function (e) { return e.id === roomUnassignedWithUser.id; })
228
+ && !enduserEvents.find(function (e) { return e.id === roomAssigned.id; })), 'enduser did not get chat rooms', 'enduser got chat rooms');
229
+ return [4 /*yield*/, user1.api.chats.createOne({ message: 'user unassigned', roomId: roomUnassigned.id })];
230
+ case 21:
231
+ userMessage = _d.sent();
232
+ return [4 /*yield*/, enduserSDK.api.chats.createOne({ message: 'enduseruser unassigned', roomId: roomUnassigned.id })];
233
+ case 22:
234
+ enduserMessage = _d.sent();
235
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
236
+ case 23:
237
+ _d.sent();
238
+ (0, testing_1.assert)(!!enduserEvents.find(function (e) { return e.id === userMessage.id; }), 'enduser did not get message', 'enduser got message from user');
239
+ (0, testing_1.assert)(!!user1Events.find(function (e) { return e.id === enduserMessage.id; }), 'user did not get message', 'user got message from enduser');
240
+ (0, testing_1.assert)(!nonAdminEvents.find(function (e) { return e.id === enduserMessage.id; }) && !nonAdminEvents.find(function (e) { return e.id === userMessage.id; }), 'non-admin got unexpected message', 'non-admin correctly did not get message from enduser or user');
241
+ return [4 /*yield*/, user1.api.chats.createOne({ message: 'user unassigned with user', roomId: roomUnassignedWithUser.id })];
242
+ case 24:
243
+ userMessage = _d.sent();
244
+ return [4 /*yield*/, enduserSDK.api.chats.createOne({ message: 'enduser unassigned with user', roomId: roomUnassignedWithUser.id })];
245
+ case 25:
246
+ enduserMessage = _d.sent();
247
+ return [4 /*yield*/, sdkNonAdmin.api.chats.createOne({ message: 'non-admin unassigned with non', roomId: roomUnassignedWithUser.id })];
248
+ case 26:
249
+ nonAdminMessage = _d.sent();
250
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
251
+ case 27:
252
+ _d.sent();
253
+ (0, testing_1.assert)(!!enduserEvents.find(function (e) { return e.id === userMessage.id; }) && !!enduserEvents.find(function (e) { return e.id === nonAdminMessage.id; }), 'enduser did not get message', 'enduser got message from user');
254
+ (0, testing_1.assert)(!!user1Events.find(function (e) { return e.id === enduserMessage.id; }) && !!user1Events.find(function (e) { return e.id === nonAdminMessage.id; }), 'user did not get messages', 'user got messages');
255
+ (0, testing_1.assert)(!!nonAdminEvents.find(function (e) { return e.id === enduserMessage.id; }) && !!nonAdminEvents.find(function (e) { return e.id === userMessage.id; }), 'non-admin didnt get messages', 'non-admin got message from user and enduser');
256
+ return [4 /*yield*/, user1.api.endusers.set_password({ id: assignedEnduser.id, password: 'enduserPassword!' })];
257
+ case 28:
258
+ _d.sent();
259
+ return [4 /*yield*/, enduserSDK.authenticate(assignedEnduser.email, 'enduserPassword!')];
260
+ case 29:
261
+ _d.sent();
262
+ return [4 /*yield*/, enduserSDK.authenticate_socket()];
263
+ case 30:
264
+ _d.sent();
265
+ enduserSDK.handle_events({
266
+ 'created-chats': function (rs) { return enduserEvents.push.apply(enduserEvents, rs); },
267
+ });
268
+ return [4 /*yield*/, user1.api.chats.createOne({ message: 'user assigned', roomId: roomAssigned.id })];
269
+ case 31:
270
+ userMessage = _d.sent();
271
+ return [4 /*yield*/, enduserSDK.api.chats.createOne({ message: 'enduser assigned', roomId: roomAssigned.id })];
272
+ case 32:
273
+ enduserMessage = _d.sent();
274
+ return [4 /*yield*/, sdkNonAdmin.api.chats.createOne({ message: 'non-admin assigned', roomId: roomAssigned.id })];
275
+ case 33:
276
+ nonAdminMessage = _d.sent();
277
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
278
+ case 34:
279
+ _d.sent();
280
+ (0, testing_1.assert)(!!enduserEvents.find(function (e) { return e.id === userMessage.id; }) && !!enduserEvents.find(function (e) { return e.id === nonAdminMessage.id; }), 'enduser did not get messages', 'enduser got messages from users');
281
+ (0, testing_1.assert)(!!user1Events.find(function (e) { return e.id === enduserMessage.id; }) && !!user1Events.find(function (e) { return e.id === nonAdminMessage.id; }), 'user did not get messages', 'user got messages');
282
+ (0, testing_1.assert)(!!nonAdminEvents.find(function (e) { return e.id === enduserMessage.id; }) && !!nonAdminEvents.find(function (e) { return e.id === userMessage.id; }), 'non-admin didnt get messages', 'non-admin got message from user and enduser');
283
+ _b = (_a = Promise).all;
284
+ return [4 /*yield*/, user1.api.endusers.deleteOne(unassignedEnduser.id)];
285
+ case 35:
286
+ _c = [
287
+ _d.sent()
288
+ ];
289
+ return [4 /*yield*/, user1.api.endusers.deleteOne(assignedEnduser.id)];
290
+ case 36:
291
+ _c = _c.concat([
292
+ _d.sent()
293
+ ]);
294
+ return [4 /*yield*/, user1.api.chat_rooms.deleteOne(roomAssigned.id)];
295
+ case 37:
296
+ _c = _c.concat([
297
+ _d.sent()
298
+ ]);
299
+ return [4 /*yield*/, user1.api.chat_rooms.deleteOne(roomUnassigned.id)];
300
+ case 38:
301
+ _c = _c.concat([
302
+ _d.sent()
303
+ ]);
304
+ return [4 /*yield*/, user1.api.chat_rooms.deleteOne(roomUnassignedWithUser.id)];
305
+ case 39: return [4 /*yield*/, _b.apply(_a, [_c.concat([
306
+ _d.sent()
307
+ ])])];
308
+ case 40:
309
+ _d.sent();
190
310
  return [2 /*return*/];
191
311
  }
192
312
  });
193
313
  }); };
194
314
  var enduser_tests = function () { return __awaiter(void 0, void 0, void 0, function () {
195
315
  var enduser, userEvents, enduserEvents, room, messageToEnduser, messageToUser, unusedTicket, ticketForEnduser, ticketFromEnduser;
196
- var _a, _b;
197
- return __generator(this, function (_c) {
198
- switch (_c.label) {
316
+ return __generator(this, function (_a) {
317
+ switch (_a.label) {
199
318
  case 0:
200
319
  (0, testing_1.log_header)("Enduser Tests");
201
320
  return [4 /*yield*/, user1.api.endusers.createOne({ email: "enduser@tellescope.com" })];
202
321
  case 1:
203
- enduser = _c.sent();
322
+ enduser = _a.sent();
204
323
  return [4 /*yield*/, user1.api.endusers.set_password({ id: enduser.id, password: 'enduserPassword!' })];
205
324
  case 2:
206
- _c.sent();
325
+ _a.sent();
207
326
  return [4 /*yield*/, enduserSDK.authenticate(enduser.email, 'enduserPassword!')];
208
327
  case 3:
209
- _c.sent();
328
+ _a.sent();
210
329
  return [4 /*yield*/, enduserSDK.connectSocket()];
211
330
  case 4:
212
- _c.sent();
331
+ _a.sent();
213
332
  userEvents = [];
214
333
  enduserEvents = [];
215
334
  user1.handle_events({
@@ -226,59 +345,53 @@ var enduser_tests = function () { return __awaiter(void 0, void 0, void 0, funct
226
345
  enduserIds: [enduser.id],
227
346
  })];
228
347
  case 5:
229
- room = _c.sent();
230
- user1.subscribe((_a = {}, _a[room.id] = 'chats', _a));
231
- user1.subscribe({ tickets: 'tickets' });
232
- enduserSDK.subscribe((_b = {},
233
- _b[room.id] = 'chats',
234
- _b.dontCache = 'chats',
235
- _b));
348
+ room = _a.sent();
236
349
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
237
350
  case 6:
238
- _c.sent();
351
+ _a.sent();
239
352
  return [4 /*yield*/, user1.api.chats.createOne({ roomId: room.id, message: "Hello!" })];
240
353
  case 7:
241
- messageToEnduser = _c.sent();
354
+ messageToEnduser = _a.sent();
242
355
  return [4 /*yield*/, enduserSDK.api.chats.createOne({ roomId: room.id, message: "Hello right back!" })];
243
356
  case 8:
244
- messageToUser = _c.sent();
357
+ messageToUser = _a.sent();
245
358
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
246
359
  case 9:
247
- _c.sent();
248
- (0, testing_1.assert)((0, utilities_1.objects_equivalent)(userEvents[0], messageToUser), 'no message on socket', 'push message to user');
249
- (0, testing_1.assert)((0, utilities_1.objects_equivalent)(enduserEvents[0], messageToEnduser), 'no message on socket', 'push message to enduser');
360
+ _a.sent();
361
+ (0, testing_1.assert)(!!userEvents.find(function (e) { return e.id === messageToUser.id; }), 'no message on socket for user', 'push message to user');
362
+ (0, testing_1.assert)(!!enduserEvents.find(function (e) { return e.id === messageToEnduser.id; }), 'no message on socket for enduser', 'push message to enduser');
250
363
  return [4 /*yield*/, user1.api.tickets.createOne({ enduserId: constants_1.PLACEHOLDER_ID, title: "For Noone" })]; // should not get pushed to enduser
251
364
  case 10:
252
- unusedTicket = _c.sent() // should not get pushed to enduser
365
+ unusedTicket = _a.sent() // should not get pushed to enduser
253
366
  ;
254
367
  return [4 /*yield*/, user1.api.tickets.createOne({ enduserId: enduser.id, title: "For enduser" })];
255
368
  case 11:
256
- ticketForEnduser = _c.sent();
369
+ ticketForEnduser = _a.sent();
257
370
  return [4 /*yield*/, enduserSDK.api.tickets.createOne({ enduserId: enduser.id, title: "By enduser" })];
258
371
  case 12:
259
- ticketFromEnduser = _c.sent();
372
+ ticketFromEnduser = _a.sent();
260
373
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
261
374
  case 13:
262
- _c.sent();
263
- (0, testing_1.assert)((0, utilities_1.objects_equivalent)(userEvents[1], ticketFromEnduser), 'no ticket on socket for user', 'push ticket to user');
264
- (0, testing_1.assert)((0, utilities_1.objects_equivalent)(enduserEvents[1], ticketForEnduser), 'no ticket on socket for enduser', 'push ticket to enduser');
265
- (0, testing_1.assert)(enduserEvents[2] === undefined, 'enduser got an orgwide ticket', 'enduser does not receive org-wide ticket');
375
+ _a.sent();
376
+ (0, testing_1.assert)(!!userEvents.find(function (t) { return t.id === ticketFromEnduser.id; }), 'no ticket on socket for user', 'push ticket to user');
377
+ (0, testing_1.assert)(!!enduserEvents.find(function (t) { return t.id === ticketForEnduser.id; }), 'no ticket on socket for enduser', 'push ticket to enduser');
378
+ (0, testing_1.assert)(!enduserEvents.find(function (t) { return t.id === unusedTicket.id; }), 'enduser got an orgwide ticket', 'enduser does not receive org-wide ticket');
266
379
  return [4 /*yield*/, user1.api.tickets.deleteOne(unusedTicket.id)];
267
380
  case 14:
268
- _c.sent();
381
+ _a.sent();
269
382
  return [4 /*yield*/, user1.api.tickets.deleteOne(ticketForEnduser.id)];
270
383
  case 15:
271
- _c.sent();
384
+ _a.sent();
272
385
  return [4 /*yield*/, user1.api.tickets.deleteOne(ticketFromEnduser.id)
273
386
  // test enduser logout
274
387
  ];
275
388
  case 16:
276
- _c.sent();
389
+ _a.sent();
277
390
  // test enduser logout
278
391
  return [4 /*yield*/, enduserSDK.api.endusers.logout()];
279
392
  case 17:
280
393
  // test enduser logout
281
- _c.sent();
394
+ _a.sent();
282
395
  return [4 /*yield*/, (0, testing_1.async_test)("verify enduser logout works", function () { return enduserSDK.api.chats.getOne({}); }, { shouldError: true, onError: function (e) { return e === 'Unauthenticated'; } }
283
396
  // { shouldError: true, onError: (e: string) => !!e }
284
397
  )
@@ -289,7 +402,7 @@ var enduser_tests = function () { return __awaiter(void 0, void 0, void 0, funct
289
402
  // await user1.api.chats.deleteOne(messageToUser.id)
290
403
  ];
291
404
  case 18:
292
- _c.sent();
405
+ _a.sent();
293
406
  return [2 /*return*/];
294
407
  }
295
408
  });
@@ -299,89 +412,86 @@ var SESSION_TIMEOUT_DELAY = 4000; // ms
299
412
  var deauthentication_tests = function (byTimeout) {
300
413
  if (byTimeout === void 0) { byTimeout = false; }
301
414
  return __awaiter(void 0, void 0, void 0, function () {
302
- var enduser, room, userEvents, enduserEvents;
303
- var _a, _b;
304
- return __generator(this, function (_c) {
305
- switch (_c.label) {
415
+ var enduser, room, userEvents, enduserEvents, badChatEnduser, badChat;
416
+ return __generator(this, function (_a) {
417
+ switch (_a.label) {
306
418
  case 0:
307
419
  (0, testing_1.log_header)("Unauthenticated Tests ".concat(byTimeout ? '- With Timeout, requires Worker' : '- With Manual Logout'));
308
420
  return [4 /*yield*/, user1.api.endusers.createOne({ email: "socketenduser@tellescope.com" })];
309
421
  case 1:
310
- enduser = _c.sent();
422
+ enduser = _a.sent();
311
423
  return [4 /*yield*/, user1.api.endusers.set_password({ id: enduser.id, password: 'enduserPassword!' })];
312
424
  case 2:
313
- _c.sent();
425
+ _a.sent();
314
426
  return [4 /*yield*/, enduserSDK.authenticate(enduser.email, 'enduserPassword!', { durationInSeconds: byTimeout ? TEST_SESSION_DURATION : undefined })];
315
427
  case 3:
316
- _c.sent();
428
+ _a.sent();
317
429
  return [4 /*yield*/, user1.api.chat_rooms.createOne({
318
430
  type: 'external',
319
431
  userIds: [user1.userInfo.id],
320
432
  enduserIds: [enduser.id],
321
433
  })];
322
434
  case 4:
323
- room = _c.sent();
435
+ room = _a.sent();
324
436
  userEvents = [];
325
437
  enduserEvents = [];
326
- user1.subscribe((_a = {}, _a[room.id] = 'chats', _a));
327
- enduserSDK.subscribe((_b = {}, _b[room.id] = 'chats', _b));
328
438
  user1.handle_events({ 'created-chats': function (rs) { return userEvents.push.apply(userEvents, rs); } });
329
439
  enduserSDK.handle_events({ 'created-chats': function (rs) { return enduserEvents.push.apply(enduserEvents, rs); } });
330
440
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
331
441
  case 5:
332
- _c.sent();
442
+ _a.sent();
333
443
  if (!!byTimeout) return [3 /*break*/, 7];
334
444
  return [4 /*yield*/, enduserSDK.api.endusers.logout()];
335
445
  case 6:
336
- _c.sent();
446
+ _a.sent();
337
447
  return [3 /*break*/, 9];
338
448
  case 7: return [4 /*yield*/, (0, testing_1.wait)(undefined, TEST_SESSION_DURATION * 1000 + SESSION_TIMEOUT_DELAY)];
339
449
  case 8:
340
- _c.sent();
341
- _c.label = 9;
450
+ _a.sent();
451
+ _a.label = 9;
342
452
  case 9: return [4 /*yield*/, user1.api.chats.createOne({ roomId: room.id, message: "Hello!" })];
343
453
  case 10:
344
- _c.sent();
454
+ badChatEnduser = _a.sent();
345
455
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
346
456
  case 11:
347
- _c.sent();
348
- (0, testing_1.assert)((0, utilities_1.objects_equivalent)(enduserEvents[0], undefined), 'enduser got message after logout on socket', 'enduser logged out');
457
+ _a.sent();
458
+ (0, testing_1.assert)(enduserEvents.find(function (c) { return c.id === badChatEnduser.id; }) === undefined, 'enduser got message after logout on socket', 'enduser logged out');
349
459
  // re-authenticate enduser to send message to user
350
460
  return [4 /*yield*/, enduserSDK.authenticate(enduser.email, 'enduserPassword!')
351
461
  // ensure user logged out appropriately for not receiving message
352
462
  ];
353
463
  case 12:
354
464
  // re-authenticate enduser to send message to user
355
- _c.sent();
465
+ _a.sent();
356
466
  // ensure user logged out appropriately for not receiving message
357
467
  return [4 /*yield*/, user1.logout()];
358
468
  case 13:
359
469
  // ensure user logged out appropriately for not receiving message
360
- _c.sent();
470
+ _a.sent();
361
471
  if (!byTimeout) return [3 /*break*/, 16];
362
472
  return [4 /*yield*/, user1.authenticate(email, password, { expirationInSeconds: byTimeout ? TEST_SESSION_DURATION : undefined })];
363
473
  case 14:
364
- _c.sent();
474
+ _a.sent();
365
475
  return [4 /*yield*/, (0, testing_1.wait)(undefined, TEST_SESSION_DURATION * 1000 + SESSION_TIMEOUT_DELAY)];
366
476
  case 15:
367
- _c.sent();
477
+ _a.sent();
368
478
  return [3 /*break*/, 18];
369
479
  case 16: return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
370
480
  case 17:
371
- _c.sent();
372
- _c.label = 18;
481
+ _a.sent();
482
+ _a.label = 18;
373
483
  case 18: return [4 /*yield*/, enduserSDK.api.chats.createOne({ roomId: room.id, message: "Hello right back!" })];
374
484
  case 19:
375
- _c.sent();
485
+ badChat = _a.sent();
376
486
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
377
487
  case 20:
378
- _c.sent();
379
- (0, testing_1.assert)((0, utilities_1.objects_equivalent)(userEvents[0], undefined), 'user got message after logout', 'user logged out');
488
+ _a.sent();
489
+ (0, testing_1.assert)(userEvents.find(function (e) { return e.id === badChat.id; }) === undefined, 'user got message after logout', 'user logged out');
380
490
  // must come before cleanup, so cleanup works
381
491
  return [4 /*yield*/, user1.authenticate(email, password)];
382
492
  case 21:
383
493
  // must come before cleanup, so cleanup works
384
- _c.sent();
494
+ _a.sent();
385
495
  // cleanup
386
496
  return [4 /*yield*/, Promise.all([
387
497
  user1.api.endusers.deleteOne(enduser.id),
@@ -390,7 +500,7 @@ var deauthentication_tests = function (byTimeout) {
390
500
  case 22:
391
501
  // must come before cleanup, so cleanup works
392
502
  // cleanup
393
- _c.sent();
503
+ _a.sent();
394
504
  return [2 /*return*/];
395
505
  }
396
506
  });
@@ -458,7 +568,7 @@ var calendar_events = function () { return __awaiter(void 0, void 0, void 0, fun
458
568
  return [4 /*yield*/, (0, testing_1.wait)(undefined, AWAIT_SOCKET_DURATION)];
459
569
  case 6:
460
570
  _a.sent();
461
- (0, testing_1.assert)(userEvents.length === 0, 'creator got calendar event', 'calendar event not gone to creator');
571
+ (0, testing_1.assert)(userEvents.length === 1, 'creator push bad', 'calendar event gone to creator');
462
572
  (0, testing_1.assert)(enduserEvents.length === 1 && enduserEvents[0].id === event.id, 'enduser did not get calendar event', 'calendar event on create for attending enduser');
463
573
  // cleanup
464
574
  return [4 /*yield*/, user1.api.endusers.deleteOne(enduser.id)];
@@ -477,7 +587,7 @@ var calendar_events = function () { return __awaiter(void 0, void 0, void 0, fun
477
587
  (0, testing_1.log_header)("Sockets");
478
588
  _a.label = 1;
479
589
  case 1:
480
- _a.trys.push([1, 14, , 15]);
590
+ _a.trys.push([1, 16, , 17]);
481
591
  return [4 /*yield*/, user1.authenticate(email, password)];
482
592
  case 2:
483
593
  _a.sent();
@@ -487,39 +597,45 @@ var calendar_events = function () { return __awaiter(void 0, void 0, void 0, fun
487
597
  return [4 /*yield*/, user2.authenticate(email2, password2)]; // generate authToken + socket connection for API keyj
488
598
  case 4:
489
599
  _a.sent(); // generate authToken + socket connection for API keyj
490
- return [4 /*yield*/, user1.connectSocket()];
600
+ return [4 /*yield*/, sdkNonAdmin.authenticate(nonAdminEmail, nonAdminPassword)];
491
601
  case 5:
492
602
  _a.sent();
493
- return [4 /*yield*/, user2.connectSocket()];
603
+ return [4 /*yield*/, user1.connectSocket()];
494
604
  case 6:
495
605
  _a.sent();
496
- return [4 /*yield*/, basic_tests()];
606
+ return [4 /*yield*/, user2.connectSocket()];
497
607
  case 7:
498
608
  _a.sent();
499
- return [4 /*yield*/, access_tests()];
609
+ return [4 /*yield*/, sdkNonAdmin.connectSocket()];
500
610
  case 8:
501
611
  _a.sent();
502
- return [4 /*yield*/, calendar_events()];
612
+ return [4 /*yield*/, basic_tests()];
503
613
  case 9:
504
614
  _a.sent();
505
- return [4 /*yield*/, enduser_tests()];
615
+ return [4 /*yield*/, access_tests()];
506
616
  case 10:
507
617
  _a.sent();
508
- return [4 /*yield*/, (0, exports.notification_tests)()];
618
+ return [4 /*yield*/, calendar_events()];
509
619
  case 11:
510
620
  _a.sent();
511
- return [4 /*yield*/, deauthentication_tests()]; // should come last!
621
+ return [4 /*yield*/, enduser_tests()];
512
622
  case 12:
623
+ _a.sent();
624
+ return [4 /*yield*/, (0, exports.notification_tests)()];
625
+ case 13:
626
+ _a.sent();
627
+ return [4 /*yield*/, deauthentication_tests()]; // should come last!
628
+ case 14:
513
629
  _a.sent(); // should come last!
514
630
  return [4 /*yield*/, deauthentication_tests(true)]; // should come last!
515
- case 13:
631
+ case 15:
516
632
  _a.sent(); // should come last!
517
- return [3 /*break*/, 15];
518
- case 14:
633
+ return [3 /*break*/, 17];
634
+ case 16:
519
635
  err_1 = _a.sent();
520
636
  console.error(err_1);
521
- return [3 /*break*/, 15];
522
- case 15:
637
+ return [3 /*break*/, 17];
638
+ case 17:
523
639
  process.exit();
524
640
  return [2 /*return*/];
525
641
  }