@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
@@ -51,8 +51,10 @@ describe('RequestRoute', () => {
51
51
  .set('content-type', 'application/json')
52
52
  .send({ "first_text": "first_text" })
53
53
  .end(function (err, res) {
54
- //console.log("res", res);
55
- //console.log("res.body", res.body);
54
+
55
+ if (err) { console.error("err: ", err); }
56
+ if (log) { console.log("res.body", res.body); }
57
+
56
58
  res.should.have.status(200);
57
59
  res.body.should.be.a('object');
58
60
 
@@ -151,13 +153,13 @@ describe('RequestRoute', () => {
151
153
  .set('content-type', 'application/json')
152
154
  .send({ "first_text": "first_text" })
153
155
  .end(function (err, res) {
154
- //console.log("res", res);
155
- //console.log("res.body", res.body);
156
+
157
+ if (err) { console.error("err: ", err); }
158
+ if (log) { console.log("res.body", res.body); }
159
+
156
160
  res.should.have.status(200);
157
161
  res.body.should.be.a('object');
158
162
 
159
- //console.log("res.body: ", res.body)
160
-
161
163
  setTimeout(() => {
162
164
 
163
165
  chai.request(server)
@@ -166,8 +168,11 @@ describe('RequestRoute', () => {
166
168
  .send()
167
169
  .end((err, res) => {
168
170
 
169
- if (err) { console.error("err: ", err) };
170
- console.log("request duration: ", res.body.duration)
171
+ if (err) { console.error("err: ", err); }
172
+ if (log) {
173
+ console.log("res.body", res.body);
174
+ console.log("request duration: ", res.body.duration)
175
+ }
171
176
 
172
177
  res.body.should.have.property('duration');
173
178
  res.body.duration.should.be.above(2000);
@@ -202,8 +207,10 @@ describe('RequestRoute', () => {
202
207
  .set('content-type', 'application/json')
203
208
  .send({ "first_text": "first_text" })
204
209
  .end(function (err, res) {
205
- //console.log("res", res);
206
- console.log("res.body", res.body);
210
+
211
+ if (err) { console.error("err: ", err); }
212
+ if (log) { console.log("res.body", res.body); }
213
+
207
214
  res.should.have.status(200);
208
215
  res.body.should.be.a('object');
209
216
 
@@ -262,9 +269,9 @@ describe('RequestRoute', () => {
262
269
  .get('/' + savedProject._id + '/requests/' + savedRequest.request_id)
263
270
  .auth(email, pwd)
264
271
  .end(function (err, res) {
265
- //console.log("res", res);
266
-
267
- console.log("res.body", res.body);
272
+
273
+ if (err) { console.error("err: ", err); }
274
+ if (log) { console.log("res.body", res.body); }
268
275
 
269
276
  res.should.have.status(200);
270
277
  res.body.should.be.a('object');
@@ -336,9 +343,9 @@ describe('RequestRoute', () => {
336
343
  .get('/' + savedProject._id + '/requests/' + savedRequest.request_id)
337
344
  .auth(email, pwd)
338
345
  .end(function (err, res) {
339
- //console.log("res", res);
340
-
341
- console.log("res.body", res.body);
346
+
347
+ if (err) { console.error("err: ", err); }
348
+ if (log) { console.log("res.body", res.body); }
342
349
 
343
350
  res.should.have.status(200);
344
351
  res.body.should.be.a('object');
@@ -386,17 +393,17 @@ describe('RequestRoute', () => {
386
393
 
387
394
  userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
388
395
 
389
- console.log("savedUser", savedUser);
396
+ if (log) { console.log("savedUser", savedUser); }
390
397
 
391
398
  projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser._id).then(function (savedProjectAndPU) {
392
399
 
393
400
  var savedProject = savedProjectAndPU.project;
394
401
 
395
- console.log("savedProjectAndPU", savedProjectAndPU);
402
+ if (log) { console.log("savedProjectAndPU", savedProjectAndPU); }
396
403
 
397
404
  leadService.createIfNotExists("leadfullname", "email-getallSimple@email.com", savedProject._id).then(function (createdLead) {
398
405
 
399
- console.log("createdLead", createdLead);
406
+ if (log) { console.log("createdLead", createdLead); }
400
407
 
401
408
  var now = Date.now();
402
409
 
@@ -410,7 +417,7 @@ describe('RequestRoute', () => {
410
417
 
411
418
  requestService.create(new_request).then(function (savedRequest) {
412
419
 
413
- console.log("savedRequest", savedRequest);
420
+ if (log) { console.log("savedRequest", savedRequest); }
414
421
 
415
422
  // createWithId(request_id, requester_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status) {
416
423
  // requestService.createWithId("request_id1", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
@@ -423,14 +430,16 @@ describe('RequestRoute', () => {
423
430
  .get('/' + savedProject._id + '/requests/')
424
431
  .auth(email, pwd)
425
432
  .end(function (err, res) {
426
- //console.log("res", res);
427
- console.log("res.body", res.body);
433
+
434
+ if (err) { console.error("err: ", err); }
435
+ if (log) { console.log("res.body", res.body); }
436
+
428
437
  res.should.have.status(200);
429
438
  res.body.should.be.a('object');
430
439
 
431
440
  expect(res.body.requests[0].department).to.not.equal(null);
432
441
  expect(res.body.requests[0].requester).to.not.equal(null);
433
- console.log("res.body.requests[0].requester", res.body.requests[0].requester);
442
+ if (log) { console.log("res.body.requests[0].requester", res.body.requests[0].requester); }
434
443
 
435
444
  expect(res.body.requests[0].requester.id_user.firstname).to.equal("Test Firstname");
436
445
 
@@ -499,8 +508,10 @@ describe('RequestRoute', () => {
499
508
  .get('/' + savedProject._id + '/requests/?no_populate=true')
500
509
  .auth(email, pwd)
501
510
  .end(function (err, res) {
502
- //console.log("res", res);
503
- console.log("res.body", res.body);
511
+
512
+ if (err) { console.error("err: ", err); }
513
+ if (log) { console.log("res.body", res.body); }
514
+
504
515
  res.should.have.status(200);
505
516
  res.body.should.be.a('object');
506
517
  // assert.isString(res.body.requests[0].department, 'order placed');
@@ -510,7 +521,7 @@ describe('RequestRoute', () => {
510
521
  // console.log("res.body.requests[0].requester", res.body.requests[0].requester);
511
522
  // expect(res.body.requests[0].requester.id_user.firstname).to.equal("Test Firstname");
512
523
 
513
- console.log("res.body.requests[0].participantsAgents", res.body.requests[0].participantsAgents);
524
+ if (log) { console.log("res.body.requests[0].participantsAgents", res.body.requests[0].participantsAgents); }
514
525
  expect(res.body.requests[0].participantsAgents).to.have.lengthOf(1);
515
526
  expect(res.body.requests[0].participantsAgents[0]).to.equal(savedUser._id.toString());
516
527
  expect(res.body.requests[0].participantsBots).to.have.lengthOf(0);
@@ -551,17 +562,17 @@ describe('RequestRoute', () => {
551
562
 
552
563
  userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
553
564
 
554
- console.log("savedUser", savedUser);
565
+ if (log) { console.log("savedUser", savedUser); }
555
566
 
556
567
  projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser._id).then(function (savedProjectAndPU) {
557
568
 
558
569
  var savedProject = savedProjectAndPU.project;
559
570
 
560
- console.log("savedProjectAndPU", savedProjectAndPU);
571
+ if (log) { console.log("savedProjectAndPU", savedProjectAndPU); }
561
572
 
562
573
  leadService.createIfNotExists("leadfullname", "email-getallfilter@email.com", savedProject._id).then(function (createdLead) {
563
574
 
564
- console.log("createdLead", createdLead);
575
+ if (log) { console.log("createdLead", createdLead); }
565
576
  var now = Date.now();
566
577
 
567
578
 
@@ -575,7 +586,7 @@ describe('RequestRoute', () => {
575
586
 
576
587
  requestService.create(new_request).then(function (savedRequest) {
577
588
 
578
- console.log("savedRequest", savedRequest);
589
+ if (log) { console.log("savedRequest", savedRequest); }
579
590
 
580
591
  // createWithId(request_id, requester_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status) {
581
592
  // requestService.createWithId("request_id1", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
@@ -588,14 +599,16 @@ describe('RequestRoute', () => {
588
599
  .get('/' + savedProject._id + '/requests/?snap_department_routing=assigned')
589
600
  .auth(email, pwd)
590
601
  .end(function (err, res) {
591
- //console.log("res", res);
592
- console.log("res.body", res.body);
602
+
603
+ if (err) { console.error("err: ", err); }
604
+ if (log) { console.log("res.body", res.body); }
605
+
593
606
  res.should.have.status(200);
594
607
  res.body.should.be.a('object');
595
608
 
596
609
  expect(res.body.requests[0].department).to.not.equal(null);
597
610
  expect(res.body.requests[0].requester).to.not.equal(null);
598
- console.log("res.body.requests[0].requester", res.body.requests[0].requester);
611
+ if (log) { console.log("res.body.requests[0].requester", res.body.requests[0].requester); }
599
612
 
600
613
  expect(res.body.requests[0].requester.id_user.firstname).to.equal("Test Firstname");
601
614
 
@@ -637,17 +650,17 @@ describe('RequestRoute', () => {
637
650
 
638
651
  userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
639
652
 
640
- console.log("savedUser", savedUser);
653
+ if (log) { console.log("savedUser", savedUser); }
641
654
 
642
655
  projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser._id).then(function (savedProjectAndPU) {
643
656
 
644
657
  var savedProject = savedProjectAndPU.project;
645
658
 
646
- console.log("savedProjectAndPU", savedProjectAndPU);
659
+ if (log) { console.log("savedProjectAndPU", savedProjectAndPU); }
647
660
 
648
661
  leadService.createIfNotExists("leadfullname", "email-getallfilter@email.com", savedProject._id).then(function (createdLead) {
649
662
 
650
- console.log("createdLead", createdLead);
663
+ if (log) { console.log("createdLead", createdLead); }
651
664
 
652
665
  var now = Date.now();
653
666
 
@@ -661,7 +674,7 @@ describe('RequestRoute', () => {
661
674
 
662
675
  requestService.create(new_request).then(function (savedRequest) {
663
676
 
664
- console.log("savedRequest", savedRequest);
677
+ if (log) { console.log("savedRequest", savedRequest); }
665
678
 
666
679
  // createWithId(request_id, requester_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status) {
667
680
  // requestService.createWithId("request_id1", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
@@ -674,14 +687,16 @@ describe('RequestRoute', () => {
674
687
  .get('/' + savedProject._id + '/requests/?snap_department_default=true')
675
688
  .auth(email, pwd)
676
689
  .end(function (err, res) {
677
- //console.log("res", res);
678
- console.log("res.body", res.body);
690
+
691
+ if (err) { console.error("err: ", err); }
692
+ if (log) { console.log("res.body", res.body); }
693
+
679
694
  res.should.have.status(200);
680
695
  res.body.should.be.a('object');
681
696
 
682
697
  expect(res.body.requests[0].department).to.not.equal(null);
683
698
  expect(res.body.requests[0].requester).to.not.equal(null);
684
- console.log("res.body.requests[0].requester", res.body.requests[0].requester);
699
+ if (log) { console.log("res.body.requests[0].requester", res.body.requests[0].requester); }
685
700
 
686
701
  expect(res.body.requests[0].requester.id_user.firstname).to.equal("Test Firstname");
687
702
 
@@ -723,17 +738,17 @@ describe('RequestRoute', () => {
723
738
 
724
739
  userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
725
740
 
726
- console.log("savedUser", savedUser);
741
+ if (log) { console.log("savedUser", savedUser); }
727
742
 
728
743
  projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser._id).then(function (savedProjectAndPU) {
729
744
 
730
745
  var savedProject = savedProjectAndPU.project;
731
746
 
732
- console.log("savedProjectAndPU", savedProjectAndPU);
747
+ if (log) { console.log("savedProjectAndPU", savedProjectAndPU); }
733
748
 
734
749
  leadService.createIfNotExists("leadfullname", "email-getallfilter@email.com", savedProject._id).then(function (createdLead) {
735
750
 
736
- console.log("createdLead", createdLead);
751
+ if (log) { console.log("createdLead", createdLead); }
737
752
 
738
753
  var now = Date.now();
739
754
 
@@ -747,7 +762,7 @@ describe('RequestRoute', () => {
747
762
 
748
763
  requestService.create(new_request).then(function (savedRequest) {
749
764
 
750
- console.log("savedRequest", savedRequest);
765
+ if (log) { console.log("savedRequest", savedRequest); }
751
766
 
752
767
  // createWithId(request_id, requester_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status) {
753
768
  // requestService.createWithId("request_id1", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
@@ -760,14 +775,16 @@ describe('RequestRoute', () => {
760
775
  .get('/' + savedProject._id + '/requests/?snap_department_id_bot_exists=false')
761
776
  .auth(email, pwd)
762
777
  .end(function (err, res) {
763
- //console.log("res", res);
764
- console.log("res.body", res.body);
778
+
779
+ if (err) { console.error("err: ", err); }
780
+ if (log) { console.log("res.body", res.body); }
781
+
765
782
  res.should.have.status(200);
766
783
  res.body.should.be.a('object');
767
784
 
768
785
  expect(res.body.requests[0].department).to.not.equal(null);
769
786
  expect(res.body.requests[0].requester).to.not.equal(null);
770
- console.log("res.body.requests[0].requester", res.body.requests[0].requester);
787
+ if (log) { console.log("res.body.requests[0].requester", res.body.requests[0].requester); }
771
788
 
772
789
  expect(res.body.requests[0].requester.id_user.firstname).to.equal("Test Firstname");
773
790
 
@@ -826,13 +843,13 @@ describe('RequestRoute', () => {
826
843
  .get('/' + savedProject._id + '/requests/csv/')
827
844
  .auth(email, pwd)
828
845
  .end(function (err, res) {
829
- //console.log("res", res);
830
- console.log("res.text", res.text);
831
- // console.log("res", res);
846
+
847
+ if (err) { console.error("err: ", err); }
848
+ if (log) { console.log("res.text", res.text); }
849
+
832
850
  res.should.have.status(200);
833
851
  res.body.should.be.a('object');
834
852
 
835
-
836
853
  done();
837
854
  });
838
855
  // .catch(function(err) {
@@ -876,8 +893,10 @@ describe('RequestRoute', () => {
876
893
  .get('/' + savedProject._id + '/requests/')
877
894
  .auth(email, pwd)
878
895
  .end(function (err, res) {
879
- // console.log("res", res);
880
- // console.log("res.body", res.body);
896
+
897
+ if (err) { console.error("err: ", err); }
898
+ if (log) { console.log("res.body", res.body); }
899
+
881
900
  res.should.have.status(200);
882
901
  res.body.should.be.a('object');
883
902
  expect(res.body.requests[0].department).to.not.equal(null);
@@ -922,8 +941,10 @@ describe('RequestRoute', () => {
922
941
  .set('content-type', 'application/json')
923
942
  .send({ "first_text": "first_text" })
924
943
  .end(function (err, res) {
925
- //console.log("res", res);
926
- console.log("res.body", res.body);
944
+
945
+ if (err) { console.error("err: ", err); }
946
+ if (log) { console.log("res.body", res.body); }
947
+
927
948
  res.should.have.status(200);
928
949
  res.body.should.be.a('object');
929
950
 
@@ -949,7 +970,7 @@ describe('RequestRoute', () => {
949
970
  res.body.should.have.property('department').not.eql(null);
950
971
  // res.body.should.have.property('lead').eql(undefined);
951
972
 
952
- console.log("res.body.request_id: " + res.body.request_id);
973
+ if (log) { console.log("res.body.request_id: " + res.body.request_id); }
953
974
 
954
975
  chai.request(server)
955
976
  .put('/' + savedProject._id + '/requests/' + res.body.request_id + "/departments")
@@ -957,8 +978,10 @@ describe('RequestRoute', () => {
957
978
  .set('content-type', 'application/json')
958
979
  .send({})
959
980
  .end(function (err, res2) {
960
- //console.log("res", res);
961
- console.log("res.body", res2.body);
981
+
982
+ if (err) { console.error("err: ", err); }
983
+ if (log) { console.log("res.body", res.body); }
984
+
962
985
  res2.should.have.status(200);
963
986
  res2.body.should.be.a('object');
964
987
  expect(res.body.participants.length).to.equal(1);
@@ -1001,8 +1024,10 @@ describe('RequestRoute', () => {
1001
1024
  .set('content-type', 'application/json')
1002
1025
  .send({ "first_text": "first_text" })
1003
1026
  .end(function (err, res) {
1004
- //console.log("res", res);
1005
- console.log("res.body", res.body);
1027
+
1028
+ if (err) { console.error("err: ", err); }
1029
+ if (log) { console.log("res.body", res.body); }
1030
+
1006
1031
  res.should.have.status(200);
1007
1032
  res.body.should.be.a('object');
1008
1033
 
@@ -1028,7 +1053,7 @@ describe('RequestRoute', () => {
1028
1053
  res.body.should.have.property('department').not.eql(null);
1029
1054
  // res.body.should.have.property('lead').eql(undefined);
1030
1055
 
1031
- console.log("res.body.request_id: " + res.body.request_id);
1056
+ if (log) { console.log("res.body.request_id: " + res.body.request_id); }
1032
1057
 
1033
1058
  chai.request(server)
1034
1059
  .put('/' + savedProject._id + '/requests/' + res.body.request_id + "/departments")
@@ -1036,8 +1061,10 @@ describe('RequestRoute', () => {
1036
1061
  .set('content-type', 'application/json')
1037
1062
  .send({ "no_populate": "true" })
1038
1063
  .end(function (err, res2) {
1039
- //console.log("res", res);
1040
- console.log("res.body", res2.body);
1064
+
1065
+ if (err) { console.error("err: ", err); }
1066
+ if (log) { console.log("res.body", res.body); }
1067
+
1041
1068
  res2.should.have.status(200);
1042
1069
  res2.body.should.be.a('object');
1043
1070
  expect(res.body.participants.length).to.equal(1);
@@ -1079,8 +1106,10 @@ describe('RequestRoute', () => {
1079
1106
  .set('content-type', 'application/json')
1080
1107
  .send({ "first_text": "first_text" })
1081
1108
  .end(function (err, res) {
1082
- //console.log("res", res);
1083
- console.log("res.body", res.body);
1109
+
1110
+ if (err) { console.error("err: ", err); }
1111
+ if (log) { console.log("res.body", res.body); }
1112
+
1084
1113
  res.should.have.status(200);
1085
1114
  res.body.should.be.a('object');
1086
1115
 
@@ -1106,7 +1135,7 @@ describe('RequestRoute', () => {
1106
1135
  res.body.should.have.property('department').not.eql(null);
1107
1136
  // res.body.should.have.property('lead').eql(undefined);
1108
1137
 
1109
- console.log("res.body.request_id: " + res.body.request_id);
1138
+ if (log) { console.log("res.body.request_id: " + res.body.request_id); }
1110
1139
 
1111
1140
  chai.request(server)
1112
1141
  .put('/' + savedProject._id + '/requests/' + res.body.request_id + "/assign")
@@ -1114,8 +1143,10 @@ describe('RequestRoute', () => {
1114
1143
  .set('content-type', 'application/json')
1115
1144
  .send({})
1116
1145
  .end(function (err, res2) {
1117
- //console.log("res", res);
1118
- console.log("res.body", res2.body);
1146
+
1147
+ if (err) { console.error("err: ", err); }
1148
+ if (log) { console.log("res.body", res.body); }
1149
+
1119
1150
  res2.should.have.status(200);
1120
1151
  res2.body.should.be.a('object');
1121
1152
  expect(res.body.participants.length).to.equal(1);
@@ -1173,8 +1204,10 @@ describe('RequestRoute', () => {
1173
1204
  .set('content-type', 'application/json')
1174
1205
  .send({ "text": "first_text" })
1175
1206
  .end(function (err, res) {
1176
- //console.log("res", res);
1177
- console.log("res.body", res.body);
1207
+
1208
+ if (err) { console.error("err: ", err); }
1209
+ if (log) { console.log("res.body", res.body); }
1210
+
1178
1211
  res.should.have.status(200);
1179
1212
  res.body.should.be.a('object');
1180
1213
 
@@ -1298,7 +1331,6 @@ describe('RequestRoute', () => {
1298
1331
  res.should.have.status(200);
1299
1332
  res.body.should.be.a('object');
1300
1333
 
1301
- console.log("request created")
1302
1334
  chai.request(server)
1303
1335
  .get('/' + savedProject._id + '/requests/count?conversation_quota=true')
1304
1336
  .auth(email, pwd)
@@ -1306,7 +1338,6 @@ describe('RequestRoute', () => {
1306
1338
 
1307
1339
  if (err) { console.log("err: ", err) };
1308
1340
  if (log) { console.log("res.body: ", res.body) };
1309
- console.log("res.body: ", res.body)
1310
1341
 
1311
1342
  res.should.have.status(200);
1312
1343