@tiledesk/tiledesk-server 2.9.31 → 2.9.32

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.9.32
9
+ - Added voice filters in get requests
10
+ - Added endpoint to get all projects
11
+ - Updated vxml-connector to 0.1.49
12
+
8
13
  # 2.9.31
9
14
  - Improved conversations queues management
10
15
  - Added conversation status 150 (ABANDONED)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.9.31",
4
+ "version": "2.9.32",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -52,7 +52,7 @@
52
52
  "@tiledesk/tiledesk-whatsapp-connector": "^0.1.73",
53
53
  "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.8",
54
54
  "@tiledesk/tiledesk-sms-connector": "^0.1.10",
55
- "@tiledesk/tiledesk-vxml-connector": "^0.1.44",
55
+ "@tiledesk/tiledesk-vxml-connector": "^0.1.49",
56
56
  "amqplib": "^0.5.5",
57
57
  "app-root-path": "^3.0.0",
58
58
  "bcrypt-nodejs": "0.0.3",
package/routes/project.js CHANGED
@@ -13,7 +13,7 @@ var Group = require('../models/group');
13
13
 
14
14
  var winston = require('../config/winston');
15
15
  var roleChecker = require('../middleware/has-role');
16
-
16
+ var config = require('../config/database');
17
17
 
18
18
  // THE THREE FOLLOWS IMPORTS ARE USED FOR AUTHENTICATION IN THE ROUTE
19
19
  var passport = require('passport');
@@ -25,6 +25,24 @@ var orgUtil = require("../utils/orgUtil");
25
25
  var cacheEnabler = require("../services/cacheEnabler");
26
26
  var mongoose = require('mongoose');
27
27
 
28
+ var jwt = require('jsonwebtoken');
29
+ // CHECK IT ASAP!!!!
30
+ let configSecret = process.env.GLOBAL_SECRET || config.secret;
31
+ var pKey = process.env.GLOBAL_SECRET_OR_PRIVATE_KEY;
32
+ // console.log("pKey",pKey);
33
+
34
+ if (pKey) {
35
+ configSecret = pKey.replace(/\\n/g, '\n');
36
+ }
37
+
38
+ let pubConfigSecret = process.env.GLOBAL_SECRET || config.secret;
39
+ var pubKey = process.env.GLOBAL_SECRET_OR_PUB_KEY;
40
+ if (pubKey) {
41
+ pubConfigSecret = pubKey.replace(/\\n/g, '\n');
42
+ }
43
+ // CHECK IT ASAP!!!!
44
+
45
+
28
46
  router.post('/', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], async (req, res) => {
29
47
 
30
48
  // create(name, createdBy, settings)
@@ -735,6 +753,95 @@ Project.findByIdAndUpdate(req.params.projectid, { $pull: { bannedUsers: { "_id":
735
753
 
736
754
  });
737
755
 
756
+ router.get('/all', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], function (req, res) {
757
+
758
+ if (req.headers.authorization) {
759
+
760
+ let token = req.headers.authorization.split(" ")[1];
761
+ let decode = jwt.verify(token, pubConfigSecret)
762
+ if (decode && (decode.email === process.env.ADMIN_EMAIL)) {
763
+
764
+ Project.aggregate([
765
+ // {
766
+ // $match: {
767
+ // status: 100,
768
+ // //createdAt: { $gte: startDate}
769
+ // },
770
+ // },
771
+ {
772
+ $sort: {
773
+ createdAt: -1
774
+ },
775
+ },
776
+ {
777
+ $lookup: {
778
+ from: 'project_users',
779
+ localField: '_id',
780
+ foreignField: 'id_project',
781
+ as: 'project_user',
782
+ pipeline: [
783
+ { $match: { role: 'owner' } }
784
+ ]
785
+ }
786
+ },
787
+ {
788
+ $addFields: {
789
+ project_user: { $arrayElemAt: ['$project_user', 0] }
790
+ }
791
+ },
792
+ {
793
+ $lookup: {
794
+ from: 'users',
795
+ localField: 'project_user.id_user',
796
+ foreignField: '_id',
797
+ as: 'user'
798
+ },
799
+ },
800
+ {
801
+ $addFields: {
802
+ user: { $arrayElemAt: ['$user', 0] }
803
+ }
804
+ }
805
+ ])
806
+ .then((projects) => {
807
+ winston.verbose("Projects found " + projects.length)
808
+ // const fieldsToKeep = ['_id', 'name', 'createdBy', 'createdAt', 'user.email' ];
809
+
810
+ const filteredProjects = projects.map(project => {
811
+ const filteredProject = {};
812
+ filteredProject._id = project._id;
813
+ filteredProject.name = project.name;
814
+ filteredProject.owner = project.user?.email;
815
+ filteredProject.createdAt = project.createdAt;
816
+ filteredProject.profile_name = project.profile?.name;
817
+ // ... add other fields here
818
+
819
+ // fieldsToKeep.forEach(field => {
820
+ // if (project[field] !== undefined) {
821
+ // filteredProject[field] = project[field];
822
+ // }
823
+ // });
824
+ return filteredProject;
825
+ });
826
+
827
+ return res.status(200).send(filteredProjects);
828
+ })
829
+ .catch((err) => {
830
+ console.error(err);
831
+ return res.status(500).send({ success: false, error: err});
832
+ });
833
+
834
+ // let updatedUser = await User.findByIdAndUpdate(savedUser._id, { emailverified: true }, { new: true }).exec();
835
+ // winston.debug("updatedUser: ", updatedUser);
836
+ // skipVerificationEmail = true;
837
+ // winston.verbose("skip sending verification email")
838
+ } else {
839
+ return res.status(403).send({ success: false, error: "You don't have the permission required to perform the operation"});
840
+ }
841
+
842
+ }
843
+
844
+ });
738
845
 
739
846
 
740
847
  //roleChecker.hasRole('agent') works because req.params.projectid is valid using :projectid of this method
package/routes/request.js CHANGED
@@ -884,7 +884,10 @@ router.get('/', function (req, res, next) {
884
884
 
885
885
  var page = 0;
886
886
  var limit = DEFAULT_LIMIT; // Number of request per page
887
+ var page = 0;
888
+ var skip = 0;
887
889
  let statusArray = [];
890
+ var projectuser = req.projectuser;
888
891
 
889
892
  if (req.query.limit) {
890
893
  limit = parseInt(req.query.limit);
@@ -897,19 +900,16 @@ router.get('/', function (req, res, next) {
897
900
  page = req.query.page;
898
901
  }
899
902
 
900
- var skip = page * limit;
901
- winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
903
+ skip = page * limit;
902
904
 
903
- // Default Query
905
+ // Default query
904
906
  var query = { "id_project": req.projectid, "status": { $lt: 1000, $ne: 150 }, preflight: false };
905
907
 
906
- var projectuser = req.projectuser;
907
-
908
908
  if (req.user instanceof Subscription) {
909
- //all request
909
+ // All request
910
910
  } else if (projectuser && (projectuser.role == "owner" || projectuser.role == "admin")) {
911
- // all request
912
- // per uni mostrare solo quelle proprie quindi solo participants
911
+ // All request
912
+ // Per uni mostrare solo quelle proprie quindi solo participants
913
913
  if (req.query.mine) {
914
914
  query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
915
915
  }
@@ -919,7 +919,6 @@ router.get('/', function (req, res, next) {
919
919
 
920
920
  if (req.query.dept_id) {
921
921
  query.department = req.query.dept_id;
922
- winston.debug('REQUEST ROUTE - QUERY DEPT ID', query.department);
923
922
  }
924
923
 
925
924
  if (req.query.requester_email) {
@@ -927,27 +926,13 @@ router.get('/', function (req, res, next) {
927
926
  }
928
927
 
929
928
  if (req.query.full_text) {
930
- winston.debug('req.query.fulltext', req.query.full_text);
931
929
  query.$text = { "$search": req.query.full_text };
932
930
  }
933
931
 
934
- var history_search = false; // ? serve ancora?
935
-
936
- // if (req.query.status) {
937
- // winston.debug('req.query.status', req.query.status);
938
- // query.status = req.query.status;
939
-
940
- // if (req.query.status == 1000 || req.query.status == "1000") {
941
- // history_search = true;
942
- // }
943
- // if (req.query.status === "all") {
944
- // history_search = true;
945
- // delete query.status;
946
- // }
947
- // }
932
+ var history_search = false;
948
933
 
934
+ // Multiple status management
949
935
  if (req.query.status) {
950
-
951
936
  if (req.query.status === 'all') {
952
937
  delete query.status;
953
938
  } else {
@@ -961,40 +946,27 @@ router.get('/', function (req, res, next) {
961
946
  delete query.status;
962
947
  }
963
948
  }
964
-
965
949
  if (statusArray.length > 0) {
966
950
  query.status = {
967
951
  $in: statusArray
968
952
  }
969
953
  }
970
-
971
954
  }
972
955
 
973
956
  if (req.query.lead) {
974
- winston.debug('req.query.lead', req.query.lead);
975
957
  query.lead = req.query.lead;
976
958
  }
977
959
 
978
960
  // USERS & BOTS
979
961
  if (req.query.participant) {
980
- winston.debug('req.query.participant', req.query.participant);
981
962
  query.participants = req.query.participant;
982
963
  }
983
964
 
984
- winston.debug('req.query.hasbot', req.query.hasbot);
985
965
  if (req.query.hasbot != undefined) {
986
- winston.debug('req.query.hasbot', req.query.hasbot);
987
966
  query.hasBot = req.query.hasbot;
988
967
  }
989
968
 
990
- // if (req.query.waiting_time_exists) { //non basta aggiungi anche che nn è null
991
- // query.waiting_time = {"$exists": req.query.waiting_time_exists} //{$ne:null}
992
- // winston.debug('REQUEST ROUTE - QUERY waiting_time_exists', query.waiting_time_exists);
993
- // }
994
-
995
-
996
969
  if (req.query.tags) {
997
- winston.debug('req.query.tags', req.query.tags);
998
970
  query["tags.tag"] = req.query.tags;
999
971
  }
1000
972
 
@@ -1026,9 +998,7 @@ router.get('/', function (req, res, next) {
1026
998
  //fixato. secondo me qui manca un parentesi tonda per gli or
1027
999
  if (history_search === true && req.project && req.project.profile && ((req.project.profile.type === 'free' && req.project.trialExpired === true) || (req.project.profile.type === 'payment' && req.project.isActiveSubscription === false))) {
1028
1000
 
1029
-
1030
1001
  var startdate = moment().subtract(14, "days").format("YYYY-MM-DD");
1031
-
1032
1002
  var enddate = moment().format("YYYY-MM-DD");
1033
1003
 
1034
1004
  winston.debug('»»» REQUEST ROUTE - startdate ', startdate);
@@ -1037,11 +1007,8 @@ router.get('/', function (req, res, next) {
1037
1007
  var enddatePlusOneDay = moment(new Date()).add(1, 'days').toDate()
1038
1008
  winston.debug('»»» REQUEST ROUTE - enddate + 1 days: ', enddatePlusOneDay);
1039
1009
 
1040
- // var enddatePlusOneDay = "2019-09-17T00:00:00.000Z"
1041
-
1042
1010
  query.createdAt = { $gte: new Date(Date.parse(startdate)).toISOString(), $lte: new Date(enddatePlusOneDay).toISOString() }
1043
1011
  winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
1044
-
1045
1012
  }
1046
1013
 
1047
1014
  /**
@@ -1072,9 +1039,6 @@ router.get('/', function (req, res, next) {
1072
1039
  var newdate = new Date(date);
1073
1040
  var endDate_plusOneDay = newdate.setDate(newdate.getDate() + 1);
1074
1041
  winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED END DATE + 1 DAY ', endDate_plusOneDay);
1075
- // var endDate_plusOneDay = moment('2018-09-03').add(1, 'd')
1076
- // var endDate_plusOneDay = endDate.add(1).day();
1077
- // var toDate = new Date(Date.parse(endDate_plusOneDay)).toISOString()
1078
1042
 
1079
1043
  query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString(), $lte: new Date(endDate_plusOneDay).toISOString() }
1080
1044
  winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
@@ -1092,44 +1056,34 @@ router.get('/', function (req, res, next) {
1092
1056
 
1093
1057
  winston.debug('REQUEST ROUTE - QUERY CREATED AT (only for start date)', query.createdAt);
1094
1058
  }
1095
- // }
1096
-
1097
-
1098
1059
 
1099
1060
  if (req.query.snap_department_routing) {
1100
1061
  query["snapshot.department.routing"] = req.query.snap_department_routing;
1101
- winston.debug('REQUEST ROUTE - QUERY snap_department_routing', query.snap_department_routing);
1102
1062
  }
1103
1063
 
1104
1064
  if (req.query.snap_department_default) {
1105
1065
  query["snapshot.department.default"] = req.query.snap_department_default;
1106
- winston.debug('REQUEST ROUTE - QUERY snap_department_default', query.snap_department_default);
1107
1066
  }
1108
1067
 
1109
1068
 
1110
1069
  if (req.query.snap_department_id_bot) {
1111
1070
  query["snapshot.department.id_bot"] = req.query.snap_department_id_bot;
1112
- winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot', query.snap_department_id_bot);
1113
1071
  }
1114
1072
 
1115
1073
  if (req.query.snap_department_id_bot_exists) {
1116
1074
  query["snapshot.department.id_bot"] = { "$exists": req.query.snap_department_id_bot_exists }
1117
- winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot_exists', query.snap_department_id_bot_exists);
1118
1075
  }
1119
1076
 
1120
1077
  if (req.query.snap_lead_lead_id) {
1121
1078
  query["snapshot.lead.lead_id"] = req.query.snap_lead_lead_id;
1122
- winston.debug('REQUEST ROUTE - QUERY snap_lead_lead_id', query.snap_lead_lead_id);
1123
1079
  }
1124
1080
 
1125
1081
  if (req.query.snap_lead_email) {
1126
1082
  query["snapshot.lead.email"] = req.query.snap_lead_email;
1127
- winston.debug('REQUEST ROUTE - QUERY snap_lead_email', query.snap_lead_email);
1128
1083
  }
1129
1084
 
1130
1085
  if (req.query.smartAssignment) {
1131
1086
  query.smartAssignment = req.query.smartAssignment;
1132
- winston.debug('REQUEST ROUTE - QUERY smartAssignment', query.smartAssignment);
1133
1087
  }
1134
1088
 
1135
1089
  if (req.query.channel) {
@@ -1140,8 +1094,6 @@ router.get('/', function (req, res, next) {
1140
1094
  } else {
1141
1095
  query["channel.name"] = req.query.channel
1142
1096
  }
1143
-
1144
- winston.debug('REQUEST ROUTE - QUERY channel', query.channel);
1145
1097
  }
1146
1098
 
1147
1099
  if (req.query.priority) {
@@ -1153,17 +1105,37 @@ router.get('/', function (req, res, next) {
1153
1105
  if (req.query.direction) {
1154
1106
  direction = req.query.direction;
1155
1107
  }
1156
- winston.debug("direction", direction);
1157
1108
 
1158
1109
  var sortField = "createdAt";
1159
1110
  if (req.query.sort) {
1160
1111
  sortField = req.query.sort;
1161
1112
  }
1162
- winston.debug("sortField", sortField);
1163
1113
 
1164
1114
  var sortQuery = {};
1165
1115
  sortQuery[sortField] = direction;
1166
- winston.debug("sort query", sortQuery);
1116
+
1117
+ // VOICE FILTERS - Start
1118
+ if (req.query.caller) {
1119
+ query["attributes.caller_phone"] = req.query.caller;
1120
+ }
1121
+ if (req.query.called) {
1122
+ query["attributes.called_phone"] = req.query.called;
1123
+ }
1124
+ if (req.query.call_id) {
1125
+ query["attributes.call_id"] = req.query.call_id;
1126
+ }
1127
+ // VOICE FILTERS - End
1128
+
1129
+ if (req.query.duration && req.query.duration_op) {
1130
+ let duration = Number(req.query.duration) * 60 * 1000;
1131
+ if (req.query.duration_op === 'gt') {
1132
+ query.duration = { $gte: duration }
1133
+ } else if (req.query.duration_op === 'lt') {
1134
+ query.duration = { $lte: duration }
1135
+ } else {
1136
+ winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
1137
+ }
1138
+ }
1167
1139
 
1168
1140
  if (req.query.abandonded && (req.query.abandoned === true || req.query.abandoned === 'true')) {
1169
1141
  query["attributes.fully_abandoned"] = true
@@ -1173,26 +1145,21 @@ router.get('/', function (req, res, next) {
1173
1145
  query.draft = { $in: [false, null] }
1174
1146
  }
1175
1147
 
1176
- winston.debug('REQUEST ROUTE - REQUEST FIND ', query);
1177
-
1178
1148
  var projection = undefined;
1179
1149
 
1180
1150
  if (req.query.full_text) {
1181
-
1182
1151
  if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
1183
- winston.info('fulltext projection on');
1152
+ winston.verbose('fulltext projection on');
1184
1153
  projection = { score: { $meta: "textScore" } };
1185
1154
  }
1186
-
1187
1155
  }
1188
- // requestcachefarequi populaterequired
1156
+
1157
+ winston.verbose('REQUEST ROUTE - REQUEST FIND QUERY ', query);
1158
+
1189
1159
  var q1 = Request.find(query, projection).
1190
1160
  skip(skip).limit(limit);
1191
1161
 
1192
- winston.debug('REQUEST ROUTE no_populate:' + req.query.no_populate);
1193
-
1194
1162
  if (req.query.no_populate != "true" && req.query.no_populate != true) {
1195
- winston.verbose('REQUEST ROUTE - no_polutate false ', req.headers);
1196
1163
  q1.populate('department').
1197
1164
  populate('participatingBots'). //nico già nn gli usa
1198
1165
  populate('participatingAgents'). //nico già nn gli usa
@@ -1200,17 +1167,7 @@ router.get('/', function (req, res, next) {
1200
1167
  populate({ path: 'requester', populate: { path: 'id_user' } }); //toglilo perche nico lo prende già da snapshot
1201
1168
  }
1202
1169
 
1203
- // cache(cacheUtil.defaultTTL, "requests-"+projectId).
1204
-
1205
-
1206
- // if (req.query.select_snapshot) {
1207
- // winston.info('select_snapshot');
1208
- // q1.select("+snapshot");
1209
- // // q1.select({ "snapshot": 1});
1210
- // }
1211
-
1212
1170
  if (req.query.full_text) {
1213
- winston.debug('fulltext sort');
1214
1171
  if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
1215
1172
  q1.sort({ score: { $meta: "textScore" } }) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
1216
1173
  }
@@ -1218,10 +1175,6 @@ router.get('/', function (req, res, next) {
1218
1175
  q1.sort(sortQuery);
1219
1176
  }
1220
1177
 
1221
-
1222
- // winston.info('q1',q1);
1223
-
1224
-
1225
1178
  q1.exec();
1226
1179
 
1227
1180
  // TODO if ?onlycount=true do not perform find query but only
@@ -1234,10 +1187,7 @@ router.get('/', function (req, res, next) {
1234
1187
  q2 = 0;
1235
1188
  }
1236
1189
 
1237
- var promises = [
1238
- q1,
1239
- q2
1240
- ];
1190
+ var promises = [ q1, q2 ];
1241
1191
 
1242
1192
  Promise.all(promises).then(function (results) {
1243
1193
  var objectToReturn = {
@@ -1664,11 +1614,6 @@ router.get('/csv', function (req, res, next) {
1664
1614
  query.$text = { "$search": req.query.full_text };
1665
1615
  }
1666
1616
 
1667
- // if (req.query.status) {
1668
- // winston.debug('req.query.status', req.query.status);
1669
- // query.status = req.query.status;
1670
- // }
1671
-
1672
1617
  if (req.query.status) {
1673
1618
 
1674
1619
  if (req.query.status === 'all') {
@@ -1776,6 +1721,27 @@ router.get('/csv', function (req, res, next) {
1776
1721
 
1777
1722
  winston.debug("sort query", sortQuery);
1778
1723
 
1724
+ if (req.query.channel) {
1725
+ if (req.query.channel === "offline") {
1726
+ query["channel.name"] = { "$in": ["email", "form"] }
1727
+ } else if (req.query.channel === "online") {
1728
+ query["channel.name"] = { "$nin": ["email", "form"] }
1729
+ } else {
1730
+ query["channel.name"] = req.query.channel
1731
+ }
1732
+ }
1733
+
1734
+ // VOICE FILTERS - Start
1735
+ if (req.query.caller) {
1736
+ query["attributes.caller_phone"] = req.query.caller;
1737
+ }
1738
+ if (req.query.called) {
1739
+ query["attributes.called_phone"] = req.query.called;
1740
+ }
1741
+ if (req.query.call_id) {
1742
+ query["attributes.call_id"] = req.query.call_id;
1743
+ }
1744
+ // VOICE FILTERS - End
1779
1745
 
1780
1746
  // TODO ORDER BY SCORE
1781
1747
  // return Faq.find(query, {score: { $meta: "textScore" } })
@@ -1783,6 +1749,21 @@ router.get('/csv', function (req, res, next) {
1783
1749
 
1784
1750
  // aggiungi filtro per data marco
1785
1751
 
1752
+ if (req.query.duration && req.query.duration_op) {
1753
+ let duration = Number(req.query.duration) * 60 * 1000;
1754
+ if (req.query.duration_op === 'gt') {
1755
+ query.duration = { $gte: duration }
1756
+ } else if (req.query.duration_op === 'lt') {
1757
+ query.duration = { $lte: duration }
1758
+ } else {
1759
+ winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
1760
+ }
1761
+ }
1762
+
1763
+ if (req.query.draft && (req.query.draft === 'false' || req.query.draft === false)) {
1764
+ query.draft = { $in: [false, null] }
1765
+ }
1766
+
1786
1767
  winston.debug('REQUEST ROUTE - REQUEST FIND ', query)
1787
1768
  return Request.find(query, '-transcript -status -__v').
1788
1769
  skip(skip).limit(limit).
@@ -1860,7 +1841,17 @@ router.get('/csv', function (req, res, next) {
1860
1841
  // // da terminare e testare. potrebbe essere troppo lenta la query per tanti record
1861
1842
  // element.participatingAgents = participatingAgents;
1862
1843
 
1863
-
1844
+ if (element.attributes) {
1845
+ if (element.attributes.caller_phone) {
1846
+ element.caller_phone = element.attributes.caller_phone;
1847
+ }
1848
+ if (element.attributes.called_phone) {
1849
+ element.called_phone = element.attributes.called_phone;
1850
+ }
1851
+ if (element.attributes.caller_phone) {
1852
+ element.call_id = element.attributes.call_id;
1853
+ }
1854
+ }
1864
1855
 
1865
1856
  delete element.lead;
1866
1857
 
@@ -50,6 +50,47 @@ describe('ProjectRoute', () => {
50
50
 
51
51
  describe('/create', () => {
52
52
 
53
+ it('getAllProjectsWithSuperAdminCredential', (done) => {
54
+
55
+ var email = "test-signup-" + Date.now() + "@email.com";
56
+ var pwd = "pwd";
57
+
58
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
59
+ projectService.create("test-project-create-1", savedUser._id).then(() => {
60
+ projectService.create("test-project-create-2", savedUser._id).then((savedProject2) => {
61
+
62
+ chai.request(server)
63
+ .post('/auth/signin')
64
+ .send({ email: "admin@tiledesk.com", password: "adminadmin" })
65
+ // .send({ email: email, password: pwd }) // con queste credenziali non si può fare la richiesta /projects/all
66
+ .end((err, res) => {
67
+
68
+ if (log) { console.log("login with superadmin res.body: ", res.body) };
69
+ res.should.have.status(200);
70
+ res.body.should.be.a('object');
71
+ expect(res.body.success).to.equal(true);
72
+ expect(res.body.token).not.equal(null);
73
+
74
+ let superadmin_token = res.body.token;
75
+
76
+ chai.request(server)
77
+ .get('/projects/all')
78
+ .set('Authorization', superadmin_token)
79
+ .end((err, res) => {
80
+
81
+ console.log("res.body: ", res.body.length);
82
+ console.log("example: ", res.body[0]);
83
+ res.should.have.status(200);
84
+ res.body.should.be.a('array');
85
+
86
+ done()
87
+ })
88
+ })
89
+ })
90
+ })
91
+ })
92
+ }).timeout(10000)
93
+
53
94
  it('updateProjectProfileWithSuperAdminCredential', (done) => {
54
95
 
55
96
  var email = "test-signup-" + Date.now() + "@email.com";