@tiledesk/tiledesk-server 2.10.15 → 2.10.17
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +12 -0
- package/app.js +2 -1
- package/models/request.js +8 -0
- package/package.json +4 -3
- package/pubmodules/activities/test/activityRoute.js +6 -2
- package/pubmodules/events/test/eventRoute.js +7 -3
- package/pubmodules/pubModulesManager.js +24 -0
- package/pubmodules/voice-twilio/index.js +6 -0
- package/pubmodules/voice-twilio/listener.js +59 -0
- package/routes/campaigns.js +1 -1
- package/routes/files.js +6 -4
- package/routes/images.js +0 -2
- package/routes/kb.js +7 -1
- package/routes/users.js +2 -2
- package/services/fileGridFsService.js +12 -10
- package/services/requestService.js +2 -1
- package/test/app-test.js +36 -1
- package/test/authentication.js +662 -796
- package/test/authenticationJwt.js +213 -315
- package/test/authorization.js +53 -72
- package/test/campaignsRoute.js +42 -47
- package/test/cannedRoute.js +30 -16
- package/test/departmentService.js +222 -274
- package/test/example.json +31 -1
- package/test/faqRoute.js +713 -622
- package/test/faqService.js +124 -159
- package/test/faqkbRoute.js +128 -100
- package/test/fileRoute.js +50 -46
- package/test/imageRoute.js +263 -254
- package/test/jwtRoute.js +128 -153
- package/test/kbRoute.js +40 -17
- package/test/kbsettingsRoute.js +78 -54
- package/test/keysRoute.js +6 -7
- package/test/labelRoute.js +591 -696
- package/test/labelService.js +40 -47
- package/test/leadService.js +100 -115
- package/test/logsRoute.js +13 -7
- package/test/messageRootRoute.js +112 -102
- package/test/messageRoute.js +1171 -1419
- package/test/messageService.js +41 -43
- package/test/openaiRoute.js +5 -1
- package/test/projectRoute.js +23 -4
- package/test/projectService.js +3 -1
- package/test/quoteManager.js +36 -13
- package/test/requestRoute.js +103 -72
- package/test/requestService.js +51 -51
- package/test/userRoute.js +37 -8
- package/test/userService.js +34 -31
- package/utils/promiseUtil.js +1 -1
package/test/labelService.js
CHANGED
@@ -16,112 +16,105 @@ require('../services/mongoose-cache-fn')(mongoose);
|
|
16
16
|
|
17
17
|
describe('labelService', function () {
|
18
18
|
|
19
|
-
|
20
|
-
|
21
19
|
|
22
20
|
it('getWithoutClonedLabel', function (done) {
|
23
21
|
var userid = "5badfe5d553d1844ad654072";
|
24
22
|
|
25
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
26
|
-
|
23
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
24
|
+
|
27
25
|
// get(id_project, language, key) {
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
labelService.get(savedProject._id, "EN", "LABEL_PLACEHOLDER").then(function (label) {
|
27
|
+
|
28
|
+
expect(label).to.equal("type your message..");
|
31
29
|
|
32
30
|
done();
|
33
|
-
|
31
|
+
}).catch(function (err) {
|
34
32
|
winston.error("test reject", err);
|
35
|
-
assert.isNotOk(err,'Promise error');
|
33
|
+
assert.isNotOk(err, 'Promise error');
|
36
34
|
done();
|
35
|
+
});
|
37
36
|
});
|
38
37
|
});
|
39
|
-
});
|
40
|
-
|
41
38
|
|
42
39
|
|
43
40
|
it('getITLanguageButNotPresentInProject', function (done) {
|
44
41
|
var userid = "5badfe5d553d1844ad654072";
|
45
42
|
|
46
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
47
|
-
|
43
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
44
|
+
|
48
45
|
// get(id_project, language, key) {
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
labelService.get(savedProject._id, "IT", "LABEL_PLACEHOLDER").then(function (label) {
|
47
|
+
|
48
|
+
expect(label).to.equal("type your message..");
|
52
49
|
|
53
50
|
done();
|
54
|
-
|
51
|
+
}).catch(function (err) {
|
55
52
|
winston.error("test reject", err);
|
56
|
-
assert.isNotOk(err,'Promise error');
|
53
|
+
assert.isNotOk(err, 'Promise error');
|
57
54
|
done();
|
55
|
+
});
|
58
56
|
});
|
59
57
|
});
|
60
|
-
});
|
61
58
|
|
62
59
|
|
63
60
|
it('getWrongLanguage', function (done) {
|
64
61
|
var userid = "5badfe5d553d1844ad654072";
|
65
62
|
|
66
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
67
|
-
|
63
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
64
|
+
|
68
65
|
// get(id_project, language, key) {
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
labelService.get(savedProject._id, "OO", "LABEL_PLACEHOLDER").then(function (label) {
|
67
|
+
|
68
|
+
expect(label).to.equal("type your message..");
|
72
69
|
|
73
70
|
done();
|
74
|
-
|
71
|
+
}).catch(function (err) {
|
75
72
|
winston.error("test reject", err);
|
76
|
-
assert.isNotOk(err,'Promise error');
|
73
|
+
assert.isNotOk(err, 'Promise error');
|
77
74
|
done();
|
75
|
+
});
|
78
76
|
});
|
79
77
|
});
|
80
|
-
});
|
81
|
-
|
82
|
-
|
83
78
|
|
84
79
|
|
85
80
|
it('getLanguage', function (done) {
|
86
81
|
var userid = "5badfe5d553d1844ad654072";
|
87
82
|
|
88
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
89
|
-
|
83
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
84
|
+
|
90
85
|
// getLanguage(id_project, language) {
|
91
|
-
|
92
|
-
|
93
|
-
|
86
|
+
labelService.getLanguage(savedProject._id, "EN").then(function (labels) {
|
87
|
+
|
88
|
+
expect(labels.data.LABEL_PLACEHOLDER).to.equal("type your message..");
|
94
89
|
|
95
90
|
done();
|
96
|
-
|
91
|
+
}).catch(function (err) {
|
97
92
|
winston.error("test reject", err);
|
98
|
-
assert.isNotOk(err,'Promise error');
|
93
|
+
assert.isNotOk(err, 'Promise error');
|
99
94
|
done();
|
95
|
+
});
|
100
96
|
});
|
101
97
|
});
|
102
|
-
});
|
103
|
-
|
104
|
-
|
105
98
|
|
106
99
|
|
107
100
|
it('getLanguageWrongLang', function (done) {
|
108
101
|
var userid = "5badfe5d553d1844ad654072";
|
109
102
|
|
110
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
111
|
-
|
103
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
104
|
+
|
112
105
|
// getLanguage(id_project, language) {
|
113
|
-
|
114
|
-
|
115
|
-
|
106
|
+
labelService.getLanguage(savedProject._id, "XX").then(function (labels) {
|
107
|
+
|
108
|
+
expect(labels.data.LABEL_PLACEHOLDER).to.equal("type your message..");
|
116
109
|
|
117
110
|
done();
|
118
|
-
|
111
|
+
}).catch(function (err) {
|
119
112
|
winston.error("test reject", err);
|
120
|
-
assert.isNotOk(err,'Promise error');
|
113
|
+
assert.isNotOk(err, 'Promise error');
|
121
114
|
done();
|
115
|
+
});
|
122
116
|
});
|
123
117
|
});
|
124
|
-
});
|
125
118
|
|
126
119
|
|
127
120
|
});
|
package/test/leadService.js
CHANGED
@@ -13,175 +13,160 @@ mongoose.connect(config.databasetest);
|
|
13
13
|
var leadService = require('../services/leadService');
|
14
14
|
var projectService = require("../services/projectService");
|
15
15
|
|
16
|
+
let log = false;
|
17
|
+
|
16
18
|
describe('LeadService()', function () {
|
17
19
|
|
18
20
|
var userid = "5badfe5d553d1844ad654072";
|
19
21
|
|
20
|
-
|
21
22
|
it('create', function (done) {
|
22
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
24
|
+
// create(fullname, email, id_project, createdBy)
|
25
|
+
var attr = { myprop: 123 };
|
26
|
+
leadService.create("fullname", "email@email.com", savedProject._id, userid, attr).then(function (savedLead) {
|
26
27
|
winston.debug("resolve", savedLead.toObject());
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
expect(savedLead.fullname).to.equal("fullname");
|
29
|
+
expect(savedLead.email).to.equal("email@email.com");
|
30
|
+
expect(savedLead.id_project).to.equal(savedProject._id.toString());
|
31
|
+
expect(savedLead.lead_id).to.not.equal(null);
|
32
|
+
expect(savedLead.attributes).to.equal(attr);
|
33
|
+
expect(savedLead.attributes.myprop).to.equal(123);
|
33
34
|
|
34
35
|
done();
|
35
|
-
|
36
|
+
}).catch(function (err) {
|
36
37
|
winston.error("test reject", err);
|
37
|
-
assert.isNotOk(err,'Promise error');
|
38
|
+
assert.isNotOk(err, 'Promise error');
|
38
39
|
done();
|
40
|
+
});
|
39
41
|
});
|
40
42
|
});
|
41
|
-
});
|
42
|
-
|
43
|
-
|
44
43
|
|
45
44
|
|
46
45
|
it('update', function (done) {
|
47
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
47
|
+
// create(fullname, email, id_project, createdBy)
|
48
|
+
var attr = { myprop: 123 };
|
49
|
+
leadService.create("fullname", "email@email.com", savedProject._id, userid, attr).then(function (savedLead) {
|
51
50
|
winston.debug("resolve", savedLead.toObject());
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
expect(savedLead.fullname).to.equal("fullname");
|
52
|
+
expect(savedLead.email).to.equal("email@email.com");
|
53
|
+
expect(savedLead.id_project).to.equal(savedProject._id.toString());
|
54
|
+
expect(savedLead.lead_id).to.not.equal(null);
|
55
|
+
expect(savedLead.attributes).to.equal(attr);
|
56
|
+
expect(savedLead.attributes.myprop).to.equal(123);
|
58
57
|
|
59
58
|
// updateWitId(lead_id, fullname, email, id_project) {
|
60
59
|
|
61
|
-
|
60
|
+
leadService.updateWitId(savedLead.lead_id, "fullname2", "email2@email2.com", savedProject._id).then(function (updatedLead) {
|
62
61
|
|
63
62
|
expect(updatedLead.fullname).to.equal("fullname2");
|
64
63
|
expect(updatedLead.email).to.equal("email2@email2.com");
|
65
64
|
expect(updatedLead.id_project).to.equal(savedProject._id.toString());
|
66
65
|
expect(updatedLead.lead_id).to.not.equal(savedLead.id);
|
67
66
|
|
68
|
-
|
69
|
-
}).catch(function(err) {
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
done();
|
68
|
+
}).catch(function (err) {
|
69
|
+
winston.error("test reject", err);
|
70
|
+
assert.isNotOk(err, 'Promise error');
|
71
|
+
done();
|
73
72
|
});
|
73
|
+
});
|
74
|
+
});
|
74
75
|
});
|
75
|
-
});
|
76
|
-
});
|
77
|
-
|
78
|
-
|
79
76
|
|
80
77
|
|
81
78
|
it('createWithoutEmail', function (done) {
|
82
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
83
|
-
|
84
|
-
|
79
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
80
|
+
// create(fullname, email, id_project, createdBy)
|
81
|
+
leadService.create("fullname", null, savedProject._id, userid).then(function (savedLead) {
|
85
82
|
winston.debug("resolve", savedLead.toObject());
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
83
|
+
expect(savedLead.fullname).to.equal("fullname");
|
84
|
+
expect(savedLead.email).to.equal(null);
|
85
|
+
expect(savedLead.id_project).to.equal(savedProject._id.toString());
|
86
|
+
expect(savedLead.lead_id).to.not.equal(null);
|
87
|
+
expect(savedLead.attributes).to.equal(undefined);
|
91
88
|
done();
|
92
|
-
|
89
|
+
}).catch(function (err) {
|
93
90
|
winston.error("test reject", err);
|
94
|
-
assert.isNotOk(err,'Promise error');
|
91
|
+
assert.isNotOk(err, 'Promise error');
|
95
92
|
done();
|
93
|
+
});
|
96
94
|
});
|
97
95
|
});
|
98
|
-
});
|
99
|
-
|
100
|
-
|
101
96
|
|
102
97
|
|
103
98
|
it('createIfNotExists-already-exists', function (done) {
|
104
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
99
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
100
|
+
// create(fullname, email, id_project, createdBy)
|
101
|
+
leadService.create("fullname", "email@email.com", savedProject._id, userid).then(function (savedLead) {
|
102
|
+
if (log) { console.log("savedLead", savedLead); }
|
103
|
+
leadService.createIfNotExists("fullname", "email@email.com", savedProject._id, userid).then(function (savedLeadIfNotExists) {
|
104
|
+
if (log) { console.log("savedLeadIfNotExists", savedLeadIfNotExists); }
|
105
|
+
expect(savedLead.fullname).to.equal("fullname");
|
106
|
+
expect(savedLead.email).to.equal("email@email.com");
|
107
|
+
expect(savedLead.id_project).to.equal(savedProject._id.toString());
|
108
|
+
expect(savedLeadIfNotExists._id.toString()).to.equal(savedLead._id.toString());
|
109
|
+
expect(savedLeadIfNotExists.lead_id).to.not.equal(null);
|
110
|
+
|
111
|
+
done();
|
112
|
+
}).catch(function (err) {
|
113
|
+
winston.error("test reject", err);
|
114
|
+
assert.isNotOk(err, 'Promise error');
|
115
|
+
done();
|
116
|
+
});
|
115
117
|
|
116
|
-
|
117
|
-
}).catch(function(err) {
|
118
|
-
winston.error("test reject", err);
|
119
|
-
assert.isNotOk(err,'Promise error');
|
120
|
-
done();
|
118
|
+
});
|
121
119
|
});
|
122
|
-
|
123
|
-
});
|
124
120
|
});
|
125
|
-
});
|
126
|
-
|
127
121
|
|
128
122
|
|
129
123
|
it('createIfNotExists-not-exists', function (done) {
|
130
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
expect(savedLeadIfNotExists.id_project).to.equal(savedProject._id.toString());
|
139
|
-
expect(savedLeadIfNotExists.lead_id).to.not.equal(null);
|
140
|
-
|
141
|
-
done();
|
142
|
-
}).catch(function(err) {
|
143
|
-
winston.error("test reject", err);
|
144
|
-
assert.isNotOk(err,'Promise error');
|
145
|
-
done();
|
146
|
-
});
|
147
|
-
|
148
|
-
|
149
|
-
});
|
150
|
-
});
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
it('createIfNotExistsWithId-already-exists', function (done) {
|
157
|
-
projectService.create("test1", userid).then(function(savedProject) {
|
158
|
-
// create(fullname, email, id_project, createdBy)
|
159
|
-
var lead_id = "lead_id_" + savedProject._id;
|
160
|
-
leadService.createWitId(lead_id, "fullname","email@email.com", savedProject._id, userid).then(function(savedLead) {
|
161
|
-
console.log("savedLead", savedLead);
|
162
|
-
leadService.createIfNotExistsWithLeadId(lead_id, "fullname", "email@email.com", savedProject._id, userid).then(function(savedLeadIfNotExists) {
|
163
|
-
console.log("savedLeadIfNotExists", savedLeadIfNotExists);
|
164
|
-
expect(savedLead.fullname).to.equal("fullname");
|
165
|
-
expect(savedLead.email).to.equal("email@email.com");
|
166
|
-
expect(savedLead.lead_id).to.equal(lead_id);
|
167
|
-
expect(savedLead.id_project).to.equal(savedProject._id.toString());
|
168
|
-
expect(savedLeadIfNotExists._id.toString()).to.equal(savedLead._id.toString());
|
169
|
-
expect(savedLeadIfNotExists.lead_id).to.equal(lead_id);
|
124
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
125
|
+
// create(fullname, email, id_project, createdBy)
|
126
|
+
leadService.createIfNotExists("fullname2", "email2@email.com", savedProject._id, userid).then(function (savedLeadIfNotExists) {
|
127
|
+
if (log) { console.log("savedLeadIfNotExists", savedLeadIfNotExists); }
|
128
|
+
expect(savedLeadIfNotExists.fullname).to.equal("fullname2");
|
129
|
+
expect(savedLeadIfNotExists.email).to.equal("email2@email.com");
|
130
|
+
expect(savedLeadIfNotExists.id_project).to.equal(savedProject._id.toString());
|
131
|
+
expect(savedLeadIfNotExists.lead_id).to.not.equal(null);
|
170
132
|
|
171
133
|
done();
|
172
|
-
|
134
|
+
}).catch(function (err) {
|
173
135
|
winston.error("test reject", err);
|
174
|
-
assert.isNotOk(err,'Promise error');
|
136
|
+
assert.isNotOk(err, 'Promise error');
|
175
137
|
done();
|
176
|
-
|
138
|
+
});
|
177
139
|
|
178
|
-
});
|
179
|
-
});
|
180
|
-
});
|
181
140
|
|
141
|
+
});
|
142
|
+
});
|
182
143
|
|
183
144
|
|
145
|
+
it('createIfNotExistsWithId-already-exists', function (done) {
|
146
|
+
projectService.create("test1", userid).then(function (savedProject) {
|
147
|
+
// create(fullname, email, id_project, createdBy)
|
148
|
+
var lead_id = "lead_id_" + savedProject._id;
|
149
|
+
leadService.createWitId(lead_id, "fullname", "email@email.com", savedProject._id, userid).then(function (savedLead) {
|
150
|
+
if (log) { console.log("savedLead", savedLead); }
|
151
|
+
leadService.createIfNotExistsWithLeadId(lead_id, "fullname", "email@email.com", savedProject._id, userid).then(function (savedLeadIfNotExists) {
|
152
|
+
if (log) { console.log("savedLeadIfNotExists", savedLeadIfNotExists); }
|
153
|
+
expect(savedLead.fullname).to.equal("fullname");
|
154
|
+
expect(savedLead.email).to.equal("email@email.com");
|
155
|
+
expect(savedLead.lead_id).to.equal(lead_id);
|
156
|
+
expect(savedLead.id_project).to.equal(savedProject._id.toString());
|
157
|
+
expect(savedLeadIfNotExists._id.toString()).to.equal(savedLead._id.toString());
|
158
|
+
expect(savedLeadIfNotExists.lead_id).to.equal(lead_id);
|
159
|
+
|
160
|
+
done();
|
161
|
+
}).catch(function (err) {
|
162
|
+
winston.error("test reject", err);
|
163
|
+
assert.isNotOk(err, 'Promise error');
|
164
|
+
done();
|
165
|
+
});
|
184
166
|
|
167
|
+
});
|
168
|
+
});
|
169
|
+
});
|
185
170
|
|
186
171
|
});
|
187
172
|
|
package/test/logsRoute.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
//During the test the env variable is set to test
|
2
2
|
process.env.NODE_ENV = 'test';
|
3
|
+
process.env.LOG_LEVEL = 'critical';
|
3
4
|
|
4
5
|
var User = require('../models/user');
|
5
6
|
var projectService = require('../services/projectService');
|
@@ -11,11 +12,15 @@ let chaiHttp = require('chai-http');
|
|
11
12
|
let server = require('../app');
|
12
13
|
let should = chai.should();
|
13
14
|
|
15
|
+
chai.use(chaiHttp);
|
16
|
+
|
14
17
|
// chai.config.includeStack = true;
|
15
18
|
|
16
19
|
var expect = chai.expect;
|
17
20
|
var assert = chai.assert;
|
18
21
|
|
22
|
+
let log = false;
|
23
|
+
|
19
24
|
let mock_log = {
|
20
25
|
json_message: {
|
21
26
|
messaging_product: "whatsapp",
|
@@ -46,7 +51,6 @@ let mock_log = {
|
|
46
51
|
status_code: 3,
|
47
52
|
error: null,
|
48
53
|
}
|
49
|
-
chai.use(chaiHttp);
|
50
54
|
|
51
55
|
describe('LogsRoute', () => {
|
52
56
|
|
@@ -62,16 +66,16 @@ describe('LogsRoute', () => {
|
|
62
66
|
|
63
67
|
mock_log.id_project = savedProject._id;
|
64
68
|
mock_log.transaction_id = "automation-request-" + savedProject._id;
|
65
|
-
console.log("mock_log.transaction_id: ", mock_log.transaction_id);
|
66
69
|
|
67
70
|
chai.request(server)
|
68
71
|
.post('/' + savedProject._id + '/logs/whatsapp')
|
69
72
|
.auth(email, pwd)
|
70
73
|
.send(mock_log)
|
71
74
|
.end((err, res) => {
|
72
|
-
|
73
|
-
|
74
|
-
console.log("
|
75
|
+
|
76
|
+
if (err) { console.error("err: ", err); }
|
77
|
+
if (log) { console.log("res.body: ", res.body); }
|
78
|
+
|
75
79
|
res.should.have.status(200);
|
76
80
|
res.body.should.be.a('object');
|
77
81
|
|
@@ -79,8 +83,10 @@ describe('LogsRoute', () => {
|
|
79
83
|
.get('/' + savedProject._id + '/logs/whatsapp/' + mock_log.transaction_id)
|
80
84
|
.auth(email, pwd)
|
81
85
|
.end((err, res) => {
|
82
|
-
|
83
|
-
console.
|
86
|
+
|
87
|
+
if (err) { console.error("err: ", err); }
|
88
|
+
if (log) { console.log("res.body: ", res.body); }
|
89
|
+
|
84
90
|
res.should.have.status(200);
|
85
91
|
|
86
92
|
done();
|