@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.
@@ -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('config.secret:'+ config.secret);
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, config.secret, function (err, decoded) {
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.agents":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
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.agents":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
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