@tiledesk/tiledesk-server 2.10.15 → 2.10.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/CHANGELOG.md +12 -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/users.js +2 -2
  15. package/services/fileGridFsService.js +12 -10
  16. package/services/requestService.js +2 -1
  17. package/test/app-test.js +36 -1
  18. package/test/authentication.js +662 -796
  19. package/test/authenticationJwt.js +213 -315
  20. package/test/authorization.js +53 -72
  21. package/test/campaignsRoute.js +42 -47
  22. package/test/cannedRoute.js +30 -16
  23. package/test/departmentService.js +222 -274
  24. package/test/example.json +31 -1
  25. package/test/faqRoute.js +713 -622
  26. package/test/faqService.js +124 -159
  27. package/test/faqkbRoute.js +128 -100
  28. package/test/fileRoute.js +50 -46
  29. package/test/imageRoute.js +263 -254
  30. package/test/jwtRoute.js +128 -153
  31. package/test/kbRoute.js +40 -17
  32. package/test/kbsettingsRoute.js +78 -54
  33. package/test/keysRoute.js +6 -7
  34. package/test/labelRoute.js +591 -696
  35. package/test/labelService.js +40 -47
  36. package/test/leadService.js +100 -115
  37. package/test/logsRoute.js +13 -7
  38. package/test/messageRootRoute.js +112 -102
  39. package/test/messageRoute.js +1171 -1419
  40. package/test/messageService.js +41 -43
  41. package/test/openaiRoute.js +5 -1
  42. package/test/projectRoute.js +23 -4
  43. package/test/projectService.js +3 -1
  44. package/test/quoteManager.js +36 -13
  45. package/test/requestRoute.js +103 -72
  46. package/test/requestService.js +51 -51
  47. package/test/userRoute.js +37 -8
  48. package/test/userService.js +34 -31
  49. package/utils/promiseUtil.js +1 -1
package/test/jwtRoute.js CHANGED
@@ -12,6 +12,8 @@ let server = require('../app');
12
12
  let should = chai.should();
13
13
  var jwt = require('jsonwebtoken');
14
14
 
15
+ let log = false;
16
+
15
17
  // chai.config.includeStack = true;
16
18
 
17
19
  var expect = chai.expect;
@@ -22,177 +24,150 @@ chai.use(chaiHttp);
22
24
  describe('JWTRoute', () => {
23
25
 
24
26
  describe('/decode', () => {
25
-
26
-
27
27
 
28
28
  it('decodeWithIatExp', (done) => {
29
29
 
30
-
31
- // this.timeout();
32
-
33
- var email = "test-signup-" + Date.now() + "@email.com";
34
- var pwd = "pwd";
35
-
36
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
37
- projectService.create("test-join-member", savedUser._id).then(function(savedProject) {
38
- chai.request(server)
39
- .post('/'+ savedProject._id + '/keys/generate')
40
- .auth(email, pwd)
41
- .send()
42
- .end((err, res) => {
43
- //console.log("res", res);
44
- console.log("res.body", res.body);
45
- res.should.have.status(200);
46
- res.body.should.be.a('object');
47
- expect(res.body.jwtSecret).to.not.equal(null);
48
-
49
- chai.request(server)
50
- .post('/'+ savedProject._id + '/jwt/generatetestjwt')
51
- .auth(email, pwd)
52
- .send({"name":"andrea", "surname":"leo"})
53
- .end((err, res) => {
54
- res.should.have.status(200);
55
- res.body.should.be.a('object');
56
- expect(res.body.token).to.not.equal(null);
57
-
58
- var jwtToken = res.body.token;
59
- console.log("jwtToken", jwtToken);
60
- chai.request(server)
61
- .post('/'+ savedProject._id + '/jwt/decode')
62
- .set('Authorization', jwtToken)
63
- .send()
64
- .end((err, res) => {
65
- res.should.have.status(200);
66
- res.body.should.be.a('object');
67
- expect(res.body.name).to.not.equal("andrea");
68
- expect(res.body.surname).to.not.equal("leo");
69
- expect(res.body.iat).to.not.equal(null);
70
- expect(res.body.exp).to.not.equal(null);
71
- done();
72
- });
73
-
74
-
75
- });
76
-
77
- });
78
-
79
-
30
+ var email = "test-signup-" + Date.now() + "@email.com";
31
+ var pwd = "pwd";
32
+
33
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
34
+ projectService.create("test-join-member", savedUser._id).then(function (savedProject) {
35
+ chai.request(server)
36
+ .post('/' + savedProject._id + '/keys/generate')
37
+ .auth(email, pwd)
38
+ .send()
39
+ .end((err, res) => {
40
+
41
+ if (err) { console.error("err: ", err); }
42
+ if (log) { console.log("res.body", res.body); }
43
+
44
+ res.should.have.status(200);
45
+ res.body.should.be.a('object');
46
+ expect(res.body.jwtSecret).to.not.equal(null);
47
+
48
+ chai.request(server)
49
+ .post('/' + savedProject._id + '/jwt/generatetestjwt')
50
+ .auth(email, pwd)
51
+ .send({ "name": "andrea", "surname": "leo" })
52
+ .end((err, res) => {
53
+
54
+ if (err) { console.error("err: ", err); }
55
+ if (log) { console.log("res.body", res.body); }
56
+
57
+ res.should.have.status(200);
58
+ res.body.should.be.a('object');
59
+ expect(res.body.token).to.not.equal(null);
60
+
61
+ var jwtToken = res.body.token;
62
+ if (log) { console.log("jwtToken", jwtToken); }
63
+
64
+ chai.request(server)
65
+ .post('/' + savedProject._id + '/jwt/decode')
66
+ .set('Authorization', jwtToken)
67
+ .send()
68
+ .end((err, res) => {
69
+
70
+ res.should.have.status(200);
71
+ res.body.should.be.a('object');
72
+
73
+ expect(res.body.name).to.not.equal("andrea");
74
+ expect(res.body.surname).to.not.equal("leo");
75
+ expect(res.body.iat).to.not.equal(null);
76
+ expect(res.body.exp).to.not.equal(null);
77
+
78
+ done();
79
+ });
80
80
  });
81
+ });
82
+ });
83
+ });
84
+ }).timeout(20000);
85
+
86
+
87
+ it('decodeWithIatNoExp', (done) => {
88
+
89
+ var email = "test-signup-" + Date.now() + "@email.com";
90
+ var pwd = "pwd";
91
+
92
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
93
+ projectService.create("test-join-member", savedUser._id).then(function (savedProject) {
94
+ chai.request(server)
95
+ .post('/' + savedProject._id + '/keys/generate')
96
+ .auth(email, pwd)
97
+ .send()
98
+ .end((err, res) => {
99
+
100
+ if (err) { console.error("err: ", err); }
101
+ if (log) { console.log("res.body", res.body); }
102
+
103
+ res.should.have.status(200);
104
+ res.body.should.be.a('object');
105
+ expect(res.body.jwtSecret).to.not.equal(null);
106
+
107
+ var jwtToken = jwt.sign({ "name": "andrea", "surname": "leo" }, res.body.jwtSecret);
108
+ if (log) { console.log("jwtToken", jwtToken); }
109
+
110
+ chai.request(server)
111
+ .post('/' + savedProject._id + '/jwt/decode')
112
+ .set('Authorization', 'JWT ' + jwtToken)
113
+ .send()
114
+ .end((err, res) => {
115
+
116
+ if (err) { console.error("err: ", err); }
117
+ if (log) { console.log("res.body", res.body); }
118
+
119
+ res.should.have.status(401);
120
+
121
+ done();
81
122
  });
82
-
123
+ });
124
+ });
125
+ });
83
126
  }).timeout(20000);
84
127
 
85
128
 
129
+ it('decodeWithIatTooHightExp', (done) => {
86
130
 
131
+ var email = "test-signup-" + Date.now() + "@email.com";
132
+ var pwd = "pwd";
87
133
 
134
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
135
+ projectService.create("test-join-member", savedUser._id).then(function (savedProject) {
136
+ chai.request(server)
137
+ .post('/' + savedProject._id + '/keys/generate')
138
+ .auth(email, pwd)
139
+ .send()
140
+ .end((err, res) => {
88
141
 
89
- it('decodeWithIatNoExp', (done) => {
142
+ if (err) { console.error("err: ", err); }
143
+ if (log) { console.log("res.body", res.body); }
90
144
 
91
-
92
- // this.timeout();
93
-
94
- var email = "test-signup-" + Date.now() + "@email.com";
95
- var pwd = "pwd";
96
-
97
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
98
- projectService.create("test-join-member", savedUser._id).then(function(savedProject) {
99
- chai.request(server)
100
- .post('/'+ savedProject._id + '/keys/generate')
101
- .auth(email, pwd)
102
- .send()
103
- .end((err, res) => {
104
- //console.log("res", res);
105
- console.log("res.body", res.body);
106
- res.should.have.status(200);
107
- res.body.should.be.a('object');
108
- expect(res.body.jwtSecret).to.not.equal(null);
109
-
110
-
111
- var jwtToken = jwt.sign({"name":"andrea", "surname":"leo"}, res.body.jwtSecret);
112
-
113
-
114
-
115
- console.log("jwtToken", jwtToken);
116
- chai.request(server)
117
- .post('/'+ savedProject._id + '/jwt/decode')
118
- .set('Authorization', 'JWT '+jwtToken)
119
- .send()
120
- .end((err, res) => {
121
- res.should.have.status(401);
122
-
123
- done();
124
- });
125
-
126
-
127
-
128
-
129
- });
130
-
131
-
132
- });
133
- });
134
-
135
- }).timeout(20000);
136
-
137
-
138
-
139
-
140
-
141
-
142
- it('decodeWithIatTooHightExp', (done) => {
143
-
144
-
145
- // this.timeout();
146
-
147
- var email = "test-signup-" + Date.now() + "@email.com";
148
- var pwd = "pwd";
149
-
150
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
151
- projectService.create("test-join-member", savedUser._id).then(function(savedProject) {
152
- chai.request(server)
153
- .post('/'+ savedProject._id + '/keys/generate')
154
- .auth(email, pwd)
155
- .send()
156
- .end((err, res) => {
157
- //console.log("res", res);
158
- console.log("res.body", res.body);
159
- res.should.have.status(200);
160
- res.body.should.be.a('object');
161
- expect(res.body.jwtSecret).to.not.equal(null);
162
-
163
-
164
- var jwtToken = jwt.sign({"name":"andrea", "surname":"leo"}, res.body.jwtSecret, { expiresIn: 800 });
165
-
166
-
167
-
168
- console.log("jwtToken", jwtToken);
169
- chai.request(server)
170
- .post('/'+ savedProject._id + '/jwt/decode')
171
- .set('Authorization', 'JWT '+jwtToken)
172
- .send()
173
- .end((err, res) => {
174
- res.should.have.status(401);
175
-
176
- done();
177
- });
178
-
179
-
180
-
181
-
182
- });
183
-
184
-
185
- });
186
- });
187
-
188
- }).timeout(20000);
145
+ res.should.have.status(200);
146
+ res.body.should.be.a('object');
147
+ expect(res.body.jwtSecret).to.not.equal(null);
189
148
 
149
+ var jwtToken = jwt.sign({ "name": "andrea", "surname": "leo" }, res.body.jwtSecret, { expiresIn: 800 });
150
+ if (log) { console.log("jwtToken", jwtToken); }
190
151
 
152
+ chai.request(server)
153
+ .post('/' + savedProject._id + '/jwt/decode')
154
+ .set('Authorization', 'JWT ' + jwtToken)
155
+ .send()
156
+ .end((err, res) => {
191
157
 
158
+ if (err) { console.error("err: ", err); }
159
+ if (log) { console.log("res.body", res.body); }
192
160
 
161
+ res.should.have.status(401);
193
162
 
163
+ done();
164
+ });
165
+ });
166
+ });
167
+ });
168
+ }).timeout(20000);
194
169
 
195
- });
170
+ });
196
171
 
197
172
  });
198
173
 
package/test/kbRoute.js CHANGED
@@ -2,6 +2,8 @@
2
2
  process.env.NODE_ENV = 'test';
3
3
  process.env.GPTKEY = "fakegptkey";
4
4
  process.env.KB_WEBHOOK_TOKEN = "testtoken"
5
+ process.env.PINECONE_INDEX = "test_index"
6
+ process.env.LOG_LEVEL = 'critical'
5
7
 
6
8
  var userService = require('../services/userService');
7
9
  var projectService = require('../services/projectService');
@@ -56,6 +58,7 @@ describe('KbRoute', () => {
56
58
 
57
59
  res.should.have.status(200);
58
60
  expect(res.body.length).to.equal(1);
61
+ expect(res.body[0].engine.index_name).to.equal('test_index')
59
62
 
60
63
  let namespace_id = res.body[0].id;
61
64
 
@@ -112,7 +115,7 @@ describe('KbRoute', () => {
112
115
  expect(res.body.length).to.equal(1);
113
116
 
114
117
  let namespace_id = res.body[0].id;
115
- console.log("namespace_id: ", namespace_id);
118
+ if (log) { console.log("namespace_id: ", namespace_id); }
116
119
 
117
120
  let kb = {
118
121
  name: "example_text1",
@@ -130,7 +133,7 @@ describe('KbRoute', () => {
130
133
 
131
134
  if (err) { console.error("err: ", err); }
132
135
  if (log) { console.log("create kb res.body: ", res.body); }
133
- console.log("create kb res.body: ", res.body);
136
+
134
137
  res.should.have.status(200);
135
138
  res.body.should.be.a('object');
136
139
  expect(res.body.value.id_project).to.equal(res.body.value.namespace)
@@ -187,7 +190,7 @@ describe('KbRoute', () => {
187
190
 
188
191
  if (err) { console.error("err: ", err); }
189
192
  if (log) { console.log("create kb res.body: ", res.body); }
190
- console.log("create kb res.body: ", res.body);
193
+
191
194
  res.should.have.status(200);
192
195
  res.body.should.be.a('object');
193
196
 
@@ -202,16 +205,18 @@ describe('KbRoute', () => {
202
205
  if (log) { console.log("res.body: ", res.body )};
203
206
 
204
207
  res.should.have.status(200);
205
- //expect(res.body.length).to.equal(1);
208
+ /**
209
+ * Unable to verify the response due to an external request
210
+ */
211
+ expect(res.body.success).to.equal(true);
212
+ expect(res.body.message).to.equal("Get chunks skipped in test environment");
206
213
 
207
214
  done();
208
215
  })
209
-
210
216
  })
211
217
  })
212
218
  });
213
219
  });
214
-
215
220
  })
216
221
 
217
222
  it('get-with-queries', (done) => {
@@ -272,6 +277,8 @@ describe('KbRoute', () => {
272
277
  .auth(email, pwd)
273
278
  .send(kb1)
274
279
  .end((err, res) => {
280
+
281
+ if (err) { console.error("err: ", err); }
275
282
  if (log) { console.log("create kb1 res.body: ", res.body); }
276
283
  res.should.have.status(200);
277
284
 
@@ -281,7 +288,10 @@ describe('KbRoute', () => {
281
288
  .auth(email, pwd)
282
289
  .send(kb2)
283
290
  .end((err, res) => {
291
+
292
+ if (err) { console.error("err: ", err); }
284
293
  if (log) { console.log("create kb2 res.body: ", res.body); }
294
+
285
295
  res.should.have.status(200);
286
296
 
287
297
  setTimeout(() => {
@@ -290,7 +300,10 @@ describe('KbRoute', () => {
290
300
  .auth(email, pwd)
291
301
  .send(kb3)
292
302
  .end((err, res) => {
303
+
304
+ if (err) { console.error("err: ", err); }
293
305
  if (log) { console.log("create kb3 res.body: ", res.body); }
306
+
294
307
  res.should.have.status(200);
295
308
 
296
309
  let query = "?status=-1&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example&namespace=" + namespace_id;
@@ -300,8 +313,10 @@ describe('KbRoute', () => {
300
313
  .get('/' + savedProject._id + "/kb" + query)
301
314
  .auth(email, pwd)
302
315
  .end((err, res) => {
316
+
303
317
  if (err) { console.error("err: ", err)}
304
318
  if (log) { console.log("getall res.body: ", res.body); }
319
+
305
320
  res.should.have.status(200);
306
321
  res.body.should.be.a('object');
307
322
  res.body.kbs.should.be.a('array');
@@ -370,7 +385,10 @@ describe('KbRoute', () => {
370
385
  .auth(email, pwd)
371
386
  .send(kb1)
372
387
  .end((err, res) => {
388
+
389
+ if (err) { console.error("err: ", err); }
373
390
  if (log) { console.log("create kb1 res.body: ", res.body); }
391
+
374
392
  res.should.have.status(200);
375
393
 
376
394
  let namespace_id = "fakenamespaceid";
@@ -381,7 +399,10 @@ describe('KbRoute', () => {
381
399
  .get('/' + savedProject._id + "/kb" + query)
382
400
  .auth(email, pwd)
383
401
  .end((err, res) => {
402
+
403
+ if (err) { console.error("err: ", err); }
384
404
  if (log) { console.log("getall res.body: ", res.body); }
405
+
385
406
  res.should.have.status(200);
386
407
  res.body.should.be.a('object');
387
408
  res.body.kbs.should.be.a('array');
@@ -555,7 +576,6 @@ describe('KbRoute', () => {
555
576
 
556
577
  if (err) { console.error("err: ", err); }
557
578
  if (log) { console.log("res.body: ", res.body) }
558
- console.log("res.body: ", res.body)
559
579
 
560
580
  res.should.have.status(200);
561
581
  expect(res.body.length).to.equal(4)
@@ -598,7 +618,7 @@ describe('KbRoute', () => {
598
618
 
599
619
  if (err) { console.error("err: ", err); }
600
620
  if (log) { console.log("res.body: ", res.body) }
601
- console.log("res.body: ", res.body)
621
+
602
622
  res.should.have.status(200);
603
623
  expect(res.body.length).to.equal(1)
604
624
  expect(res.body[0].scrape_type).to.equal(4)
@@ -645,11 +665,11 @@ describe('KbRoute', () => {
645
665
 
646
666
  if (err) { console.error("err: ", err); }
647
667
  if (log) { console.log("res.body: ", res.body) }
648
- console.log("res.body: ", res.body)
668
+
649
669
  res.should.have.status(200);
650
670
  expect(res.body.length).to.equal(1)
651
671
  expect(res.body[0].scrape_type).to.equal(3)
652
- expect(typeof res.body[0].scrape_options === "undefined").to.be.true;
672
+ expect(typeof res.body[0].scrape_options === null);
653
673
 
654
674
  done();
655
675
 
@@ -725,7 +745,10 @@ describe('KbRoute', () => {
725
745
  .auth(email, pwd)
726
746
  .send(kb) // can be empty
727
747
  .end((err, res) => {
748
+
749
+ if (err) { console.error("err: ", err); }
728
750
  if (log) { console.log("create kb res.body: ", res.body); }
751
+
729
752
  res.should.have.status(200);
730
753
 
731
754
  let kbid = res.body.value._id;
@@ -736,6 +759,7 @@ describe('KbRoute', () => {
736
759
  .send({ id: kbid })
737
760
  .end((err, res) => {
738
761
 
762
+ if (err) { console.error("err: ", err); }
739
763
  if (log) { console.log("single scrape res.body: ", res.body); }
740
764
 
741
765
  /**
@@ -1326,8 +1350,6 @@ describe('KbRoute', () => {
1326
1350
  if (err) { console.error("err: ", err); }
1327
1351
  if (log) { console.log("get all namespaces res.body: ", res.body); }
1328
1352
 
1329
- console.log("namespace created..")
1330
-
1331
1353
  chai.request(server)
1332
1354
  .post('/' + savedProject._id + "/kb/qa")
1333
1355
  .auth(email, pwd)
@@ -1336,7 +1358,7 @@ describe('KbRoute', () => {
1336
1358
 
1337
1359
  if (err) { console.error("err: ", err) };
1338
1360
  if (log) { console.log("res.body: ", res.body) };
1339
- console.log("res.body: ", res.body)
1361
+
1340
1362
  done();
1341
1363
  })
1342
1364
 
@@ -1361,7 +1383,7 @@ describe('KbRoute', () => {
1361
1383
  .end((err, res) => {
1362
1384
 
1363
1385
  if (err) { console.log("error: ", err) };
1364
- if (log) { console.log("1 res.body: ", res.body) };
1386
+ if (log) { console.log("res.body: ", res.body) };
1365
1387
 
1366
1388
  res.should.have.status(200);
1367
1389
  res.body.should.be.a('array');
@@ -1383,7 +1405,7 @@ describe('KbRoute', () => {
1383
1405
  .end((err, res) => {
1384
1406
 
1385
1407
  if (err) { console.log("error: ", err) };
1386
- if (log) { console.log("2 res.body: ", res.body) };
1408
+ if (log) { console.log("res.body: ", res.body) };
1387
1409
 
1388
1410
  res.should.have.status(200);
1389
1411
  res.body.should.be.a('object');
@@ -1397,7 +1419,7 @@ describe('KbRoute', () => {
1397
1419
  .end((err, res) => {
1398
1420
 
1399
1421
  if (err) { console.error("err: ", err) };
1400
- if (log) { console.log("3 res.body: ", res.body) };
1422
+ if (log) { console.log("res.body: ", res.body) };
1401
1423
 
1402
1424
  res.should.have.status(200);
1403
1425
  res.body.should.be.a('object');
@@ -1420,7 +1442,8 @@ describe('KbRoute', () => {
1420
1442
 
1421
1443
  })
1422
1444
 
1423
- describe('namespaces', () => {
1445
+
1446
+ describe('/namespaces', () => {
1424
1447
 
1425
1448
 
1426
1449
  /**