@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
@@ -1,5 +1,6 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
+ process.env.LOG_LEVEL = 'critical';
3
4
 
4
5
  var expect = require('chai').expect;
5
6
 
@@ -16,85 +17,141 @@ var faqService = require('../services/faqService');
16
17
  var Faq = require('../models/faq');
17
18
  var winston = require('../config/winston');
18
19
 
20
+ let log = false;
21
+
19
22
 
20
23
  describe('FaqService()', function () {
21
24
 
22
25
  it('create-and-search', (done) => {
23
-
26
+
24
27
  var email = "test-subscription-" + Date.now() + "@email.com";
25
28
  var pwd = "pwd";
26
29
 
27
-
30
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
31
+ projectService.create("test-FaqService", savedUser._id).then(function (savedProject) {
32
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function (savedBot) {
33
+
34
+ var newFaq = new Faq({
35
+ id_faq_kb: savedBot._id,
36
+ question: "question",
37
+ answer: "answer",
38
+ id_project: savedProject._id,
39
+ topic: "default",
40
+ createdBy: savedUser._id,
41
+ updatedBy: savedUser._id
42
+ });
43
+
44
+ newFaq.save(function (err, savedFaq) {
45
+ winston.debug("err", err);
46
+ winston.debug("resolve", savedFaq);
47
+ expect(savedBot.name).to.equal("testbot");
48
+ expect(savedBot.secret).to.not.equal(null);
49
+ expect(savedFaq.question).to.equal("question");
50
+ expect(savedFaq.intent_id).to.not.equal(undefined);
51
+ expect(savedFaq.intent_display_name).to.not.equal(undefined);
52
+ expect(savedFaq.webhook_enabled).to.equal(false);
53
+
54
+ var query = { "id_project": savedProject._id };
55
+
56
+ // aggiunta qui
57
+ query.$text = { "$search": "question" };
58
+
59
+ return Faq.find(query, { score: { $meta: "textScore" } })
60
+ .sort({ score: { $meta: "textScore" } }) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
61
+ .lean().
62
+ exec(function (err, faqs) {
63
+ if (log) { console.log("faqs", faqs); }
64
+ // expect(faqs.length).to.equal(1);
65
+ expect(faqs[0]._id.toString()).to.equal(savedFaq._id.toString());
66
+ expect(faqs[0].answer).to.equal("answer");
67
+ expect(faqs[0].question).to.equal("question");
68
+ expect(faqs[0].score).to.not.equal(null);
69
+
70
+ done();
71
+ });
72
+ });
73
+ });
74
+ });
75
+ });
76
+ });
28
77
 
29
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
30
- projectService.create("test-FaqService", savedUser._id).then(function(savedProject) {
31
- faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
32
78
 
33
- var newFaq = new Faq({
34
- id_faq_kb: savedBot._id,
35
- question: "question",
36
- answer: "answer",
37
- id_project: savedProject._id,
38
- topic: "default",
39
- createdBy: savedUser._id,
40
- updatedBy: savedUser._id
41
- });
42
-
43
- newFaq.save(function (err, savedFaq) {
44
- winston.debug("err", err);
45
- winston.debug("resolve", savedFaq);
46
- expect(savedBot.name).to.equal("testbot");
47
- expect(savedBot.secret).to.not.equal(null);
48
- expect(savedFaq.question).to.equal("question");
49
- expect(savedFaq.intent_id).to.not.equal(undefined);
50
- expect(savedFaq.intent_display_name).to.not.equal(undefined);
51
- expect(savedFaq.webhook_enabled).to.equal(false);
52
-
53
- var query = { "id_project": savedProject._id };
54
-
55
-
56
- // aggiunta qui
57
- query.$text = {"$search": "question"};
58
-
59
- return Faq.find(query, {score: { $meta: "textScore" } })
60
- .sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
61
- .lean().
62
- exec(function (err, faqs) {
63
- console.log("faqs", faqs);
64
- // expect(faqs.length).to.equal(1);
65
- expect(faqs[0]._id.toString()).to.equal(savedFaq._id.toString());
66
- expect(faqs[0].answer).to.equal("answer");
67
- expect(faqs[0].question).to.equal("question");
68
- expect(faqs[0].score).to.not.equal(null);
69
- done();
70
- });
71
-
72
-
79
+ it('create-with-intent_display_name-and-search', (done) => {
73
80
 
81
+ var email = "test-subscription-" + Date.now() + "@email.com";
82
+ var pwd = "pwd";
74
83
 
84
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
85
+ projectService.create("test-FaqService", savedUser._id).then(function (savedProject) {
86
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function (savedBot) {
87
+
88
+ var newFaq = new Faq({
89
+ id_faq_kb: savedBot._id,
90
+ question: "question",
91
+ answer: "answer",
92
+ id_project: savedProject._id,
93
+ topic: "default",
94
+ intent_display_name: "question1",
95
+ createdBy: savedUser._id,
96
+ updatedBy: savedUser._id
97
+ });
98
+
99
+ newFaq.save(function (err, savedFaq) {
100
+ winston.debug("err", err);
101
+ winston.debug("resolve", savedFaq);
102
+ expect(savedBot.name).to.equal("testbot");
103
+ expect(savedBot.secret).to.not.equal(null);
104
+ expect(savedFaq.question).to.equal("question");
105
+ expect(savedFaq.intent_id).to.not.equal(undefined);
106
+ expect(savedFaq.intent_display_name).to.equal("question1");
107
+ expect(savedFaq.webhook_enabled).to.equal(false);
108
+
109
+ var query = { "id_project": savedProject._id };
110
+
111
+ // aggiunta qui
112
+ query.$text = { "$search": "question" };
113
+
114
+ return Faq.find(query, { score: { $meta: "textScore" } })
115
+ .sort({ score: { $meta: "textScore" } }) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
116
+ .lean().
117
+ exec(function (err, faqs) {
118
+ if (log) { console.log("faqs", faqs); }
119
+ // expect(faqs.length).to.equal(1);
120
+ expect(faqs[0]._id.toString()).to.equal(savedFaq._id.toString());
121
+ expect(faqs[0].answer).to.equal("answer");
122
+ expect(faqs[0].question).to.equal("question");
123
+ expect(faqs[0].score).to.not.equal(null);
75
124
 
125
+ done();
76
126
  });
77
-
78
-
127
+ });
128
+ });
129
+ });
79
130
  });
80
131
  });
81
- });
82
- });
83
-
84
132
 
85
133
 
134
+ it('create-with-duplicated-intent_display_name-and-search', (done) => {
86
135
 
136
+ var email = "test-subscription-" + Date.now() + "@email.com";
137
+ var pwd = "pwd";
87
138
 
88
- it('create-with-intent_display_name-and-search', (done) => {
89
-
90
- var email = "test-subscription-" + Date.now() + "@email.com";
91
- var pwd = "pwd";
139
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
140
+ projectService.create("test-FaqService", savedUser._id).then(function (savedProject) {
141
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function (savedBot) {
92
142
 
93
-
143
+ var newFaq0 = new Faq({
144
+ id_faq_kb: savedBot._id,
145
+ question: "question",
146
+ answer: "answer",
147
+ id_project: savedProject._id,
148
+ topic: "default",
149
+ intent_display_name: "question1",
150
+ createdBy: savedUser._id,
151
+ updatedBy: savedUser._id
152
+ });
94
153
 
95
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
96
- projectService.create("test-FaqService", savedUser._id).then(function(savedProject) {
97
- faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
154
+ newFaq0.save(function (err, savedFaq0) {
98
155
 
99
156
  var newFaq = new Faq({
100
157
  id_faq_kb: savedBot._id,
@@ -106,112 +163,20 @@ it('create-with-intent_display_name-and-search', (done) => {
106
163
  createdBy: savedUser._id,
107
164
  updatedBy: savedUser._id
108
165
  });
109
-
110
- newFaq.save(function (err, savedFaq) {
111
- winston.debug("err", err);
112
- winston.debug("resolve", savedFaq);
113
- expect(savedBot.name).to.equal("testbot");
114
- expect(savedBot.secret).to.not.equal(null);
115
- expect(savedFaq.question).to.equal("question");
116
- expect(savedFaq.intent_id).to.not.equal(undefined);
117
- expect(savedFaq.intent_display_name).to.equal("question1");
118
- expect(savedFaq.webhook_enabled).to.equal(false);
119
-
120
- var query = { "id_project": savedProject._id };
121
-
122
-
123
- // aggiunta qui
124
- query.$text = {"$search": "question"};
125
-
126
- return Faq.find(query, {score: { $meta: "textScore" } })
127
- .sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
128
- .lean().
129
- exec(function (err, faqs) {
130
- console.log("faqs", faqs);
131
- // expect(faqs.length).to.equal(1);
132
- expect(faqs[0]._id.toString()).to.equal(savedFaq._id.toString());
133
- expect(faqs[0].answer).to.equal("answer");
134
- expect(faqs[0].question).to.equal("question");
135
- expect(faqs[0].score).to.not.equal(null);
136
- done();
137
- });
138
-
139
-
140
-
141
-
142
-
143
- });
144
-
145
-
146
- });
147
- });
148
- });
149
- });
150
-
151
-
152
-
153
-
154
-
155
166
 
156
- it('create-with-duplicated-intent_display_name-and-search', (done) => {
157
-
158
- var email = "test-subscription-" + Date.now() + "@email.com";
159
- var pwd = "pwd";
160
-
161
-
162
-
163
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
164
- projectService.create("test-FaqService", savedUser._id).then(function(savedProject) {
165
- faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
166
-
167
- var newFaq0 = new Faq({
168
- id_faq_kb: savedBot._id,
169
- question: "question",
170
- answer: "answer",
171
- id_project: savedProject._id,
172
- topic: "default",
173
- intent_display_name: "question1",
174
- createdBy: savedUser._id,
175
- updatedBy: savedUser._id
176
- });
177
-
178
- newFaq0.save(function (err, savedFaq0) {
179
-
180
-
181
- var newFaq = new Faq({
182
- id_faq_kb: savedBot._id,
183
- question: "question",
184
- answer: "answer",
185
- id_project: savedProject._id,
186
- topic: "default",
187
- intent_display_name: "question1",
188
- createdBy: savedUser._id,
189
- updatedBy: savedUser._id
190
- });
191
-
192
- newFaq.save(function (err, savedFaq) {
167
+ newFaq.save(function (err, savedFaq) {
193
168
 
194
- console.log("err.code ",err.code );
195
- if (err.code == 11000) {
196
- done()
197
- }
198
-
169
+ if (log) { console.log("err.code ", err.code); }
170
+ if (err.code == 11000) {
171
+ done()
172
+ }
199
173
 
200
- });
201
-
202
174
  });
203
-
204
-
175
+ });
176
+ });
177
+ });
178
+ });
205
179
  });
206
- });
207
- });
208
- });
209
-
210
-
211
-
212
-
213
-
214
-
215
180
 
216
181
  });
217
182