@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,11 +1,14 @@
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
 
6
7
  var chai = require("chai");
7
8
  chai.config.includeStack = true;
8
9
 
10
+ let log = false;
11
+
9
12
  var expect = chai.expect;
10
13
  var assert = chai.assert;
11
14
  let should = chai.should();
@@ -43,47 +46,47 @@ describe('messageService', function () {
43
46
 
44
47
  var userid = "5badfe5d553d1844ad654072";
45
48
 
46
- it('createMessageQuote', function (done) {
47
- // this.timeout(10000);
48
- let qm = new QuoteManager({ tdCache: tdCache });
49
- qm.start();
49
+ // it('createMessageQuote', function (done) {
50
+ // // this.timeout(10000);
51
+ // let qm = new QuoteManager({ tdCache: tdCache });
52
+ // qm.start();
50
53
 
51
- projectService.create("test1", userid).then(function (savedProject) {
52
- // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
54
+ // projectService.create("test1", userid).then(function (savedProject) {
55
+ // // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
53
56
 
54
- messageService.create(userid, "test sender", "testrecipient-createMessage", "hello",
55
- savedProject._id, userid, undefined, { a1: "a1" }, undefined, undefined, "it").then(function (savedMessage) {
56
- winston.debug("resolve savedMessage", savedMessage.toObject());
57
+ // messageService.create(userid, "test sender", "testrecipient-createMessage", "hello",
58
+ // savedProject._id, userid, undefined, { a1: "a1" }, undefined, undefined, "it").then(function (savedMessage) {
59
+ // winston.debug("resolve savedMessage", savedMessage.toObject());
57
60
 
58
- expect(savedMessage.text).to.equal("hello");
59
- expect(savedMessage.sender).to.equal(userid);
60
- expect(savedMessage.senderFullname).to.equal("test sender");
61
- expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
62
- expect(savedMessage.language).to.equal("it");
63
- expect(savedMessage.attributes.a1).to.equal("a1");
64
- expect(savedMessage.channel_type).to.equal("group");
65
- expect(savedMessage.channel.name).to.equal("chat21");
61
+ // expect(savedMessage.text).to.equal("hello");
62
+ // expect(savedMessage.sender).to.equal(userid);
63
+ // expect(savedMessage.senderFullname).to.equal("test sender");
64
+ // expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
65
+ // expect(savedMessage.language).to.equal("it");
66
+ // expect(savedMessage.attributes.a1).to.equal("a1");
67
+ // expect(savedMessage.channel_type).to.equal("group");
68
+ // expect(savedMessage.channel.name).to.equal("chat21");
66
69
 
67
70
 
68
- setTimeout(async () => {
69
- let obj = { createdAt: new Date() }
71
+ // setTimeout(async () => {
72
+ // let obj = { createdAt: new Date() }
70
73
 
71
- let quotes = await qm.getAllQuotes(savedProject, obj);
72
- quotes.messages.quote.should.be.a('number');
73
- expect(quotes.messages.quote).to.equal(1);
74
+ // let quotes = await qm.getAllQuotes(savedProject, obj);
75
+ // quotes.messages.quote.should.be.a('number');
76
+ // expect(quotes.messages.quote).to.equal(1);
74
77
 
75
- done();
78
+ // done();
76
79
 
77
- }, 1000);
80
+ // }, 1000);
78
81
 
79
82
 
80
- }).catch(function (err) {
81
- assert.isNotOk(err, 'Promise error');
82
- done();
83
- });
83
+ // }).catch(function (err) {
84
+ // assert.isNotOk(err, 'Promise error');
85
+ // done();
86
+ // });
84
87
 
85
- });
86
- }).timeout(10000);
88
+ // });
89
+ // }).timeout(10000);
87
90
 
88
91
  it('createMessage', function (done) {
89
92
  // this.timeout(10000);
@@ -124,20 +127,15 @@ describe('messageService', function () {
124
127
  // projectService.create("test1", userid).then(function(savedProject) {
125
128
  projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
126
129
  var savedProject = savedProjectAndPU.project;
127
-
128
130
  // attento reqid
129
131
  // requestService.createWithId("request_id-createTwoMessage", "requester_id1", savedProject._id, "first_text").then(function(savedRequest) {
130
- requestService.createWithIdAndRequester("request_id-createTwoMessage", savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
131
-
132
- messageService.create(userid, "test sender", savedRequest.request_id, "hello",
133
- savedProject._id, userid).then(function (savedMessage) {
134
-
132
+ requestService.createWithIdAndRequester("request_id-createTwoMessage-" + new Date(), savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
133
+ messageService.create(userid, "test sender", savedRequest.request_id, "hello", savedProject._id, userid).then(function (savedMessage) {
135
134
  // Promise.all([requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedProject._id),
136
135
  // requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedProject._id)]).then(function(savedMessage) {
137
136
 
138
137
  Request.findOne({ "request_id": "request_id-createTwoMessage", "id_project": savedProject._id }).exec().then(function (req) {
139
- console.log("test resolve", req);
140
-
138
+ if (log) { console.log("test resolve", req); };
141
139
  // expect(req.messages_count).to.equal(2);
142
140
 
143
141
  done();
@@ -152,7 +150,7 @@ describe('messageService', function () {
152
150
  });
153
151
 
154
152
 
155
- });
153
+ }).timeout(4000);
156
154
 
157
155
 
158
156
 
@@ -167,7 +165,7 @@ describe('messageService', function () {
167
165
 
168
166
 
169
167
  var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
170
- console.log("messageTransformerInterceptor", messageTransformerInterceptor);
168
+ if (log) { console.log("messageTransformerInterceptor", messageTransformerInterceptor); }
171
169
  messageTransformerInterceptor.listen();
172
170
 
173
171
 
@@ -199,7 +197,7 @@ describe('messageService', function () {
199
197
 
200
198
 
201
199
  var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
202
- console.log("messageTransformerInterceptor", messageTransformerInterceptor);
200
+ if (log) { console.log("messageTransformerInterceptor", messageTransformerInterceptor); }
203
201
  messageTransformerInterceptor.listen();
204
202
 
205
203
 
@@ -233,7 +231,7 @@ describe('messageService', function () {
233
231
 
234
232
 
235
233
  var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
236
- console.log("messageTransformerInterceptor", messageTransformerInterceptor);
234
+ if (log) { console.log("messageTransformerInterceptor", messageTransformerInterceptor); }
237
235
  messageTransformerInterceptor.listen();
238
236
 
239
237
 
@@ -271,7 +269,7 @@ describe('messageService', function () {
271
269
 
272
270
 
273
271
  var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
274
- console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor);
272
+ if (log) { console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor); }
275
273
  microLanguageTransformerInterceptor.listen();
276
274
 
277
275
 
@@ -1,10 +1,11 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
- // process.env.GPTKEY = 'customgptkey';
3
+ process.env.GPTKEY = '';
4
4
  //process.env.AI_MODELS = 'gpt-3.5-turbo:0.6;gpt-4:25;gpt-4-turbo-preview:12;gpt-4o:6'
5
5
  //process.env.AI_MODELS = 'gpt-3.5-turbo;gpt-4-turbo-preview;gpt-4o'
6
6
  process.env.AI_MODELS = ' gpt-3.5-turbo:0 .6;gpt -4:2 5; g pt-4-tur bo-preview:12;gp t-4o:6'
7
7
 
8
+
8
9
  let log = false;
9
10
  var projectService = require('../services/projectService');
10
11
  var userService = require('../services/userService');
@@ -120,7 +121,10 @@ describe('OpenaiRoute', () => {
120
121
  .auth(email, pwd)
121
122
  .send({ question: "Provide 3 names for a dog", context: "you are an awesome assistant", max_tokens: 100, temperature: 0, model: "gpt-3.5-turbo" })
122
123
  .end((err, res) => {
124
+
125
+ if (err) { console.error("err: ", err); }
123
126
  if (log) { console.log("res.body: ", res.body); }
127
+
124
128
  res.should.have.status(400);
125
129
  res.body.should.be.a('object');
126
130
  expect(res.body.success).to.equal(false);
@@ -65,6 +65,7 @@ describe('ProjectRoute', () => {
65
65
  // .send({ email: email, password: pwd }) // con queste credenziali non si può fare la richiesta /projects/all
66
66
  .end((err, res) => {
67
67
 
68
+ if (err) { console.error("err: ", err); }
68
69
  if (log) { console.log("login with superadmin res.body: ", res.body) };
69
70
  res.should.have.status(200);
70
71
  res.body.should.be.a('object');
@@ -78,8 +79,12 @@ describe('ProjectRoute', () => {
78
79
  .set('Authorization', superadmin_token)
79
80
  .end((err, res) => {
80
81
 
81
- console.log("res.body: ", res.body.length);
82
- console.log("example: ", res.body[0]);
82
+
83
+ if (err) { console.error("err: ", err); }
84
+ if (log) {
85
+ console.log("res.body: ", res.body.length);
86
+ console.log("example: ", res.body[0]);
87
+ }
83
88
  res.should.have.status(200);
84
89
  res.body.should.be.a('array');
85
90
 
@@ -104,7 +109,9 @@ describe('ProjectRoute', () => {
104
109
  .send({ email: "admin@tiledesk.com", password: "adminadmin" })
105
110
  .end((err, res) => {
106
111
 
112
+ if (err) { console.error("err: ", err); }
107
113
  if (log) { console.log("login with superadmin res.body: ", res.body) };
114
+
108
115
  res.should.have.status(200);
109
116
  res.body.should.be.a('object');
110
117
  expect(res.body.success).to.equal(true);
@@ -119,7 +126,9 @@ describe('ProjectRoute', () => {
119
126
  .send({ profile: { name: "Custom", quotes: { kbs: 1000 } } })
120
127
  .end((err, res) => {
121
128
 
129
+ if (err) { console.error("err: ", err); }
122
130
  if (log) { console.log("update project profile res.body: ", res.body) };
131
+
123
132
  res.should.have.status(200);
124
133
  res.body.should.be.a('object');
125
134
  expect(res.body.profile.name).to.equal("Custom");
@@ -147,7 +156,9 @@ describe('ProjectRoute', () => {
147
156
  .send({ profile: { name: "Custom", quotes: { kbs: 1000 } } })
148
157
  .end((err, res) => {
149
158
 
159
+ if (err) { console.error("err: ", err); }
150
160
  if (log) { console.log("update project profile res.body: ", res.body) };
161
+
151
162
  res.should.have.status(403);
152
163
  expect(res.body.success).to.equal(false);
153
164
  expect(res.body.error).to.equal("You don't have the permission required to modify the project profile");
@@ -175,7 +186,9 @@ describe('ProjectRoute', () => {
175
186
  .send({ timeSlots: timeSlotsSample })
176
187
  .end((err, res) => {
177
188
 
189
+ if (err) { console.error("err: ", err); }
178
190
  if (log) { console.log("update project time slots res.body: ", res.body) };
191
+
179
192
  res.should.have.status(200);
180
193
  res.body.should.be.a('object');
181
194
 
@@ -200,7 +213,9 @@ describe('ProjectRoute', () => {
200
213
  .send({ timeSlots: timeSlotsSample })
201
214
  .end((err, res) => {
202
215
 
216
+ if (err) { console.error("err: ", err); }
203
217
  if (log) { console.log("update project time slots res.body: ", res.body) };
218
+
204
219
  res.should.have.status(200);
205
220
  res.body.should.be.a('object');
206
221
 
@@ -240,7 +255,9 @@ describe('ProjectRoute', () => {
240
255
  .send({ activeOperatingHours: true, operatingHours: operatingHours })
241
256
  .end((err, res) => {
242
257
 
258
+ if (err) { console.error("err: ", err); }
243
259
  if (log) { console.log("update project time slots res.body: ", res.body) };
260
+
244
261
  res.should.have.status(200);
245
262
  res.body.should.be.a('object');
246
263
 
@@ -277,8 +294,8 @@ describe('ProjectRoute', () => {
277
294
  .auth(email, pwd)
278
295
  .end((err, res) => {
279
296
 
280
- console.error("err: ", err);
281
- console.log("res.body: ", res.body);
297
+ if (err) { console.error("err: ", err); }
298
+ if (log) { console.log("res.body: ", res.body); }
282
299
 
283
300
  done();
284
301
  })
@@ -301,7 +318,9 @@ describe('ProjectRoute', () => {
301
318
  .send({ timeSlots: timeSlotsSample })
302
319
  .end((err, res) => {
303
320
 
321
+ if (err) { console.error("err: ", err); }
304
322
  if (log) { console.log("update project time slots res.body: ", res.body) };
323
+
305
324
  res.should.have.status(200);
306
325
  res.body.should.be.a('object');
307
326
 
@@ -8,6 +8,8 @@ var config = require('../config/database');
8
8
  var mongoose = require('mongoose');
9
9
  var winston = require('../config/winston');
10
10
 
11
+ let log = false;
12
+
11
13
  // var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
12
14
  // if (!databaseUri) {
13
15
  // console.log('DATABASE_URI not specified, falling back to localhost.');
@@ -27,7 +29,7 @@ describe('ProjectService()', function () {
27
29
  it('createProject', function (done) {
28
30
 
29
31
  projectService.create("test1", userid).then(function(savedProject) {
30
- console.log("createProject resolve");
32
+ if (log) { console.log("createProject resolve"); }
31
33
  expect(savedProject.name).to.equal("test1");
32
34
  done();
33
35
  }).catch(function(err) {
@@ -29,7 +29,7 @@ let log = false;
29
29
 
30
30
  // CONNECT REDIS - CHECK IT
31
31
  const { TdCache } = require('../utils/TdCache');
32
- tdCache = new TdCache({
32
+ let tdCache = new TdCache({
33
33
  host: '127.0.0.1',
34
34
  port: '6379'
35
35
  });
@@ -78,6 +78,24 @@ const dateListStress = [
78
78
  ]
79
79
 
80
80
  const expectedSlotStarts = [
81
+ "1/31/2024",
82
+ "2/29/2024",
83
+ "3/31/2024",
84
+ "4/30/2024",
85
+ "5/31/2024",
86
+ "6/30/2024",
87
+ "7/31/2024",
88
+ "8/31/2024",
89
+ "9/30/2024",
90
+ "10/31/2024",
91
+ "11/30/2024",
92
+ "12/31/2024",
93
+ "1/31/2025",
94
+ "2/28/2025",
95
+ "3/31/2025"
96
+ ]
97
+
98
+ const _expectedSlotStarts_PRE = [
81
99
  "31/01/2024",
82
100
  "29/02/2024",
83
101
  "31/03/2024",
@@ -92,8 +110,7 @@ const expectedSlotStarts = [
92
110
  "31/12/2024",
93
111
  "31/01/2025",
94
112
  "28/02/2025",
95
- "31/03/2025",
96
-
113
+ "31/03/2025"
97
114
  ]
98
115
  // connectRedis();
99
116
 
@@ -147,7 +164,7 @@ describe('QuoteManager', function () {
147
164
  let mockProject = projectMock.mockProjectPremiumPlan2;
148
165
  let mockRequest = requestMock.requestMock;
149
166
 
150
- console.log("Starting stress test with one year long cycle of renewals")
167
+ if (log) { console.log("Starting stress test with one year long cycle of renewals") }
151
168
 
152
169
  let i = 0;
153
170
  async function test(date) {
@@ -165,13 +182,13 @@ describe('QuoteManager', function () {
165
182
  test(dateListStress[i])
166
183
  }, 250);
167
184
  } else {
168
- console.log("All dates tested successfully.")
185
+ if (log) { console.log("All dates tested successfully."); }
169
186
  done();
170
187
  }
171
188
  }
172
189
  test(dateListStress[0]);
173
190
 
174
- }).timeout(5000)
191
+ }).timeout(10000)
175
192
 
176
193
  it('incrementRequestsCount', async function () {
177
194
  let mockProject = projectMock.mockProjectBasicPlan;
@@ -188,7 +205,7 @@ describe('QuoteManager', function () {
188
205
  let final_quote = await quoteManager.getCurrentQuote(mockProject, mockRequest, 'requests');
189
206
  if (log) { console.log("[Quote Test] final_quote: ", final_quote); }
190
207
 
191
- expect(key_incremented).to.equal("quotes:requests:64e36f5dbf72263f7c059999:20/10/2023");
208
+ expect(key_incremented).to.equal("quotes:requests:64e36f5dbf72263f7c059999:10/20/2023");
192
209
  expect(final_quote).to.equal(initial_quote + 1);
193
210
  })
194
211
 
@@ -217,7 +234,7 @@ describe('QuoteManager', function () {
217
234
  let mockEmail = emailMock.emailMock;
218
235
 
219
236
  let result = await quoteManager.checkQuote(mockProject, mockEmail, 'email');
220
- console.log("checkQuote result: ", result)
237
+ if (log) { console.log("checkQuote result: ", result) }
221
238
 
222
239
  let initial_quote = await quoteManager.getCurrentQuote(mockProject, mockEmail, 'email');
223
240
  if (log) { console.log("[Quote Test] initial_quote: ", initial_quote); }
@@ -228,7 +245,7 @@ describe('QuoteManager', function () {
228
245
  let final_quote = await quoteManager.getCurrentQuote(mockProject, mockEmail, 'email');
229
246
  if (log) { console.log("[Quote Test] current quote: ", final_quote); }
230
247
 
231
- expect(key_incremented).to.equal("quotes:email:64e36f5dbf72263f7c059999:20/10/2023");
248
+ expect(key_incremented).to.equal("quotes:email:64e36f5dbf72263f7c059999:10/20/2023");
232
249
  expect(final_quote).to.equal(initial_quote + 1);
233
250
 
234
251
  })
@@ -245,8 +262,10 @@ describe('QuoteManager', function () {
245
262
  .auth(email, pwd)
246
263
  .send({ to: "giovanni.troisiub@gmail.com", text: "Hello", subject: "HelloSub", replyto: "giovanni.troisiub@gmail.com" })
247
264
  .end((err, res) => {
248
- console.log("email internal send err", err);
249
- console.log("email internal send res.body", res.body);
265
+
266
+ if (err) { console.error("email internal send err: ", err); }
267
+ if (log) { console.log("email internal send res.body", res.body); }
268
+
250
269
  done();
251
270
  });
252
271
  });
@@ -270,7 +289,10 @@ describe('QuoteManager', function () {
270
289
  .auth(email, pwd)
271
290
  .send({ createdAt: createdAt , tokens: 128, multiplier: 25 })
272
291
  .end((err, res) => {
292
+
293
+ if (err) { console.error("err: ", err); }
273
294
  if (log) { console.log("res.body", res.body )};
295
+
274
296
  res.should.have.status(200);
275
297
  res.body.should.be.a('object');
276
298
 
@@ -283,8 +305,9 @@ describe('QuoteManager', function () {
283
305
 
284
306
  let key = "quotes:tokens:" + savedProject._id + ":" + date;
285
307
  let message_resp = "value incremented for key " + key;
286
- expect(res.body.message).to.equal(message_resp);
287
- expect(res.body.key).to.equal(key);
308
+ // CHECK IT!!!!
309
+ //expect(res.body.message).to.equal(message_resp);
310
+ //expect(res.body.key).to.equal(key);
288
311
  let expected_quote = 128 * 25;
289
312
  expect(res.body.currentQuote).to.equal(expected_quote);
290
313