@tiledesk/tiledesk-server 2.10.15 → 2.10.16

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 +6 -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
@@ -11,6 +11,8 @@ var config = require('../config/database');
11
11
  var mongoose = require('mongoose');
12
12
  var winston = require('../config/winston');
13
13
 
14
+ let log = false;
15
+
14
16
  // var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
15
17
  // if (!databaseUri) {
16
18
  // console.log('DATABASE_URI not specified, falling back to localhost.');
@@ -130,7 +132,7 @@ describe('RequestService', function () {
130
132
  let obj = { createdAt: new Date() }
131
133
 
132
134
  let quotes = await qm.getAllQuotes(savedProject, obj);
133
- console.log("quotes: ", quotes);
135
+ if (log) { console.log("quotes: ", quotes); }
134
136
  // quotes.requests.quote.should.be.a('string');
135
137
  // expect(quotes.requests.quote).to.equal('1');
136
138
 
@@ -139,7 +141,7 @@ describe('RequestService', function () {
139
141
 
140
142
 
141
143
  }).catch(function (err) {
142
- console.log("test reject", err);
144
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
143
145
  assert.isNotOk(err, 'Promise error');
144
146
  // done();
145
147
  });
@@ -183,11 +185,11 @@ describe('RequestService', function () {
183
185
  expect(savedRequest.participantsAgents).to.contains(userid);
184
186
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
185
187
  expect(savedRequest.hasBot).to.equal(false);
186
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
188
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
187
189
  expect(savedRequest.participants[0].toString()).to.equal(userid);
188
190
  expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
189
191
  expect(savedRequest.assigned_at).to.not.equal(null);
190
- console.log("savedRequest.participants1");
192
+ if (log) { console.log("savedRequest.participants1"); }
191
193
 
192
194
  expect(savedRequest.snapshot.department.name).to.not.equal(null);
193
195
  expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
@@ -196,7 +198,7 @@ describe('RequestService', function () {
196
198
  expect(savedRequest.snapshot.requester.role).to.equal("owner");
197
199
  expect(savedRequest.snapshot.requester.isAuthenticated).to.equal(true);
198
200
  // expect(savedRequest.snapshot.requester.role).to.equal("owner");
199
- console.log("savedRequest.participants2");
201
+ if (log) { console.log("savedRequest.participants2"); }
200
202
 
201
203
  expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
202
204
 
@@ -204,20 +206,20 @@ describe('RequestService', function () {
204
206
  // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
205
207
 
206
208
  expect(savedRequest.id_project).to.equal(savedProject._id.toString());
207
- console.log("savedRequest.participants3");
209
+ if (log) { console.log("savedRequest.participants3"); }
208
210
  // aiuto
209
211
  // expect(savedRequest.department).to.equal("requester_id1");
210
212
 
211
213
  requestService.create(request).then(function (savedRequest) {
212
214
  // assert.isNotOk('No duplicate check index');
213
- console.log("no index check ???");
215
+ if (log) { console.log("no index check ???"); }
214
216
  // done();
215
217
  }).catch(function (err) {
216
- console.log("ok duplicate check index ", err);
218
+ if (log) { console.log("ok duplicate check index ", err); }
217
219
  done();
218
220
  });
219
221
  }).catch(function (err) {
220
- console.log("test reject", err);
222
+ if (log) { console.log("test reject", err); }
221
223
  assert.isNotOk(err, 'Promise error');
222
224
  // done();
223
225
  });
@@ -261,7 +263,7 @@ describe('RequestService', function () {
261
263
  expect(savedRequest.participantsAgents).to.contains(userid);
262
264
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
263
265
  expect(savedRequest.hasBot).to.equal(false);
264
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
266
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
265
267
  expect(savedRequest.participants[0].toString()).to.equal(userid);
266
268
  expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
267
269
  expect(savedRequest.assigned_at).to.not.equal(null);
@@ -288,12 +290,14 @@ describe('RequestService', function () {
288
290
  expect(updatedLead.email).to.equal("email2@email2.com");
289
291
  expect(updatedLead.id_project).to.equal(savedProject._id.toString());
290
292
  expect(updatedLead.lead_id).to.not.equal(createdLead.id);
291
- console.log("updatedLead", updatedLead);
293
+ if (log) { console.log("updatedLead", updatedLead); }
292
294
 
293
295
  requestEvent.on('request.update.snapshot.lead', function (data) {
294
296
 
295
297
  Request.findById(savedRequest._id, function (err, request) {
296
- console.log("err", err);
298
+
299
+ if (err) { console.error("err", err); }
300
+
297
301
  expect(request.request_id).to.equal("request_idcreateObjSimpleUpdateLeadUpdateSnapshot-" + now);
298
302
  expect(request.snapshot.lead.fullname).to.equal("fullname2");
299
303
  done();
@@ -307,7 +311,7 @@ describe('RequestService', function () {
307
311
 
308
312
 
309
313
  }).catch(function (err) {
310
- console.log("test reject", err);
314
+ if (log) { console.log("test reject", err); }
311
315
  assert.isNotOk(err, 'Promise error');
312
316
  done();
313
317
  });
@@ -354,7 +358,7 @@ describe('RequestService', function () {
354
358
  expect(savedRequest.participantsAgents).to.contains(userid);
355
359
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
356
360
  expect(savedRequest.hasBot).to.equal(false);
357
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
361
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
358
362
  expect(savedRequest.participants[0].toString()).to.equal(userid);
359
363
  expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
360
364
  expect(savedRequest.assigned_at).to.not.equal(null);
@@ -377,7 +381,7 @@ describe('RequestService', function () {
377
381
  // expect(savedRequest.department).to.equal("requester_id1");
378
382
  done();
379
383
  }).catch(function (err) {
380
- console.log("test reject", err);
384
+ if (log) { console.log("test reject", err); }
381
385
  assert.isNotOk(err, 'Promise error');
382
386
  done();
383
387
  });
@@ -425,7 +429,7 @@ describe('RequestService', function () {
425
429
  expect(savedRequest.participantsAgents).to.have.lengthOf(0);
426
430
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
427
431
  expect(savedRequest.hasBot).to.equal(false);
428
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
432
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
429
433
  expect(savedRequest.assigned_at).to.equal(undefined);
430
434
 
431
435
  expect(savedRequest.snapshot.department.name).to.not.equal(null);
@@ -446,7 +450,7 @@ describe('RequestService', function () {
446
450
  // expect(savedRequest.department).to.equal("requester_id1");
447
451
  done();
448
452
  }).catch(function (err) {
449
- console.log("test reject", err);
453
+ if (log) { console.log("test reject", err); }
450
454
  assert.isNotOk(err, 'Promise error');
451
455
  done();
452
456
  });
@@ -479,7 +483,7 @@ describe('RequestService', function () {
479
483
  expect(savedRequest.participantsAgents).to.contains(userid);
480
484
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
481
485
  expect(savedRequest.hasBot).to.equal(false);
482
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
486
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
483
487
  expect(savedRequest.participants[0].toString()).to.equal(userid);
484
488
  expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
485
489
  expect(savedRequest.assigned_at).to.not.equal(null);
@@ -498,7 +502,7 @@ describe('RequestService', function () {
498
502
  // expect(savedRequest.department).to.equal("requester_id1");
499
503
  done();
500
504
  }).catch(function (err) {
501
- console.log("test reject", err);
505
+ if (log) { console.log("test reject", err); }
502
506
  assert.isNotOk(err, 'Promise error');
503
507
  done();
504
508
  });
@@ -530,7 +534,7 @@ describe('RequestService', function () {
530
534
  if (savedRequest.request_id === "createWithIdAndCreateNewLeadAndCheckRequestEvent-" + now) {
531
535
 
532
536
 
533
- console.log("savedRequest", savedRequest.toJSON());
537
+ if (log) { console.log("savedRequest", savedRequest.toJSON()); }
534
538
 
535
539
  winston.debug("resolve", savedRequest.toObject());
536
540
  expect(savedRequest.request_id).to.equal("createWithIdAndCreateNewLeadAndCheckRequestEvent-" + now);
@@ -543,7 +547,7 @@ describe('RequestService', function () {
543
547
  expect(savedRequest.participantsAgents).to.contains(userid);
544
548
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
545
549
  expect(savedRequest.hasBot).to.equal(false);
546
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
550
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
547
551
  expect(savedRequest.participants[0].toString()).to.equal(userid);
548
552
 
549
553
  expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
@@ -566,7 +570,7 @@ describe('RequestService', function () {
566
570
  requestService.createWithIdAndRequester("createWithIdAndCreateNewLeadAndCheckRequestEvent-" + now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function (savedRequest) {
567
571
 
568
572
  }).catch(function (err) {
569
- console.log("test reject", err);
573
+ if (log) { console.log("test reject", err); }
570
574
  assert.isNotOk(err, 'Promise error');
571
575
  done();
572
576
  });
@@ -633,7 +637,7 @@ describe('RequestService', function () {
633
637
  var now = Date.now();
634
638
  // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
635
639
  requestService.createWithIdAndRequester("request_id-createWithIdAndCreatedBy-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", null, null, null, null, null, "user1").then(function (savedRequest) {
636
- console.log("test resolve");
640
+
637
641
  expect(savedRequest.request_id).to.equal("request_id-createWithIdAndCreatedBy-" + now);
638
642
  expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
639
643
  expect(savedRequest.first_text).to.equal("first_text");
@@ -655,7 +659,7 @@ describe('RequestService', function () {
655
659
  done();
656
660
  })
657
661
  .catch(function (err) {
658
- console.log("test reject", err);
662
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
659
663
  assert.isNotOk(err, 'Promise error');
660
664
  done();
661
665
  });
@@ -683,7 +687,7 @@ describe('RequestService', function () {
683
687
 
684
688
  })
685
689
  .catch(function (err) {
686
- console.log("test reject", err);
690
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
687
691
  done();
688
692
  });
689
693
  });
@@ -720,7 +724,7 @@ describe('RequestService', function () {
720
724
  expect(savedRequest.department.toString()).to.equal(createdDepartment._id.toString());
721
725
  done();
722
726
  }).catch(function (err) {
723
- console.log("test reject", err);
727
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
724
728
  assert.isNotOk(err, 'Promise error');
725
729
  done();
726
730
  });
@@ -752,7 +756,7 @@ describe('RequestService', function () {
752
756
  savedProject._id, messageSender)]).then(function (all) {
753
757
  requestService.updateWaitingTimeByRequestId(savedRequest.request_id, savedProject._id, true).then(function (upRequest) {
754
758
  var maxWaitingTime = Date.now() - upRequest.createdAt;
755
- console.log("resolve closedRequest", upRequest.toObject(), maxWaitingTime);
759
+ if (log) { console.log("resolve closedRequest", upRequest.toObject(), maxWaitingTime); }
756
760
 
757
761
  expect(upRequest.status).to.equal(200);
758
762
  // console.log("1")
@@ -994,9 +998,7 @@ describe('RequestService', function () {
994
998
 
995
999
  return newProject_user.save(function (err, savedProject_user) {
996
1000
 
997
- if (err) {
998
- console.log("err", err)
999
- }
1001
+ if (err) { console.log("err", err); }
1000
1002
 
1001
1003
  var now = Date.now();
1002
1004
  requestService.createWithIdAndRequester("request_id-addparticipant-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
@@ -1033,7 +1035,7 @@ describe('RequestService', function () {
1033
1035
 
1034
1036
  done();
1035
1037
  }).catch(function (err) {
1036
- console.log("test reject", err);
1038
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1037
1039
  assert.isNotOk(err, 'Promise error');
1038
1040
  done();
1039
1041
  });
@@ -1078,9 +1080,7 @@ describe('RequestService', function () {
1078
1080
 
1079
1081
  return newProject_user.save(function (err, savedProject_user) {
1080
1082
 
1081
- if (err) {
1082
- console.log("err", err)
1083
- }
1083
+ if (err) { console.log("err", err) }
1084
1084
  var now = Date.now();
1085
1085
 
1086
1086
  requestService.createWithIdAndRequester("request_id1-setParticipantsByRequestId-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
@@ -1117,7 +1117,7 @@ describe('RequestService', function () {
1117
1117
 
1118
1118
  done();
1119
1119
  }).catch(function (err) {
1120
- console.log("test reject", err);
1120
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1121
1121
  assert.isNotOk(err, 'Promise error');
1122
1122
  done();
1123
1123
  });
@@ -1204,7 +1204,7 @@ describe('RequestService', function () {
1204
1204
  expect(savedRequest.hasBot).to.equal(false);
1205
1205
  expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1206
1206
 
1207
- console.log("savedRequest.department", savedRequest.department);
1207
+ if (log) { console.log("savedRequest.department", savedRequest.department); }
1208
1208
  // expect(savedRequest.department.name).to.equal("Default");
1209
1209
 
1210
1210
  // departmentService.create("AssignedDepartment-for-routeDepartmentSameAgentSameDepartmentSkipUpdate", savedProject._id, 'assigned', userid).then(function(createdDepartment) {
@@ -1224,7 +1224,7 @@ describe('RequestService', function () {
1224
1224
  expect(routedRequest.hasBot).to.equal(false);
1225
1225
  expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1226
1226
 
1227
- console.log("routedRequest.department.name", routedRequest.department.name);
1227
+ if (log) { console.log("routedRequest.department.name", routedRequest.department.name); }
1228
1228
  expect(routedRequest.department._id.toString()).to.equal(dep.toString());
1229
1229
  expect(routedRequest.snapshot.department._id.toString()).to.equal(dep.toString());
1230
1230
 
@@ -1233,7 +1233,7 @@ describe('RequestService', function () {
1233
1233
  });
1234
1234
 
1235
1235
  }).catch(function (err) {
1236
- console.log("test reject", err);
1236
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1237
1237
  assert.isNotOk(err, 'Promise error');
1238
1238
  done();
1239
1239
  });
@@ -1270,7 +1270,7 @@ describe('RequestService', function () {
1270
1270
  expect(savedRequest.hasBot).to.equal(false);
1271
1271
  expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1272
1272
 
1273
- console.log("savedRequest.department", savedRequest.department);
1273
+ if (log) { console.log("savedRequest.department", savedRequest.department); }
1274
1274
  // expect(savedRequest.department.name).to.equal("Default");
1275
1275
 
1276
1276
  departmentService.create("AssignedDepartment-for-routeDepartmentSameAgentDifferentDepartment", savedProject._id, 'assigned', userid).then(function (createdDepartment) {
@@ -1289,7 +1289,7 @@ describe('RequestService', function () {
1289
1289
  expect(routedRequest.hasBot).to.equal(false);
1290
1290
  expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1291
1291
 
1292
- console.log("routedRequest.department.name", routedRequest.department.name);
1292
+ if (log) { console.log("routedRequest.department.name", routedRequest.department.name); }
1293
1293
  expect(routedRequest.department._id.toString()).to.equal(createdDepartment._id.toString());
1294
1294
  expect(routedRequest.snapshot.department._id.toString()).to.equal(createdDepartment._id.toString());
1295
1295
 
@@ -1298,7 +1298,7 @@ describe('RequestService', function () {
1298
1298
  });
1299
1299
 
1300
1300
  }).catch(function (err) {
1301
- console.log("test reject", err);
1301
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1302
1302
  assert.isNotOk(err, 'Promise error');
1303
1303
  done();
1304
1304
  });
@@ -1364,7 +1364,7 @@ describe('RequestService', function () {
1364
1364
  expect(savedRequest.hasBot).to.equal(false);
1365
1365
  expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1366
1366
 
1367
- console.log("savedRequest.department", savedRequest.department);
1367
+ if (log) { console.log("savedRequest.department", savedRequest.department); }
1368
1368
  // expect(savedRequest.department.name).to.equal("Default");
1369
1369
 
1370
1370
 
@@ -1377,7 +1377,7 @@ describe('RequestService', function () {
1377
1377
  updatedBy: userid
1378
1378
  });
1379
1379
  newGroup.save(function (err, savedGroup) {
1380
- console.log("savedGroup", savedGroup)
1380
+ if (log) { console.log("savedGroup", savedGroup); }
1381
1381
 
1382
1382
 
1383
1383
 
@@ -1386,7 +1386,7 @@ describe('RequestService', function () {
1386
1386
 
1387
1387
  createdDepartment.id_group = newGroup._id;
1388
1388
  createdDepartment.save(function (err, savedGroupDepartment) {
1389
- console.log("savedGroupDepartment", savedGroupDepartment)
1389
+ if (log) { console.log("savedGroupDepartment", savedGroupDepartment); }
1390
1390
 
1391
1391
 
1392
1392
  // route(request_id, departmentid, id_project, nobot, no_populate) {
@@ -1404,7 +1404,7 @@ describe('RequestService', function () {
1404
1404
  expect(routedRequest.hasBot).to.equal(false);
1405
1405
  expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1406
1406
 
1407
- console.log("routedRequest.department.name", routedRequest.department.name);
1407
+ if (log) { console.log("routedRequest.department.name", routedRequest.department.name); }
1408
1408
  expect(routedRequest.department._id.toString()).to.equal(createdDepartment._id.toString());
1409
1409
  expect(routedRequest.snapshot.department._id.toString()).to.equal(createdDepartment._id.toString());
1410
1410
 
@@ -1468,7 +1468,7 @@ describe('RequestService', function () {
1468
1468
 
1469
1469
  done();
1470
1470
  }).catch(function (err) {
1471
- console.log("test reject", err);
1471
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1472
1472
  assert.isNotOk(err, 'Promise error');
1473
1473
  done();
1474
1474
  });
@@ -1552,7 +1552,7 @@ describe('RequestService', function () {
1552
1552
 
1553
1553
 
1554
1554
  }).catch(function (err) {
1555
- console.log("test reject", err);
1555
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1556
1556
  assert.isNotOk(err, 'Promise error');
1557
1557
  done();
1558
1558
  });
@@ -1596,7 +1596,7 @@ describe('RequestService', function () {
1596
1596
 
1597
1597
 
1598
1598
  }).catch(function (err) {
1599
- console.log("test reject", err);
1599
+ if (log) { console.log("savedRequest.participants[0]", savedRequest.participants[0]); }
1600
1600
  assert.isNotOk(err, 'Promise error');
1601
1601
  done();
1602
1602
  });
@@ -1620,7 +1620,7 @@ describe('RequestService', function () {
1620
1620
 
1621
1621
  var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor');
1622
1622
  // var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
1623
- console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor);
1623
+ if (log) { console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor); }
1624
1624
  microLanguageTransformerInterceptor.listen();
1625
1625
 
1626
1626
 
@@ -1687,7 +1687,7 @@ describe('RequestService', function () {
1687
1687
 
1688
1688
  // var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor');
1689
1689
  var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
1690
- console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor);
1690
+ if (log) { console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor); }
1691
1691
  microLanguageTransformerInterceptor.listen();
1692
1692
 
1693
1693
 
@@ -1772,7 +1772,7 @@ describe('RequestService', function () {
1772
1772
 
1773
1773
  var snapshotAgents = await Request.findById(savedRequest.id).select({ "snapshot": 1 }).exec();
1774
1774
 
1775
- console.log("snapshotAgents", snapshotAgents);
1775
+ if (log) { console.log("snapshotAgents", snapshotAgents); }
1776
1776
 
1777
1777
  expect(snapshotAgents.snapshot.agents.length).to.equal(1);
1778
1778
  // return;
package/test/userRoute.js CHANGED
@@ -4,6 +4,7 @@ process.env.NODE_ENV = 'test';
4
4
  let chai = require('chai');
5
5
  let chaiHttp = require('chai-http');
6
6
  let server = require('../app');
7
+ let should = chai.should();
7
8
 
8
9
  chai.use(chaiHttp);
9
10
 
@@ -14,6 +15,8 @@ var config = require('../config/database');
14
15
  var mongoose = require('mongoose');
15
16
  var winston = require('../config/winston');
16
17
 
18
+ let log = false;
19
+
17
20
  // var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
18
21
  // if (!databaseUri) {
19
22
  // console.log('DATABASE_URI not specified, falling back to localhost.');
@@ -23,11 +26,12 @@ var winston = require('../config/winston');
23
26
  mongoose.connect(config.databasetest);
24
27
 
25
28
  var userService = require('../services/userService');
29
+ const projectService = require('../services/projectService');
26
30
 
27
31
 
28
32
  describe('UserService()', function () {
29
33
 
30
- it('loginemail', (done) => {
34
+ it('loginemail', function (done) {
31
35
  var now = Date.now();
32
36
  var email = "test-UserService-signup-" + now + "@email.com";
33
37
  var pwd = "pwd";
@@ -36,17 +40,42 @@ describe('UserService()', function () {
36
40
  expect(savedUser.email).to.equal("test-userservice-signup-" + now + "@email.com");
37
41
  expect(savedUser.firstname).to.equal( "Test Firstname");
38
42
  expect(savedUser.lastname).to.equal("Test lastname");
43
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
39
44
 
40
- chai.request(server)
41
- .post('/users/loginemail')
45
+ chai.request(server)
46
+ .post('/' + savedProject._id + '/faq_kb')
42
47
  .auth(email, pwd)
43
- .send({ "id_project": "123456789" })
48
+ .send({ "name": "testbot", type: "internal", template: "example", language: 'en' })
44
49
  .end((err, res) => {
45
- console.log("res.body: ", res.body);
46
- console.log("res.status: ", res.status);
47
-
48
- done();
50
+
51
+ if (err) { console.error("err: ", err); }
52
+ if (log) { console.log("res.body: ", res.body); }
53
+
54
+ res.should.have.status(200);
55
+
56
+ let bot_id = res.body._id;
57
+
58
+ chai.request(server)
59
+ .post('/users/loginemail')
60
+ .auth(email, pwd)
61
+ .send({ "id_project": savedProject._id, bot_id: bot_id })
62
+ .end((err, res) => {
63
+
64
+ if (err) { console.error("err: ", err); }
65
+ if (log) { console.log("res.body: ", res.body); }
66
+
67
+ res.should.have.status(200);
68
+ res.body.should.be.a('object');
69
+ expect(res.body.success).to.equal(true);
70
+ expect(res.body.message).to.equal("Sending email...");
71
+
72
+ done();
73
+ })
49
74
  })
75
+ })
76
+
77
+
78
+
50
79
 
51
80
 
52
81
  }).catch(function(err) {
@@ -11,6 +11,8 @@ var config = require('../config/database');
11
11
  var mongoose = require('mongoose');
12
12
  var winston = require('../config/winston');
13
13
 
14
+ let log = false;
15
+
14
16
  // var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
15
17
  // if (!databaseUri) {
16
18
  // console.log('DATABASE_URI not specified, falling back to localhost.');
@@ -36,16 +38,17 @@ describe('UserService()', function () {
36
38
 
37
39
  var email = "test-userservice-signup-" + Date.now() + "@email.com";
38
40
 
39
- userService.signup( email ,"pwd", "Test Firstname", "Test lastname").then(function(savedUser) {
40
- console.log("savedUser resolve");
41
- expect(savedUser.email).to.equal(email);
42
- expect(savedUser.firstname).to.equal( "Test Firstname");
43
- expect(savedUser.lastname).to.equal("Test lastname");
44
- done();
45
- }).catch(function(err) {
46
- winston.error("test reject", err);
47
- assert.isNotOk(err,'Promise error');
48
- done();
41
+ userService.signup(email, "pwd", "Test Firstname", "Test lastname").then(function (savedUser) {
42
+
43
+ if (log) { console.log("savedUser resolve"); }
44
+ expect(savedUser.email).to.equal(email);
45
+ expect(savedUser.firstname).to.equal("Test Firstname");
46
+ expect(savedUser.lastname).to.equal("Test lastname");
47
+ done();
48
+ }).catch(function (err) {
49
+ winston.error("test reject", err);
50
+ assert.isNotOk(err, 'Promise error');
51
+ done();
49
52
  });
50
53
  });
51
54
 
@@ -55,16 +58,16 @@ describe('UserService()', function () {
55
58
  var now = Date.now();
56
59
  var email = "test-UserService-signup-" + now + "@email.com";
57
60
 
58
- userService.signup( email ,"pwd", "Test Firstname", "Test lastname").then(function(savedUser) {
59
- console.log("savedUser resolve");
60
- expect(savedUser.email).to.equal("test-userservice-signup-" + now + "@email.com");
61
- expect(savedUser.firstname).to.equal( "Test Firstname");
62
- expect(savedUser.lastname).to.equal("Test lastname");
63
- done();
64
- }).catch(function(err) {
65
- winston.error("test reject", err);
66
- assert.isNotOk(err,'Promise error');
67
- done();
61
+ userService.signup(email, "pwd", "Test Firstname", "Test lastname").then(function (savedUser) {
62
+ if (log) { console.log("savedUser resolve"); }
63
+ expect(savedUser.email).to.equal("test-userservice-signup-" + now + "@email.com");
64
+ expect(savedUser.firstname).to.equal("Test Firstname");
65
+ expect(savedUser.lastname).to.equal("Test lastname");
66
+ done();
67
+ }).catch(function (err) {
68
+ console.error("test reject", err);
69
+ assert.isNotOk(err, 'Promise error');
70
+ done();
68
71
  });
69
72
  });
70
73
 
@@ -73,7 +76,7 @@ describe('UserService()', function () {
73
76
 
74
77
  // var email = "test-signup-" + Date.now() + "@email.com";
75
78
  // userService.signup( email ,"pwd", "Test Firstname", "Test lastname").then(function(savedUser) {
76
-
79
+
77
80
  // // var r = new Request({requester_id: 'test',first_text:'ft',id_project:'123', createdBy: '123', requester: new Requester({ref: savedUser, type:'user'})});
78
81
  // // var r = new Request({requester_id: 'test',first_text:'ft',id_project:'123', createdBy: '123', requester:savedUser._id});
79
82
  // var r = new Request({requester_id: 'test',first_text:'ft',id_project:'123', createdBy: '123', requester:savedUser._id, requesterModel:'user'});
@@ -85,7 +88,7 @@ describe('UserService()', function () {
85
88
  // winston.info("req1", req1.toObject());
86
89
  // done();
87
90
  // });
88
-
91
+
89
92
  // });
90
93
  // });
91
94
  // });
@@ -98,16 +101,16 @@ describe('UserService()', function () {
98
101
 
99
102
  // var eventSchema = new mongoose.Schema({time: Date}, options);
100
103
  // var Event = mongoose.model('Event', eventSchema);
101
-
104
+
102
105
  // // ClickedLinkEvent is a special type of Event that has
103
106
  // // a URL.
104
107
  // var ClickedLinkEvent = Event.discriminator('ClickedLink',
105
108
  // new mongoose.Schema({url: String}, options));
106
-
109
+
107
110
  // // When you create a generic event, it can't have a URL field...
108
111
  // var genericEvent = new Event({time: Date.now(), url: 'google.com'});
109
112
  // assert.ok(!genericEvent.url);
110
-
113
+
111
114
  // // But a ClickedLinkEvent can
112
115
  // var clickedEvent =
113
116
  // new ClickedLinkEvent({time: Date.now(), url: 'google.com'});
@@ -115,7 +118,7 @@ describe('UserService()', function () {
115
118
 
116
119
  // clickedEvent.save(function(err, saved) {
117
120
  // console.log("saved", err);
118
-
121
+
119
122
  // });
120
123
 
121
124
 
@@ -128,10 +131,10 @@ describe('UserService()', function () {
128
131
  // } else {
129
132
  // assert.ok(false);
130
133
  // }
131
-
134
+
132
135
  // });
133
136
 
134
-
137
+
135
138
 
136
139
  // });
137
140
 
@@ -143,9 +146,9 @@ describe('UserService()', function () {
143
146
  // // admin.auth().getUser('5aaa99024c3b110014b478f0')
144
147
  // // admin.auth().getUser('5bf3cbbc20cb5d0015702910')
145
148
  // admin.auth().getUser('5b55e806c93dde00143163dd_12345678910')
146
-
147
-
148
-
149
+
150
+
151
+
149
152
  // .then(function(userRecord) {
150
153
  // // See the UserRecord reference doc for the contents of userRecord.
151
154
  // console.log("Successfully fetched user data:", userRecord.toJSON());
@@ -17,7 +17,7 @@ class PromiseUtil {
17
17
  values.push(value);
18
18
  };
19
19
 
20
- console.log("values",values);
20
+ //console.log("values",values);
21
21
  // return resolve(values);
22
22
 
23
23
  // });