@tiledesk/tiledesk-server 2.1.4-0.3 → 2.1.4-0.31
Sign up to get free protection for your applications and to get access to all the features.
- package/.circleci/config.yml +44 -0
- package/.github/workflows/docker-community-push-latest.yml +22 -0
- package/.github/workflows/{docker-image-push.yml → docker-image-en-tag-push.yml} +1 -1
- package/.github/workflows/docker-image-tag-community-tag-push.yml +21 -0
- package/.github/workflows/{docker-push-latest.yml → docker-push-en-push-latest.yml} +1 -1
- package/CHANGELOG.md +3 -0
- package/Dockerfile +1 -1
- package/Dockerfile-en +1 -1
- package/app.js +9 -1
- package/channels/chat21/chat21Handler.js +48 -5
- package/channels/chat21/package-lock.json +3013 -0
- package/models/faq_kb.js +5 -0
- package/models/message.js +10 -4
- package/models/messageConstants.js +6 -0
- package/package.json +4 -4
- package/pubmodules/emailNotification/requestNotification.js +96 -31
- package/pubmodules/pubModulesManager.js +66 -13
- package/pubmodules/rules/conciergeBot.js +56 -49
- package/routes/auth.js +4 -3
- package/routes/campaigns.js +117 -25
- package/routes/faq_kb.js +9 -2
- package/routes/messagesRoot.js +73 -16
- package/routes/project_user.js +36 -1
- package/routes/request.js +85 -37
- package/routes/requestUtilRoot.js +30 -0
- package/services/departmentService.js +9 -5
- package/services/emailService.js +41 -7
- package/services/faqBotHandler.js +8 -1
- package/services/messageService.js +57 -9
- package/services/modulesManager.js +86 -23
- package/services/requestService.js +8 -4
- package/test/messageRootRoute.js +188 -0
- package/websocket/webSocketServer.js +5 -4
@@ -0,0 +1,188 @@
|
|
1
|
+
//During the test the env variable is set to test
|
2
|
+
process.env.NODE_ENV = 'test';
|
3
|
+
|
4
|
+
var User = require('../models/user');
|
5
|
+
var projectService = require('../services/projectService');
|
6
|
+
var requestService = require('../services/requestService');
|
7
|
+
var userService = require('../services/userService');
|
8
|
+
var leadService = require('../services/leadService');
|
9
|
+
var messageService = require('../services/messageService');
|
10
|
+
var Project_user = require("../models/project_user");
|
11
|
+
var roleConstants = require('../models/roleConstants');
|
12
|
+
const uuidv4 = require('uuid/v4');
|
13
|
+
|
14
|
+
//Require the dev-dependencies
|
15
|
+
let chai = require('chai');
|
16
|
+
let chaiHttp = require('chai-http');
|
17
|
+
let server = require('../app');
|
18
|
+
let should = chai.should();
|
19
|
+
var winston = require('../config/winston');
|
20
|
+
var jwt = require('jsonwebtoken');
|
21
|
+
// chai.config.includeStack = true;
|
22
|
+
|
23
|
+
var expect = chai.expect;
|
24
|
+
var assert = chai.assert;
|
25
|
+
|
26
|
+
chai.use(chaiHttp);
|
27
|
+
|
28
|
+
describe('MessageRoute', () => {
|
29
|
+
|
30
|
+
|
31
|
+
// mocha test/messageRootRoute.js --grep 'createSimple'
|
32
|
+
|
33
|
+
it('createSimple', function (done) {
|
34
|
+
// this.timeout(10000);
|
35
|
+
|
36
|
+
var email = "test-message-create-" + Date.now() + "@email.com";
|
37
|
+
var pwd = "pwd";
|
38
|
+
|
39
|
+
userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
40
|
+
projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
|
41
|
+
|
42
|
+
var savedProject = savedProjectAndPU.project;
|
43
|
+
|
44
|
+
chai.request(server)
|
45
|
+
.post('/'+ savedProject._id + '/messages')
|
46
|
+
.auth(email, pwd)
|
47
|
+
.set('content-type', 'application/json')
|
48
|
+
.send({"recipient":"5ddd30bff0195f0017f72c6d", "recipientFullname": "Dest", "text":"text"})
|
49
|
+
.end(function(err, res) {
|
50
|
+
//console.log("res", res);
|
51
|
+
console.log("res.body", res.body);
|
52
|
+
res.should.have.status(200);
|
53
|
+
res.body.should.be.a('object');
|
54
|
+
|
55
|
+
expect(res.body.sender).to.equal(savedUser._id.toString());
|
56
|
+
expect(res.body.senderFullname).to.equal("Test Firstname Test lastname");
|
57
|
+
expect(res.body.recipient).to.equal("5ddd30bff0195f0017f72c6d");
|
58
|
+
expect(res.body.type).to.equal("text");
|
59
|
+
expect(res.body.text).to.equal("text");
|
60
|
+
expect(res.body.id_project).to.equal(savedProject._id.toString());
|
61
|
+
expect(res.body.createdBy).to.equal(savedUser._id.toString());
|
62
|
+
expect(res.body.status).to.equal(0);
|
63
|
+
expect(res.body.request).to.equal(undefined);
|
64
|
+
expect(res.body.channel_type).to.equal("direct");
|
65
|
+
expect(res.body.channel.name).to.equal("chat21");
|
66
|
+
|
67
|
+
|
68
|
+
done();
|
69
|
+
});
|
70
|
+
});
|
71
|
+
});
|
72
|
+
});
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
// mocha test/messageRootRoute.js --grep 'createValidationNoRecipient'
|
79
|
+
it('createValidationNoRecipient', function (done) {
|
80
|
+
// this.timeout(10000);
|
81
|
+
|
82
|
+
var email = "test-message-create-" + Date.now() + "@email.com";
|
83
|
+
var pwd = "pwd";
|
84
|
+
|
85
|
+
userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
86
|
+
projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
|
87
|
+
|
88
|
+
var savedProject = savedProjectAndPU.project;
|
89
|
+
|
90
|
+
chai.request(server)
|
91
|
+
.post('/'+ savedProject._id + '/messages')
|
92
|
+
.auth(email, pwd)
|
93
|
+
.set('content-type', 'application/json')
|
94
|
+
.send({"text":"text"})
|
95
|
+
.end(function(err, res) {
|
96
|
+
//console.log("res", res);
|
97
|
+
console.log("res.body", res.body);
|
98
|
+
res.should.have.status(422);
|
99
|
+
res.body.should.be.a('object');
|
100
|
+
|
101
|
+
done();
|
102
|
+
});
|
103
|
+
});
|
104
|
+
});
|
105
|
+
});
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
// mocha test/messageRootRoute.js --grep 'createValidationNoText'
|
111
|
+
it('createValidationNoText', function (done) {
|
112
|
+
// this.timeout(10000);
|
113
|
+
|
114
|
+
var email = "test-message-create-" + Date.now() + "@email.com";
|
115
|
+
var pwd = "pwd";
|
116
|
+
|
117
|
+
userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
118
|
+
projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
|
119
|
+
|
120
|
+
var savedProject = savedProjectAndPU.project;
|
121
|
+
|
122
|
+
chai.request(server)
|
123
|
+
.post('/'+ savedProject._id + '/messages')
|
124
|
+
.auth(email, pwd)
|
125
|
+
.set('content-type', 'application/json')
|
126
|
+
.send({"recipient":"5ddd30bff0195f0017f72c6d", "recipientFullname": "Dest"})
|
127
|
+
.end(function(err, res) {
|
128
|
+
//console.log("res", res);
|
129
|
+
console.log("res.body", res.body);
|
130
|
+
res.should.have.status(422);
|
131
|
+
res.body.should.be.a('object');
|
132
|
+
|
133
|
+
done();
|
134
|
+
});
|
135
|
+
});
|
136
|
+
});
|
137
|
+
});
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
// mocha test/messageRootRoute.js --grep 'createWithSenderFullName'
|
143
|
+
|
144
|
+
it('createWithSenderFullName', function (done) {
|
145
|
+
// this.timeout(10000);
|
146
|
+
|
147
|
+
var email = "test-message-create-" + Date.now() + "@email.com";
|
148
|
+
var pwd = "pwd";
|
149
|
+
|
150
|
+
userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
151
|
+
projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
|
152
|
+
|
153
|
+
var savedProject = savedProjectAndPU.project;
|
154
|
+
|
155
|
+
chai.request(server)
|
156
|
+
.post('/'+ savedProject._id + '/messages')
|
157
|
+
.auth(email, pwd)
|
158
|
+
.set('content-type', 'application/json')
|
159
|
+
.send({"senderFullname":"Pippo","recipient":"5ddd30bff0195f0017f72c6d", "recipientFullname": "Dest", "text":"text"})
|
160
|
+
.end(function(err, res) {
|
161
|
+
//console.log("res", res);
|
162
|
+
console.log("res.body", res.body);
|
163
|
+
res.should.have.status(200);
|
164
|
+
res.body.should.be.a('object');
|
165
|
+
|
166
|
+
expect(res.body.sender).to.equal(savedUser._id.toString());
|
167
|
+
expect(res.body.senderFullname).to.equal("Pippo");
|
168
|
+
expect(res.body.recipient).to.equal("5ddd30bff0195f0017f72c6d");
|
169
|
+
expect(res.body.type).to.equal("text");
|
170
|
+
expect(res.body.text).to.equal("text");
|
171
|
+
expect(res.body.id_project).to.equal(savedProject._id.toString());
|
172
|
+
expect(res.body.createdBy).to.equal(savedUser._id.toString());
|
173
|
+
expect(res.body.status).to.equal(0);
|
174
|
+
expect(res.body.request).to.equal(undefined);
|
175
|
+
expect(res.body.channel_type).to.equal("direct");
|
176
|
+
expect(res.body.channel.name).to.equal("chat21");
|
177
|
+
|
178
|
+
|
179
|
+
done();
|
180
|
+
});
|
181
|
+
});
|
182
|
+
});
|
183
|
+
});
|
184
|
+
|
185
|
+
|
186
|
+
});
|
187
|
+
|
188
|
+
|
@@ -22,6 +22,7 @@ var cacheUtil = require('../utils/cacheUtil');
|
|
22
22
|
var mongoose = require('mongoose');
|
23
23
|
const requestConstants = require("../models/requestConstants");
|
24
24
|
var RoleConstants = require('../models/roleConstants');
|
25
|
+
let configSecret = process.env.GLOBAL_SECRET || config.secret;
|
25
26
|
|
26
27
|
|
27
28
|
|
@@ -70,14 +71,14 @@ class WebSocketServer {
|
|
70
71
|
|
71
72
|
var token = queryParameter.token;
|
72
73
|
winston.debug('token:'+ token);
|
73
|
-
winston.debug('
|
74
|
+
winston.debug('configSecret:'+ configSecret);
|
74
75
|
|
75
76
|
|
76
77
|
if (!token)
|
77
78
|
cb(false, 401, 'Unauthorized');
|
78
79
|
else {
|
79
80
|
token = token.replace('JWT ', '');
|
80
|
-
jwt.verify(token,
|
81
|
+
jwt.verify(token, configSecret, function (err, decoded) {
|
81
82
|
if (err) {
|
82
83
|
winston.error('WebSocket error verifing websocket jwt token ', err);
|
83
84
|
return cb(false, 401, 'Unauthorized');
|
@@ -622,7 +623,7 @@ class WebSocketServer {
|
|
622
623
|
|
623
624
|
// ATTENTO https://stackoverflow.com/questions/64059795/mongodb-get-error-message-mongoerror-path-collision-at-activity
|
624
625
|
try {
|
625
|
-
var snapshotAgents = await Request.findById(request.id).select({"snapshot
|
626
|
+
var snapshotAgents = await Request.findById(request.id).select({"snapshot":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
|
626
627
|
winston.debug('snapshotAgents',snapshotAgents);
|
627
628
|
// requestJSON.snapshot.agents = snapshotAgents;
|
628
629
|
|
@@ -666,7 +667,7 @@ class WebSocketServer {
|
|
666
667
|
|
667
668
|
// ATTENTO https://stackoverflow.com/questions/64059795/mongodb-get-error-message-mongoerror-path-collision-at-activity
|
668
669
|
try {
|
669
|
-
var snapshotAgents = await Request.findById(request.id).select({"snapshot
|
670
|
+
var snapshotAgents = await Request.findById(request.id).select({"snapshot":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
|
670
671
|
winston.debug('snapshotAgents',snapshotAgents);
|
671
672
|
// requestJSON.snapshot.agents = snapshotAgents;
|
672
673
|
|