@tiledesk/tiledesk-server 2.10.33 → 2.10.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/app.js +1 -1
- package/jobs.js +3 -0
- package/jobsManager.js +8 -0
- package/models/analytics.js +29 -0
- package/package.json +5 -4
- package/pubmodules/analytics/analytics.js +84 -0
- package/pubmodules/sms/listener.js +0 -1
- package/pubmodules/voice-twilio/listener.js +0 -1
- package/routes/kb.js +15 -36
- package/routes/lead.js +71 -0
- package/routes/request.js +146 -1
- package/services/Scheduler.js +12 -0
- package/services/requestService.js +3 -3
- package/test/leadRoute.js +156 -0
- package/test/requestRoute.js +366 -146
package/test/requestRoute.js
CHANGED
@@ -1,40 +1,33 @@
|
|
1
1
|
//During the test the env variable is set to test
|
2
2
|
process.env.NODE_ENV = 'test';
|
3
3
|
|
4
|
-
var User = require('../models/user');
|
5
|
-
|
6
4
|
var projectService = require('../services/projectService');
|
7
5
|
var requestService = require('../services/requestService');
|
8
6
|
var userService = require('../services/userService');
|
9
7
|
var leadService = require('../services/leadService');
|
8
|
+
var faqService = require('../services/faqService');
|
10
9
|
|
10
|
+
var Department = require('../models/department');
|
11
|
+
var winston = require('../config/winston');
|
11
12
|
|
12
13
|
//Require the dev-dependencies
|
13
14
|
let chai = require('chai');
|
14
15
|
let chaiHttp = require('chai-http');
|
15
16
|
let server = require('../app');
|
16
17
|
let should = chai.should();
|
17
|
-
var
|
18
|
+
var expect = chai.expect;
|
19
|
+
var assert = chai.assert;
|
18
20
|
|
19
|
-
var Department = require('../models/department');
|
20
|
-
var faqService = require('../services/faqService');
|
21
21
|
// require('../services/mongoose-cache-fn')(mongoose);
|
22
|
-
|
23
22
|
// chai.config.includeStack = true;
|
24
23
|
|
25
24
|
let log = false;
|
26
25
|
|
27
|
-
var expect = chai.expect;
|
28
|
-
var assert = chai.assert;
|
29
|
-
|
30
26
|
chai.use(chaiHttp);
|
31
27
|
|
32
28
|
describe('RequestRoute', () => {
|
33
29
|
|
34
|
-
|
35
|
-
|
36
30
|
// mocha test/requestRoute.js --grep 'createSimple'
|
37
|
-
|
38
31
|
it('createSimple', function (done) {
|
39
32
|
// this.timeout(10000);
|
40
33
|
|
@@ -87,6 +80,8 @@ describe('RequestRoute', () => {
|
|
87
80
|
});
|
88
81
|
});
|
89
82
|
|
83
|
+
|
84
|
+
// mocha test/requestRoute.js --grep 'create-simple-new-note'
|
90
85
|
it('create-simple-new-note', function (done) {
|
91
86
|
// this.timeout(10000);
|
92
87
|
|
@@ -138,6 +133,7 @@ describe('RequestRoute', () => {
|
|
138
133
|
});
|
139
134
|
|
140
135
|
|
136
|
+
// mocha test/requestRoute.js --grep 'createSimpleAndCloseForDuration'
|
141
137
|
it('createSimpleAndCloseForDuration', function (done) {
|
142
138
|
// this.timeout(10000);
|
143
139
|
|
@@ -188,8 +184,7 @@ describe('RequestRoute', () => {
|
|
188
184
|
}).timeout(5000);
|
189
185
|
|
190
186
|
|
191
|
-
|
192
|
-
|
187
|
+
// mocha test/requestRoute.js --grep 'createUpperCaseEmail'
|
193
188
|
it('createUpperCaseEmail', function (done) {
|
194
189
|
// this.timeout(10000);
|
195
190
|
|
@@ -244,8 +239,6 @@ describe('RequestRoute', () => {
|
|
244
239
|
});
|
245
240
|
|
246
241
|
|
247
|
-
|
248
|
-
|
249
242
|
// mocha test/requestRoute.js --grep 'getbyid'
|
250
243
|
it('getbyid', function (done) {
|
251
244
|
// this.timeout(10000);
|
@@ -308,8 +301,9 @@ describe('RequestRoute', () => {
|
|
308
301
|
});
|
309
302
|
});
|
310
303
|
});
|
311
|
-
// mocha test/requestRoute.js --grep 'getbyidWithPartecipatingBots'
|
312
304
|
|
305
|
+
|
306
|
+
// mocha test/requestRoute.js --grep 'getbyidWithPartecipatingBots'
|
313
307
|
it('getbyidWithPartecipatingBots', function (done) {
|
314
308
|
// this.timeout(10000);
|
315
309
|
|
@@ -384,7 +378,6 @@ describe('RequestRoute', () => {
|
|
384
378
|
|
385
379
|
|
386
380
|
// mocha test/requestRoute.js --grep 'getallSimple'
|
387
|
-
|
388
381
|
it('getallSimple', function (done) {
|
389
382
|
// this.timeout(10000);
|
390
383
|
|
@@ -470,9 +463,7 @@ describe('RequestRoute', () => {
|
|
470
463
|
});
|
471
464
|
|
472
465
|
|
473
|
-
|
474
466
|
// mocha test/requestRoute.js --grep 'getallNoPopulate'
|
475
|
-
|
476
467
|
it('getallNoPopulate', function (done) {
|
477
468
|
// this.timeout(10000);
|
478
469
|
|
@@ -549,11 +540,7 @@ describe('RequestRoute', () => {
|
|
549
540
|
});
|
550
541
|
|
551
542
|
|
552
|
-
|
553
|
-
|
554
|
-
|
555
543
|
// mocha test/requestRoute.js --grep 'getallSimple'
|
556
|
-
|
557
544
|
it('getallFilter-snap_department_routing', function (done) {
|
558
545
|
// this.timeout(10000);
|
559
546
|
|
@@ -638,10 +625,7 @@ describe('RequestRoute', () => {
|
|
638
625
|
});
|
639
626
|
|
640
627
|
|
641
|
-
|
642
|
-
|
643
628
|
// mocha test/requestRoute.js --grep 'getallFilter-snap_department_default'
|
644
|
-
|
645
629
|
it('getallFilter-snap_department_default', function (done) {
|
646
630
|
// this.timeout(10000);
|
647
631
|
|
@@ -726,10 +710,7 @@ describe('RequestRoute', () => {
|
|
726
710
|
});
|
727
711
|
|
728
712
|
|
729
|
-
|
730
|
-
|
731
713
|
// mocha test/requestRoute.js --grep 'snap_department_id_bot_exists'
|
732
|
-
|
733
714
|
it('getallFilter-snap_department_id_bot_exists', function (done) {
|
734
715
|
// this.timeout(10000);
|
735
716
|
|
@@ -864,9 +845,7 @@ describe('RequestRoute', () => {
|
|
864
845
|
});
|
865
846
|
|
866
847
|
|
867
|
-
|
868
|
-
|
869
|
-
|
848
|
+
// mocha test/requestRoute.js --grep 'getallWithLoLead'
|
870
849
|
it('getallWithLoLead', function (done) {
|
871
850
|
// this.timeout(10000);
|
872
851
|
|
@@ -918,13 +897,365 @@ describe('RequestRoute', () => {
|
|
918
897
|
});
|
919
898
|
|
920
899
|
|
921
|
-
|
900
|
+
// mocha test/requestRoute.js --grep 'countConversations'
|
901
|
+
it('countConversations', function (done) {
|
902
|
+
// this.timeout(10000);
|
903
|
+
|
904
|
+
var email = "test-request-create-" + Date.now() + "@email.com";
|
905
|
+
var pwd = "pwd";
|
922
906
|
|
907
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
908
|
+
projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
|
923
909
|
|
910
|
+
chai.request(server)
|
911
|
+
.post('/' + savedProject._id + '/requests/')
|
912
|
+
.auth(email, pwd)
|
913
|
+
.set('content-type', 'application/json')
|
914
|
+
.send({ "first_text": "first_text" })
|
915
|
+
.end(function (err, res) {
|
924
916
|
|
917
|
+
if (err) { console.log("err: ", err) };
|
918
|
+
if (log) { console.log("res.body: ", res.body) };
|
925
919
|
|
926
|
-
|
920
|
+
res.should.have.status(200);
|
921
|
+
res.body.should.be.a('object');
|
922
|
+
|
923
|
+
chai.request(server)
|
924
|
+
.get('/' + savedProject._id + '/requests/count?conversation_quota=true')
|
925
|
+
.auth(email, pwd)
|
926
|
+
.end((err, res) => {
|
927
|
+
|
928
|
+
if (err) { console.log("err: ", err) };
|
929
|
+
if (log) { console.log("res.body: ", res.body) };
|
930
|
+
|
931
|
+
res.should.have.status(200);
|
932
|
+
|
933
|
+
done();
|
934
|
+
})
|
935
|
+
|
936
|
+
});
|
937
|
+
});
|
938
|
+
});
|
939
|
+
});
|
940
|
+
|
941
|
+
|
942
|
+
// mocha test/requestRoute.js --grep 'exludeDraftConversations'
|
943
|
+
it('exludeDraftConversations', (done) => {
|
944
|
+
|
945
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
946
|
+
var pwd = "pwd";
|
947
|
+
|
948
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
949
|
+
projectService.createAndReturnProjectAndProjectUser("test-draft-conversation", savedUser._id).then((savedProjectAndPU) => {
|
950
|
+
let savedProject = savedProjectAndPU.project;
|
951
|
+
let savedPU = savedProjectAndPU.project_user;
|
952
|
+
leadService.createIfNotExists("Lead Fullname", "email@test.com", savedProject._id).then((createdLead) => {
|
953
|
+
let now = Date.now();
|
954
|
+
let request = {
|
955
|
+
request_id: "request_id-exludeDraftConversations-" + now,
|
956
|
+
project_user_id: savedPU._id,
|
957
|
+
lead_id: createdLead._id,
|
958
|
+
id_project: savedProject._id,
|
959
|
+
first_text: "first_text",
|
960
|
+
lead: createdLead,
|
961
|
+
requester: savedPU,
|
962
|
+
attributes: { sourcePage: "https://widget-pre.tiledesk.com/v2/index.html?tiledesk_projectid=5ce3d1ceb25ad30017279999&td_draft=true" }
|
963
|
+
}
|
964
|
+
|
965
|
+
requestService.create(request).then(async (savedRequest) => {
|
966
|
+
|
967
|
+
// Case 1 - request with source page that contains td_draft
|
968
|
+
expect(savedRequest.draft).to.equal(true);
|
969
|
+
|
970
|
+
// Case 2 - request without source page that contains td_draft
|
971
|
+
//expect(savedRequest.draft).to.be.undefined;
|
972
|
+
|
973
|
+
// get all requests -> should be 0
|
974
|
+
|
975
|
+
chai.request(server)
|
976
|
+
.get('/' + savedProject._id + '/requests?draft=false')
|
977
|
+
.auth(email, pwd)
|
978
|
+
.end((err, res) => {
|
979
|
+
|
980
|
+
if (err) { console.error("err: ", err ) };
|
981
|
+
if (log) { console.log("res.body: ", res.body) }
|
982
|
+
|
983
|
+
res.should.have.status(200);
|
984
|
+
res.body.should.be.a('object');
|
985
|
+
res.body.requests.should.be.a('array');
|
986
|
+
|
987
|
+
// Case 1 - request with source page that contains td_draft
|
988
|
+
expect(res.body.requests.length).to.equal(0);
|
989
|
+
|
990
|
+
// Case 2 - request without source page that contains td_draft
|
991
|
+
//expect(res.body.requests.length).to.equal(1);
|
992
|
+
|
993
|
+
done();
|
994
|
+
})
|
995
|
+
|
996
|
+
|
997
|
+
}).catch((err) => {
|
998
|
+
console.error("error creating request: ", err)
|
999
|
+
})
|
1000
|
+
})
|
1001
|
+
|
1002
|
+
})
|
1003
|
+
})
|
1004
|
+
|
1005
|
+
})
|
1006
|
+
|
1007
|
+
|
1008
|
+
// mocha test/requestRoute.js --grep 'add-tag-to-conversation'
|
1009
|
+
it('add-tag-to-conversation', function (done) {
|
1010
|
+
|
1011
|
+
var email = "test-request-create-" + Date.now() + "@email.com";
|
1012
|
+
var pwd = "pwd";
|
1013
|
+
|
1014
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1015
|
+
projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
|
1016
|
+
|
1017
|
+
chai.request(server)
|
1018
|
+
.post('/' + savedProject._id + '/requests/')
|
1019
|
+
.auth(email, pwd)
|
1020
|
+
.set('content-type', 'application/json')
|
1021
|
+
.send({ "first_text": "first_text" })
|
1022
|
+
.end(function (err, res) {
|
1023
|
+
|
1024
|
+
if (err) { console.log("err: ", err) };
|
1025
|
+
if (log) { console.log("res.body: ", res.body) };
|
1026
|
+
|
1027
|
+
res.should.have.status(200);
|
1028
|
+
res.body.should.be.a('object');
|
1029
|
+
res.body.should.have.property('request_id').not.eql(null);
|
1030
|
+
|
1031
|
+
let request_id = res.body.request_id;
|
1032
|
+
|
1033
|
+
let tags = [
|
1034
|
+
{ tag: "tag1", color: "#43B1F2" },
|
1035
|
+
{ tag: "tag2", color: "#43B1F2" }
|
1036
|
+
]
|
1037
|
+
|
1038
|
+
// First Step: add 2 tags on a conversation no tagged at all
|
1039
|
+
chai.request(server)
|
1040
|
+
.put('/' + savedProject._id + '/requests/' + request_id + '/tag' )
|
1041
|
+
.auth(email, pwd)
|
1042
|
+
.send(tags)
|
1043
|
+
.end((err, res) => {
|
1044
|
+
|
1045
|
+
if (err) { console.log("err: ", err) };
|
1046
|
+
if (log) { console.log("res.body: ", res.body) };
|
1047
|
+
|
1048
|
+
res.should.have.status(200);
|
1049
|
+
res.body.should.be.a('object');
|
1050
|
+
expect(res.body.tags).to.have.length(2);
|
1051
|
+
expect(res.body.tags[0].tag).to.equal('tag1');
|
1052
|
+
expect(res.body.tags[1].tag).to.equal('tag2');
|
1053
|
+
|
1054
|
+
let tags2 = [
|
1055
|
+
{ tag: "tag2", color: "#43B1F2"},
|
1056
|
+
{ tag: "tag3", color: "#43B1F2"}
|
1057
|
+
]
|
1058
|
+
|
1059
|
+
// Second Step: add more 2 tags of which one already existant in the conversation
|
1060
|
+
chai.request(server)
|
1061
|
+
.put('/' + savedProject._id + '/requests/' + request_id + '/tag')
|
1062
|
+
.auth(email, pwd)
|
1063
|
+
.send(tags2)
|
1064
|
+
.end((err, res) => {
|
1065
|
+
|
1066
|
+
if (err) { console.log("err: ", err) };
|
1067
|
+
if (log) { console.log("res.body: ", res.body) };
|
1068
|
+
|
1069
|
+
res.should.have.status(200);
|
1070
|
+
res.body.should.be.a('object');
|
1071
|
+
expect(res.body.tags).to.have.length(3);
|
1072
|
+
expect(res.body.tags[0].tag).to.equal('tag1');
|
1073
|
+
expect(res.body.tags[1].tag).to.equal('tag2');
|
1074
|
+
expect(res.body.tags[2].tag).to.equal('tag3');
|
1075
|
+
|
1076
|
+
done();
|
1077
|
+
})
|
1078
|
+
|
1079
|
+
})
|
1080
|
+
|
1081
|
+
});
|
1082
|
+
});
|
1083
|
+
});
|
1084
|
+
});
|
1085
|
+
|
1086
|
+
// mocha test/requestRoute.js --grep 'remove-tag-from-conversation'
|
1087
|
+
it('remove-tag-from-conversation', function (done) {
|
1088
|
+
|
1089
|
+
var email = "test-request-create-" + Date.now() + "@email.com";
|
1090
|
+
var pwd = "pwd";
|
927
1091
|
|
1092
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1093
|
+
projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
|
1094
|
+
|
1095
|
+
chai.request(server)
|
1096
|
+
.post('/' + savedProject._id + '/requests/')
|
1097
|
+
.auth(email, pwd)
|
1098
|
+
.set('content-type', 'application/json')
|
1099
|
+
.send({ "first_text": "first_text" })
|
1100
|
+
.end(function (err, res) {
|
1101
|
+
|
1102
|
+
if (err) { console.log("err: ", err) };
|
1103
|
+
if (log) { console.log("res.body: ", res.body) };
|
1104
|
+
|
1105
|
+
res.should.have.status(200);
|
1106
|
+
res.body.should.be.a('object');
|
1107
|
+
res.body.should.have.property('request_id').not.eql(null);
|
1108
|
+
|
1109
|
+
let request_id = res.body.request_id;
|
1110
|
+
|
1111
|
+
let tags = [
|
1112
|
+
{ tag: "tag1", color: "#43B1F2" },
|
1113
|
+
{ tag: "tag2", color: "#43B1F2" }
|
1114
|
+
]
|
1115
|
+
|
1116
|
+
// First Step: add 2 tags on a conversation no tagged at all
|
1117
|
+
chai.request(server)
|
1118
|
+
.put('/' + savedProject._id + '/requests/' + request_id + '/tag' )
|
1119
|
+
.auth(email, pwd)
|
1120
|
+
.send(tags)
|
1121
|
+
.end((err, res) => {
|
1122
|
+
|
1123
|
+
if (err) { console.log("err: ", err) };
|
1124
|
+
if (log) { console.log("res.body: ", res.body) };
|
1125
|
+
|
1126
|
+
res.should.have.status(200);
|
1127
|
+
res.body.should.be.a('object');
|
1128
|
+
expect(res.body.tags).to.have.length(2);
|
1129
|
+
expect(res.body.tags[0].tag).to.equal('tag1');
|
1130
|
+
expect(res.body.tags[1].tag).to.equal('tag2');
|
1131
|
+
|
1132
|
+
let tags2 = [
|
1133
|
+
{ tag: "tag2", color: "#43B1F2"},
|
1134
|
+
{ tag: "tag3", color: "#43B1F2"}
|
1135
|
+
]
|
1136
|
+
|
1137
|
+
// Second Step: add more 2 tags of which one already existant in the conversation
|
1138
|
+
chai.request(server)
|
1139
|
+
.put('/' + savedProject._id + '/requests/' + request_id + '/tag')
|
1140
|
+
.auth(email, pwd)
|
1141
|
+
.send(tags2)
|
1142
|
+
.end((err, res) => {
|
1143
|
+
|
1144
|
+
if (err) { console.log("err: ", err) };
|
1145
|
+
if (log) { console.log("res.body: ", res.body) };
|
1146
|
+
|
1147
|
+
res.should.have.status(200);
|
1148
|
+
res.body.should.be.a('object');
|
1149
|
+
expect(res.body.tags).to.have.length(3);
|
1150
|
+
expect(res.body.tags[0].tag).to.equal('tag1');
|
1151
|
+
expect(res.body.tags[1].tag).to.equal('tag2');
|
1152
|
+
expect(res.body.tags[2].tag).to.equal('tag3');
|
1153
|
+
|
1154
|
+
let tag_to_delete = res.body.tags[2];
|
1155
|
+
|
1156
|
+
chai.request(server)
|
1157
|
+
.delete('/' + savedProject._id + '/requests/' + request_id + '/tag/' + tag_to_delete._id)
|
1158
|
+
.auth(email, pwd)
|
1159
|
+
.end((err, res) => {
|
1160
|
+
|
1161
|
+
if (err) { console.log("err: ", err) };
|
1162
|
+
if (log) { console.log("res.body: ", res.body) };
|
1163
|
+
|
1164
|
+
res.should.have.status(200);
|
1165
|
+
res.body.should.be.a('object');
|
1166
|
+
|
1167
|
+
expect(res.body.tags).to.have.length(2);
|
1168
|
+
expect(res.body.tags[0].tag).to.equal('tag1');
|
1169
|
+
expect(res.body.tags[1].tag).to.equal('tag2');
|
1170
|
+
|
1171
|
+
done();
|
1172
|
+
})
|
1173
|
+
})
|
1174
|
+
|
1175
|
+
})
|
1176
|
+
|
1177
|
+
});
|
1178
|
+
});
|
1179
|
+
});
|
1180
|
+
}).timeout(4000);
|
1181
|
+
|
1182
|
+
it('remove-tag-from-unexistent-conversation', function (done) {
|
1183
|
+
|
1184
|
+
var email = "test-request-create-" + Date.now() + "@email.com";
|
1185
|
+
var pwd = "pwd";
|
1186
|
+
|
1187
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1188
|
+
projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
|
1189
|
+
|
1190
|
+
chai.request(server)
|
1191
|
+
.post('/' + savedProject._id + '/requests/')
|
1192
|
+
.auth(email, pwd)
|
1193
|
+
.set('content-type', 'application/json')
|
1194
|
+
.send({ "first_text": "first_text" })
|
1195
|
+
.end(function (err, res) {
|
1196
|
+
|
1197
|
+
if (err) { console.log("err: ", err) };
|
1198
|
+
if (log) { console.log("res.body: ", res.body) };
|
1199
|
+
|
1200
|
+
res.should.have.status(200);
|
1201
|
+
res.body.should.be.a('object');
|
1202
|
+
res.body.should.have.property('request_id').not.eql(null);
|
1203
|
+
|
1204
|
+
let request_id = res.body.request_id;
|
1205
|
+
|
1206
|
+
let tags = [
|
1207
|
+
{ tag: "tag1", color: "#43B1F2" },
|
1208
|
+
{ tag: "tag2", color: "#43B1F2" }
|
1209
|
+
]
|
1210
|
+
|
1211
|
+
// First Step: add 2 tags on a conversation no tagged at all
|
1212
|
+
chai.request(server)
|
1213
|
+
.put('/' + savedProject._id + '/requests/' + request_id + '/tag' )
|
1214
|
+
.auth(email, pwd)
|
1215
|
+
.send(tags)
|
1216
|
+
.end((err, res) => {
|
1217
|
+
|
1218
|
+
if (err) { console.log("err: ", err) };
|
1219
|
+
if (log) { console.log("res.body: ", res.body) };
|
1220
|
+
|
1221
|
+
res.should.have.status(200);
|
1222
|
+
res.body.should.be.a('object');
|
1223
|
+
expect(res.body.tags).to.have.length(2);
|
1224
|
+
expect(res.body.tags[0].tag).to.equal('tag1');
|
1225
|
+
expect(res.body.tags[1].tag).to.equal('tag2');
|
1226
|
+
|
1227
|
+
let tag_to_delete = res.body.tags[1];
|
1228
|
+
let fake_request_id = "support-group-6752d23518dbe16860ff2cda-b1f2ecb1c617492fbbc33105b475axxx"
|
1229
|
+
|
1230
|
+
chai.request(server)
|
1231
|
+
.delete('/' + savedProject._id + '/requests/' + fake_request_id + '/tag/' + tag_to_delete._id)
|
1232
|
+
.auth(email, pwd)
|
1233
|
+
.end((err, res) => {
|
1234
|
+
|
1235
|
+
if (err) { console.log("err: ", err) };
|
1236
|
+
if (log) { console.log("res.body: ", res.body) };
|
1237
|
+
|
1238
|
+
res.should.have.status(404);
|
1239
|
+
res.body.should.be.a('object');
|
1240
|
+
|
1241
|
+
expect(res.body.success).to.equal(false);
|
1242
|
+
expect(res.body.error).to.equal("Request not found with id " + fake_request_id)
|
1243
|
+
|
1244
|
+
done();
|
1245
|
+
})
|
1246
|
+
|
1247
|
+
|
1248
|
+
})
|
1249
|
+
|
1250
|
+
});
|
1251
|
+
});
|
1252
|
+
});
|
1253
|
+
}).timeout(4000);
|
1254
|
+
|
1255
|
+
|
1256
|
+
describe('/assign', () => {
|
1257
|
+
|
1258
|
+
// mocha test/requestRoute.js --grep 'createAndReassign'
|
928
1259
|
it('createAndReassign', function (done) {
|
929
1260
|
// this.timeout(10000);
|
930
1261
|
|
@@ -1005,9 +1336,7 @@ describe('RequestRoute', () => {
|
|
1005
1336
|
});
|
1006
1337
|
|
1007
1338
|
|
1008
|
-
|
1009
1339
|
// mocha test/requestRoute.js --grep 'createAndReassignAndNoPopulate'
|
1010
|
-
|
1011
1340
|
it('createAndReassignAndNoPopulate', function (done) {
|
1012
1341
|
// this.timeout(10000);
|
1013
1342
|
|
@@ -1087,9 +1416,7 @@ describe('RequestRoute', () => {
|
|
1087
1416
|
});
|
1088
1417
|
|
1089
1418
|
|
1090
|
-
|
1091
1419
|
// mocha test/requestRoute.js --grep 'createAndAssign2'
|
1092
|
-
|
1093
1420
|
it('createAndAssign2', function (done) {
|
1094
1421
|
// this.timeout(10000);
|
1095
1422
|
|
@@ -1169,7 +1496,6 @@ describe('RequestRoute', () => {
|
|
1169
1496
|
});
|
1170
1497
|
|
1171
1498
|
|
1172
|
-
|
1173
1499
|
// mocha test/requestRoute.js --grep 'removeParticipant'
|
1174
1500
|
it('removeParticipant', function (done) {
|
1175
1501
|
// this.timeout(10000);
|
@@ -1245,109 +1571,6 @@ describe('RequestRoute', () => {
|
|
1245
1571
|
});
|
1246
1572
|
});
|
1247
1573
|
|
1248
|
-
it('exludeDraftConversations', (done) => {
|
1249
|
-
|
1250
|
-
var email = "test-signup-" + Date.now() + "@email.com";
|
1251
|
-
var pwd = "pwd";
|
1252
|
-
|
1253
|
-
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1254
|
-
projectService.createAndReturnProjectAndProjectUser("test-draft-conversation", savedUser._id).then((savedProjectAndPU) => {
|
1255
|
-
let savedProject = savedProjectAndPU.project;
|
1256
|
-
let savedPU = savedProjectAndPU.project_user;
|
1257
|
-
leadService.createIfNotExists("Lead Fullname", "email@test.com", savedProject._id).then((createdLead) => {
|
1258
|
-
let now = Date.now();
|
1259
|
-
let request = {
|
1260
|
-
request_id: "request_id-exludeDraftConversations-" + now,
|
1261
|
-
project_user_id: savedPU._id,
|
1262
|
-
lead_id: createdLead._id,
|
1263
|
-
id_project: savedProject._id,
|
1264
|
-
first_text: "first_text",
|
1265
|
-
lead: createdLead,
|
1266
|
-
requester: savedPU,
|
1267
|
-
attributes: { sourcePage: "https://widget-pre.tiledesk.com/v2/index.html?tiledesk_projectid=5ce3d1ceb25ad30017279999&td_draft=true" }
|
1268
|
-
}
|
1269
|
-
|
1270
|
-
requestService.create(request).then(async (savedRequest) => {
|
1271
|
-
|
1272
|
-
// Case 1 - request with source page that contains td_draft
|
1273
|
-
expect(savedRequest.draft).to.equal(true);
|
1274
|
-
|
1275
|
-
// Case 2 - request without source page that contains td_draft
|
1276
|
-
//expect(savedRequest.draft).to.be.undefined;
|
1277
|
-
|
1278
|
-
// get all requests -> should be 0
|
1279
|
-
|
1280
|
-
chai.request(server)
|
1281
|
-
.get('/' + savedProject._id + '/requests?draft=false')
|
1282
|
-
.auth(email, pwd)
|
1283
|
-
.end((err, res) => {
|
1284
|
-
|
1285
|
-
if (err) { console.error("err: ", err ) };
|
1286
|
-
if (log) { console.log("res.body: ", res.body) }
|
1287
|
-
|
1288
|
-
res.should.have.status(200);
|
1289
|
-
res.body.should.be.a('object');
|
1290
|
-
res.body.requests.should.be.a('array');
|
1291
|
-
|
1292
|
-
// Case 1 - request with source page that contains td_draft
|
1293
|
-
expect(res.body.requests.length).to.equal(0);
|
1294
|
-
|
1295
|
-
// Case 2 - request without source page that contains td_draft
|
1296
|
-
//expect(res.body.requests.length).to.equal(1);
|
1297
|
-
|
1298
|
-
done();
|
1299
|
-
})
|
1300
|
-
|
1301
|
-
|
1302
|
-
}).catch((err) => {
|
1303
|
-
console.error("error creating request: ", err)
|
1304
|
-
})
|
1305
|
-
})
|
1306
|
-
|
1307
|
-
})
|
1308
|
-
})
|
1309
|
-
|
1310
|
-
})
|
1311
|
-
|
1312
|
-
it('countConversations', function (done) {
|
1313
|
-
// this.timeout(10000);
|
1314
|
-
|
1315
|
-
var email = "test-request-create-" + Date.now() + "@email.com";
|
1316
|
-
var pwd = "pwd";
|
1317
|
-
|
1318
|
-
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1319
|
-
projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
|
1320
|
-
|
1321
|
-
chai.request(server)
|
1322
|
-
.post('/' + savedProject._id + '/requests/')
|
1323
|
-
.auth(email, pwd)
|
1324
|
-
.set('content-type', 'application/json')
|
1325
|
-
.send({ "first_text": "first_text" })
|
1326
|
-
.end(function (err, res) {
|
1327
|
-
|
1328
|
-
if (err) { console.log("err: ", err) };
|
1329
|
-
if (log) { console.log("res.body: ", res.body) };
|
1330
|
-
|
1331
|
-
res.should.have.status(200);
|
1332
|
-
res.body.should.be.a('object');
|
1333
|
-
|
1334
|
-
chai.request(server)
|
1335
|
-
.get('/' + savedProject._id + '/requests/count?conversation_quota=true')
|
1336
|
-
.auth(email, pwd)
|
1337
|
-
.end((err, res) => {
|
1338
|
-
|
1339
|
-
if (err) { console.log("err: ", err) };
|
1340
|
-
if (log) { console.log("res.body: ", res.body) };
|
1341
|
-
|
1342
|
-
res.should.have.status(200);
|
1343
|
-
|
1344
|
-
done();
|
1345
|
-
})
|
1346
|
-
|
1347
|
-
});
|
1348
|
-
});
|
1349
|
-
});
|
1350
|
-
});
|
1351
1574
|
|
1352
1575
|
// it('assign', (done) => {
|
1353
1576
|
|
@@ -1389,7 +1612,6 @@ describe('RequestRoute', () => {
|
|
1389
1612
|
// });
|
1390
1613
|
// }).timeout(20000);
|
1391
1614
|
|
1392
|
-
|
1393
1615
|
/*
|
1394
1616
|
it('requestParameterFromChatbot', function (done) {
|
1395
1617
|
// this.timeout(10000);
|
@@ -1433,8 +1655,6 @@ describe('RequestRoute', () => {
|
|
1433
1655
|
|
1434
1656
|
*/
|
1435
1657
|
|
1436
|
-
|
1437
|
-
|
1438
1658
|
});
|
1439
1659
|
|
1440
1660
|
});
|