@tiledesk/tiledesk-server 2.10.14 → 2.10.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/app.js +2 -1
  3. package/models/request.js +8 -0
  4. package/package.json +4 -3
  5. package/pubmodules/activities/test/activityRoute.js +6 -2
  6. package/pubmodules/events/test/eventRoute.js +7 -3
  7. package/pubmodules/pubModulesManager.js +24 -0
  8. package/pubmodules/voice-twilio/index.js +6 -0
  9. package/pubmodules/voice-twilio/listener.js +59 -0
  10. package/routes/campaigns.js +1 -1
  11. package/routes/files.js +6 -4
  12. package/routes/images.js +0 -2
  13. package/routes/kb.js +7 -1
  14. package/routes/request.js +10 -0
  15. package/routes/users.js +2 -2
  16. package/services/fileGridFsService.js +12 -10
  17. package/services/requestService.js +2 -1
  18. package/test/app-test.js +36 -1
  19. package/test/authentication.js +662 -796
  20. package/test/authenticationJwt.js +213 -315
  21. package/test/authorization.js +53 -72
  22. package/test/campaignsRoute.js +42 -47
  23. package/test/cannedRoute.js +30 -16
  24. package/test/departmentService.js +222 -274
  25. package/test/example.json +31 -1
  26. package/test/faqRoute.js +713 -622
  27. package/test/faqService.js +124 -159
  28. package/test/faqkbRoute.js +128 -100
  29. package/test/fileRoute.js +50 -46
  30. package/test/imageRoute.js +263 -254
  31. package/test/jwtRoute.js +128 -153
  32. package/test/kbRoute.js +40 -17
  33. package/test/kbsettingsRoute.js +78 -54
  34. package/test/keysRoute.js +6 -7
  35. package/test/labelRoute.js +591 -696
  36. package/test/labelService.js +40 -47
  37. package/test/leadService.js +100 -115
  38. package/test/logsRoute.js +13 -7
  39. package/test/messageRootRoute.js +112 -102
  40. package/test/messageRoute.js +1171 -1419
  41. package/test/messageService.js +41 -43
  42. package/test/openaiRoute.js +5 -1
  43. package/test/projectRoute.js +23 -4
  44. package/test/projectService.js +3 -1
  45. package/test/quoteManager.js +36 -13
  46. package/test/requestRoute.js +103 -72
  47. package/test/requestService.js +51 -51
  48. package/test/userRoute.js +37 -8
  49. package/test/userService.js +34 -31
  50. package/utils/promiseUtil.js +1 -1
@@ -21,366 +21,275 @@ var jwt = require('jsonwebtoken');
21
21
  var config = require('../config/database'); // get db config file
22
22
  var faqService = require('../services/faqService');
23
23
 
24
+ let log = false;
24
25
 
25
26
  chai.use(chaiHttp);
26
27
 
27
28
  describe('AuthenticationJWT', () => {
28
29
 
30
+ it('signinJWt-userNoAudNoSubject', (done) => {
29
31
 
32
+ var email = "test-signup-" + Date.now() + "@email.com";
33
+ var pwd = "pwd";
30
34
 
35
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
36
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
31
37
 
38
+ var jwtToken = jwt.sign(savedUser.toObject(), config.secret);
39
+ if (log) { console.log("jwtToken", jwtToken); }
32
40
 
33
- it('signinJWt-userNoAudNoSubject', (done) => {
41
+ chai.request(server)
42
+ .get('/' + savedProject._id + '/requests')
43
+ .set('Authorization', 'JWT ' + jwtToken)
44
+ .send()
45
+ .end((err, res) => {
34
46
 
35
-
36
- // this.timeout();
47
+ if (err) { console.error("err: ", err); }
48
+ if (log) { console.log("res.body", res.body); }
37
49
 
38
- var email = "test-signup-" + Date.now() + "@email.com";
39
- var pwd = "pwd";
50
+ res.should.have.status(200);
40
51
 
41
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
42
- // create(name, createdBy, settings)
43
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
44
-
45
-
52
+ done();
53
+ });
54
+ });
55
+ });
56
+ });
46
57
 
47
- var jwtToken = jwt.sign(savedUser.toObject(), config.secret);
48
-
49
-
50
-
51
- console.log("jwtToken", jwtToken);
52
- chai.request(server)
53
- .get('/'+ savedProject._id + '/requests')
54
- .set('Authorization', 'JWT '+jwtToken)
55
- .send()
56
- .end((err, res) => {
57
- console.log("res.body", res.body);
58
- res.should.have.status(200);
59
-
60
- done();
61
- });
62
58
 
63
-
64
-
65
-
66
- });
59
+ it('signinJWt-userYESAudNoSubject', (done) => {
67
60
 
68
-
69
- });
70
- });
61
+ var email = "test-signup-" + Date.now() + "@email.com";
62
+ var pwd = "pwd";
71
63
 
64
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
65
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
72
66
 
67
+ var savedUserObj = savedUser.toObject();
68
+ if (log) { console.log("savedUserObj", savedUserObj); }
73
69
 
70
+ var signOptions = {
71
+ // subject: 'user',
72
+ audience: 'https://tiledesk.com',
73
+ };
74
74
 
75
75
 
76
+ var jwtToken = jwt.sign(savedUserObj, config.secret, signOptions);
77
+ if (log) { console.log("jwtToken", jwtToken); }
76
78
 
79
+ chai.request(server)
80
+ .get('/' + savedProject._id + '/requests')
81
+ .set('Authorization', 'JWT ' + jwtToken)
82
+ .send()
83
+ .end((err, res) => {
77
84
 
78
- it('signinJWt-userYESAudNoSubject', (done) => {
85
+ if (err) { console.error("err: ", err); }
86
+ if (log) { console.log("res.body", res.body); }
79
87
 
80
-
81
- // this.timeout();
88
+ res.should.have.status(200);
82
89
 
83
- var email = "test-signup-" + Date.now() + "@email.com";
84
- var pwd = "pwd";
90
+ done();
91
+ });
92
+ });
93
+ });
94
+ });
95
+
85
96
 
86
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
87
- // create(name, createdBy, settings)
88
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
89
-
90
- var savedUserObj = savedUser.toObject();
91
- console.log("savedUserObj", savedUserObj);
92
-
93
-
94
- var signOptions = {
95
- // subject: 'user',
96
- audience: 'https://tiledesk.com',
97
- };
98
-
99
-
100
- var jwtToken = jwt.sign(savedUserObj, config.secret,signOptions);
101
-
102
-
103
-
104
- console.log("jwtToken", jwtToken);
105
- chai.request(server)
106
- .get('/'+ savedProject._id + '/requests')
107
- .set('Authorization', 'JWT '+jwtToken)
108
- .send()
109
- .end((err, res) => {
110
- console.log("res.body", res.body);
111
- res.should.have.status(200);
112
-
113
- done();
114
- });
115
97
 
116
-
117
-
118
-
119
- });
98
+ it('signinJWt-userYESAudYesSubject', (done) => {
120
99
 
121
-
122
- });
123
- });
124
-
100
+ var email = "test-signup-" + Date.now() + "@email.com";
101
+ var pwd = "pwd";
125
102
 
103
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
104
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
126
105
 
127
- it('signinJWt-userYESAudYesSubject', (done) => {
106
+ var savedUserObj = savedUser.toObject();
107
+ if (log) { console.log("savedUserObj", savedUserObj); }
128
108
 
129
-
130
- // this.timeout();
131
-
132
- var email = "test-signup-" + Date.now() + "@email.com";
133
- var pwd = "pwd";
134
-
135
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
136
- // create(name, createdBy, settings)
137
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
138
-
139
- var savedUserObj = savedUser.toObject();
140
- console.log("savedUserObj", savedUserObj);
141
-
142
-
143
- var signOptions = {
144
- subject: 'user',
145
- audience: 'https://tiledesk.com',
146
- };
147
-
148
-
149
- var jwtToken = jwt.sign(savedUserObj, config.secret,signOptions);
150
-
151
-
152
-
153
- console.log("jwtToken", jwtToken);
154
- chai.request(server)
155
- .get('/'+ savedProject._id + '/requests')
156
- .set('Authorization', 'JWT '+jwtToken)
157
- .send()
158
- .end((err, res) => {
159
- console.log("res.body", res.body);
160
- res.should.have.status(200);
161
-
162
- done();
163
- });
164
-
165
-
166
-
167
-
168
- });
169
-
170
-
171
- });
172
- });
109
+ var signOptions = {
110
+ subject: 'user',
111
+ audience: 'https://tiledesk.com',
112
+ };
173
113
 
114
+ var jwtToken = jwt.sign(savedUserObj, config.secret, signOptions);
115
+ if (log) { console.log("jwtToken", jwtToken); }
174
116
 
117
+ chai.request(server)
118
+ .get('/' + savedProject._id + '/requests')
119
+ .set('Authorization', 'JWT ' + jwtToken)
120
+ .send()
121
+ .end((err, res) => {
175
122
 
123
+ if (err) { console.error("err: ", err); }
124
+ if (log) { console.log("res.body", res.body); }
176
125
 
126
+ res.should.have.status(200);
177
127
 
128
+ done();
129
+ });
130
+ });
131
+ });
132
+ });
178
133
 
179
134
 
180
135
  it('signinJWt-Project-user-YESAudNoSubject', (done) => {
181
136
 
137
+ var email = "test-signup-" + Date.now() + "@email.com";
138
+ var pwd = "pwd";
182
139
 
183
- // this.timeout();
184
-
185
- var email = "test-signup-" + Date.now() + "@email.com";
186
- var pwd = "pwd";
187
-
188
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
189
- // create(name, createdBy, settings)
190
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
191
-
192
- chai.request(server)
193
- .post('/'+ savedProject._id + '/keys/generate')
140
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
141
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
142
+
143
+ chai.request(server)
144
+ .post('/' + savedProject._id + '/keys/generate')
194
145
  .auth(email, pwd)
195
146
  .send()
196
147
  .end((err, res) => {
197
- //console.log("res", res);
198
- console.log("res.body", res.body);
148
+
149
+ if (err) { console.error("err: ", err); }
150
+ if (log) { console.log("res.body", res.body); }
151
+
199
152
  res.should.have.status(200);
200
153
  res.body.should.be.a('object');
201
- expect(res.body.jwtSecret).to.not.equal(null);
202
-
203
- var savedUserObj = savedUser.toObject();
204
- console.log("savedUserObj", savedUserObj);
154
+ expect(res.body.jwtSecret).to.not.equal(null);
205
155
 
156
+ var savedUserObj = savedUser.toObject();
157
+ if (log) { console.log("savedUserObj", savedUserObj); }
206
158
 
207
- var signOptions = {
159
+ var signOptions = {
208
160
  // subject: 'user',
209
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
210
- };
211
-
212
-
213
- var jwtToken = jwt.sign(savedUserObj, res.body.jwtSecret,signOptions);
214
-
215
-
216
-
217
- console.log("jwtToken", jwtToken);
218
- chai.request(server)
219
- .get('/'+ savedProject._id + '/requests')
220
- .set('Authorization', 'JWT '+jwtToken)
221
- .send()
222
- .end((err, res) => {
223
- console.log("res.body", res.body);
224
- res.should.have.status(200);
225
-
226
- done();
227
- });
228
-
229
-
230
-
231
-
232
- });
161
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
162
+ };
233
163
 
164
+ var jwtToken = jwt.sign(savedUserObj, res.body.jwtSecret, signOptions);
165
+ if (log) { console.log("jwtToken", jwtToken); }
234
166
 
167
+ chai.request(server)
168
+ .get('/' + savedProject._id + '/requests')
169
+ .set('Authorization', 'JWT ' + jwtToken)
170
+ .send()
171
+ .end((err, res) => {
235
172
 
173
+ if (err) { console.error("err: ", err); }
174
+ if (log) { console.log("res.body", res.body); }
236
175
 
176
+ res.should.have.status(200);
237
177
 
178
+ done();
179
+ });
238
180
  });
239
-
240
-
241
- });
242
- });
181
+ });
182
+ });
183
+ });
243
184
 
244
185
 
245
186
 
246
187
 
247
188
  it('signinJWt-Project-user-YESAudYesSubject', (done) => {
248
189
 
190
+ var email = "test-signup-" + Date.now() + "@email.com";
191
+ var pwd = "pwd";
249
192
 
250
- // this.timeout();
251
-
252
- var email = "test-signup-" + Date.now() + "@email.com";
253
- var pwd = "pwd";
254
-
255
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
256
- // create(name, createdBy, settings)
257
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
258
-
259
- chai.request(server)
260
- .post('/'+ savedProject._id + '/keys/generate')
193
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
194
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
195
+
196
+ chai.request(server)
197
+ .post('/' + savedProject._id + '/keys/generate')
261
198
  .auth(email, pwd)
262
199
  .send()
263
200
  .end((err, res) => {
264
- //console.log("res", res);
265
- console.log("res.body", res.body);
266
- res.should.have.status(200);
267
- res.body.should.be.a('object');
268
- expect(res.body.jwtSecret).to.not.equal(null);
269
-
270
- var savedUserObj = savedUser.toObject();
271
- console.log("savedUserObj", savedUserObj);
272
201
 
202
+ if (err) { console.error("err: ", err); }
203
+ if (log) { console.log("res.body", res.body); }
273
204
 
274
- var signOptions = {
275
- subject: 'user',
276
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
277
- };
278
-
205
+ res.should.have.status(200);
206
+ res.body.should.be.a('object');
207
+ expect(res.body.jwtSecret).to.not.equal(null);
279
208
 
280
- var jwtToken = jwt.sign(savedUserObj, res.body.jwtSecret,signOptions);
209
+ var savedUserObj = savedUser.toObject();
210
+ if (log) { console.log("savedUserObj", savedUserObj); }
281
211
 
282
-
283
-
284
- console.log("jwtToken", jwtToken);
285
- chai.request(server)
286
- .get('/'+ savedProject._id + '/requests')
287
- .set('Authorization', 'JWT '+jwtToken)
288
- .send()
289
- .end((err, res) => {
290
- console.log("res.body", res.body);
291
- res.should.have.status(200);
292
-
293
- done();
294
- });
212
+ var signOptions = {
213
+ subject: 'user',
214
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
215
+ };
295
216
 
296
-
297
-
217
+ var jwtToken = jwt.sign(savedUserObj, res.body.jwtSecret, signOptions);
218
+ if (log) { console.log("jwtToken", jwtToken); }
298
219
 
299
- });
300
-
220
+ chai.request(server)
221
+ .get('/' + savedProject._id + '/requests')
222
+ .set('Authorization', 'JWT ' + jwtToken)
223
+ .send()
224
+ .end((err, res) => {
301
225
 
226
+ if (err) { console.error("err: ", err); }
227
+ if (log) { console.log("res.body", res.body); }
302
228
 
229
+ res.should.have.status(200);
303
230
 
304
-
305
- });
306
-
307
-
231
+ done();
232
+ });
308
233
  });
309
- });
234
+ });
235
+ });
236
+ });
310
237
 
311
238
 
312
-
313
239
  it('signinJWt-Project-external-user-YESAudYesSubject', (done) => {
314
240
 
315
241
 
316
242
  // this.timeout();
317
-
318
- var email = "test-signup-" + Date.now() + "@email.com";
319
- var pwd = "pwd";
320
-
321
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
322
- // create(name, createdBy, settings)
323
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
324
-
325
- chai.request(server)
326
- .post('/'+ savedProject._id + '/keys/generate')
243
+
244
+ var email = "test-signup-" + Date.now() + "@email.com";
245
+ var pwd = "pwd";
246
+
247
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
248
+ // create(name, createdBy, settings)
249
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
250
+
251
+ chai.request(server)
252
+ .post('/' + savedProject._id + '/keys/generate')
327
253
  .auth(email, pwd)
328
254
  .send()
329
255
  .end((err, res) => {
330
- //console.log("res", res);
331
- console.log("res.body", res.body);
256
+
257
+ if (err) { console.error("err: ", err); }
258
+ if (log) { console.log("res.body", res.body); }
259
+
332
260
  res.should.have.status(200);
333
261
  res.body.should.be.a('object');
334
- expect(res.body.jwtSecret).to.not.equal(null);
335
-
262
+ expect(res.body.jwtSecret).to.not.equal(null);
336
263
 
337
- var externalUserObj = {_id:"123",name:"andrea", surname:"leo"};
338
-
339
- console.log("externalUserObj", externalUserObj);
340
264
 
265
+ var externalUserObj = { _id: "123", name: "andrea", surname: "leo" };
266
+ if (log) { console.log("externalUserObj", externalUserObj); }
341
267
 
342
- var signOptions = {
343
- subject: 'userexternal',
344
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
345
- };
268
+ var signOptions = {
269
+ subject: 'userexternal',
270
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
271
+ };
346
272
 
273
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
274
+ if (log) { console.log("jwtToken", jwtToken); }
347
275
 
348
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
276
+ chai.request(server)
277
+ .get('/testauth/noentitycheck')
278
+ .set('Authorization', 'JWT ' + jwtToken)
279
+ .send()
280
+ .end((err, res) => {
349
281
 
350
-
351
-
352
- console.log("jwtToken", jwtToken);
353
-
354
- chai.request(server)
355
- .get('/testauth/noentitycheck')
356
- .set('Authorization', 'JWT '+jwtToken)
357
- .send()
358
- .end((err, res) => {
359
- console.log("res.body", res.body);
360
- res.should.have.status(200);
361
-
362
- done();
363
- });
364
-
365
-
366
-
367
-
368
- });
282
+ if (err) { console.error("err: ", err); }
283
+ if (log) { console.log("res.body", res.body); }
369
284
 
285
+ res.should.have.status(200);
370
286
 
371
-
372
-
373
-
374
- });
375
-
376
-
287
+ done();
288
+ });
377
289
  });
378
- });
379
-
380
-
381
-
382
-
383
-
290
+ });
291
+ });
292
+ });
384
293
 
385
294
 
386
295
  // // mocha test/authenticationJwt.js --grep 'signinJWt-Project-external-user-YESAudYesSubjectAndRole'
@@ -424,7 +333,7 @@ it('signinJWt-userYESAudYesSubject', (done) => {
424
333
 
425
334
 
426
335
 
427
- // console.log("jwtToken", jwtToken);
336
+ // if (log) { console.log("jwtToken", jwtToken); }
428
337
 
429
338
  // chai.request(server)
430
339
  // .get('/testauth/noentitycheck')
@@ -454,56 +363,45 @@ it('signinJWt-userYESAudYesSubject', (done) => {
454
363
 
455
364
  it('signinJWt-bot-YESAudYesSubject', (done) => {
456
365
 
366
+ var email = "test-signup-" + Date.now() + "@email.com";
367
+ var pwd = "pwd";
457
368
 
458
- // this.timeout();
459
-
460
- var email = "test-signup-" + Date.now() + "@email.com";
461
- var pwd = "pwd";
462
-
463
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
464
- // create(name, createdBy, settings)
465
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
466
- // create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language) {
467
- faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
468
- var savedBotObj = savedBot.toObject();
469
- console.log("savedBotObj", savedBotObj);
470
-
471
-
472
- var signOptions = {
473
- subject: 'bot',
474
- audience: 'https://tiledesk.com/bots/'+savedBot._id,
475
- };
476
-
477
-
478
- var jwtToken = jwt.sign(savedBotObj, savedBot.secret,signOptions);
479
-
480
-
481
-
482
- console.log("jwtToken", jwtToken);
483
- chai.request(server)
484
- // .get('/'+ savedProject._id + '/faq_kb')
485
- .get('/'+savedProject._id+'/authtestWithRoleCheck/bot')
486
-
487
- .set('Authorization', 'JWT '+jwtToken)
488
- .send()
489
- .end((err, res) => {
490
- console.log("res.body", res.body);
491
- res.should.have.status(200);
492
-
493
- done();
494
- });
495
-
496
-
497
-
498
-
499
- });
500
-
369
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
370
+ // create(name, createdBy, settings)
371
+ projectService.create("test-signinJWt-user", savedUser._id).then(function (savedProject) {
372
+ // create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language) {
373
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function (savedBot) {
374
+
375
+ var savedBotObj = savedBot.toObject();
376
+ if (log) { console.log("savedBotObj", savedBotObj); }
377
+
378
+ var signOptions = {
379
+ subject: 'bot',
380
+ audience: 'https://tiledesk.com/bots/' + savedBot._id,
381
+ };
382
+
383
+ var jwtToken = jwt.sign(savedBotObj, savedBot.secret, signOptions);
384
+ if (log) { console.log("jwtToken", jwtToken); }
385
+
386
+ chai.request(server)
387
+ // .get('/'+ savedProject._id + '/faq_kb')
388
+ .get('/' + savedProject._id + '/authtestWithRoleCheck/bot')
389
+
390
+ .set('Authorization', 'JWT ' + jwtToken)
391
+ .send()
392
+ .end((err, res) => {
393
+
394
+ if (err) { console.error("err: ", err); }
395
+ if (log) { console.log("res.body", res.body); }
396
+
397
+ res.should.have.status(200);
398
+
399
+ done();
501
400
  });
502
- });
503
- });
504
-
505
-
506
-
401
+ });
402
+ });
403
+ });
404
+ });
507
405
 
508
406
  });
509
407