@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/app.js +2 -1
  3. package/models/request.js +8 -0
  4. package/package.json +4 -3
  5. package/pubmodules/activities/test/activityRoute.js +6 -2
  6. package/pubmodules/events/test/eventRoute.js +7 -3
  7. package/pubmodules/pubModulesManager.js +24 -0
  8. package/pubmodules/voice-twilio/index.js +6 -0
  9. package/pubmodules/voice-twilio/listener.js +59 -0
  10. package/routes/campaigns.js +1 -1
  11. package/routes/files.js +6 -4
  12. package/routes/images.js +0 -2
  13. package/routes/kb.js +7 -1
  14. package/routes/users.js +2 -2
  15. package/services/fileGridFsService.js +12 -10
  16. package/services/requestService.js +2 -1
  17. package/test/app-test.js +36 -1
  18. package/test/authentication.js +662 -796
  19. package/test/authenticationJwt.js +213 -315
  20. package/test/authorization.js +53 -72
  21. package/test/campaignsRoute.js +42 -47
  22. package/test/cannedRoute.js +30 -16
  23. package/test/departmentService.js +222 -274
  24. package/test/example.json +31 -1
  25. package/test/faqRoute.js +713 -622
  26. package/test/faqService.js +124 -159
  27. package/test/faqkbRoute.js +128 -100
  28. package/test/fileRoute.js +50 -46
  29. package/test/imageRoute.js +263 -254
  30. package/test/jwtRoute.js +128 -153
  31. package/test/kbRoute.js +40 -17
  32. package/test/kbsettingsRoute.js +78 -54
  33. package/test/keysRoute.js +6 -7
  34. package/test/labelRoute.js +591 -696
  35. package/test/labelService.js +40 -47
  36. package/test/leadService.js +100 -115
  37. package/test/logsRoute.js +13 -7
  38. package/test/messageRootRoute.js +112 -102
  39. package/test/messageRoute.js +1171 -1419
  40. package/test/messageService.js +41 -43
  41. package/test/openaiRoute.js +5 -1
  42. package/test/projectRoute.js +23 -4
  43. package/test/projectService.js +3 -1
  44. package/test/quoteManager.js +36 -13
  45. package/test/requestRoute.js +103 -72
  46. package/test/requestService.js +51 -51
  47. package/test/userRoute.js +37 -8
  48. package/test/userService.js +34 -31
  49. package/utils/promiseUtil.js +1 -1
@@ -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');
@@ -19,6 +20,7 @@ let should = chai.should();
19
20
  var winston = require('../config/winston');
20
21
  var jwt = require('jsonwebtoken');
21
22
  // chai.config.includeStack = true;
23
+ let log = false;
22
24
 
23
25
  var expect = chai.expect;
24
26
  var assert = chai.assert;
@@ -27,1683 +29,1433 @@ chai.use(chaiHttp);
27
29
 
28
30
  describe('MessageRoute', () => {
29
31
 
30
-
31
- // mocha test/messageRoute.js --grep 'createSimple'
32
-
32
+ // mocha test/messageRoute.js --grep 'createSimple'
33
33
  it('createSimple', function (done) {
34
- // this.timeout(10000);
35
34
 
36
35
  var email = "test-message-create-" + Date.now() + "@email.com";
37
36
  var pwd = "pwd";
38
37
 
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 + '/requests/req123/messages')
46
- .auth(email, pwd)
47
- .set('content-type', 'application/json')
48
- .send({"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.sender).to.equal(savedProjectAndPU.project_user._id.toString());
57
- // expect(res.body.senderFullname).to.equal("senderFullname");
58
- expect(res.body.recipient).to.equal("req123");
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
-
64
- expect(res.body.request.request_id).to.equal("req123");
65
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
66
- // expect(res.body.request.requester_id).to.equal("sender");
67
- expect(res.body.request.first_text).to.equal("text");
68
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
69
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
70
-
71
- // expect(res.body.request.messages_count).to.equal(1);
72
-
73
- expect(res.body.request.status).to.equal(200);
74
- expect(res.body.request.snapshot.agents.length).to.equal(1);
75
- expect(res.body.request.participants.length).to.equal(1);
76
- expect(res.body.request.department).to.not.equal(null);
77
- expect(res.body.request.lead).to.not.equal(null);
78
-
79
- expect(res.body.channel_type).to.equal("group");
80
- expect(res.body.channel.name).to.equal("chat21");
81
- expect(res.body.request.channel.name).to.equal("chat21");
38
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
39
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
82
40
 
41
+ var savedProject = savedProjectAndPU.project;
83
42
 
84
- expect(res.body.request.location).to.equal(undefined);
85
-
86
-
87
- done();
88
- });
43
+ chai.request(server)
44
+ .post('/' + savedProject._id + '/requests/req123/messages')
45
+ .auth(email, pwd)
46
+ .set('content-type', 'application/json')
47
+ .send({ "text": "text" })
48
+ .end(function (err, res) {
49
+
50
+ if (err) { console.error("err", err); }
51
+ if (log) { console.log("res.body", res.body); }
52
+
53
+ res.should.have.status(200);
54
+ res.body.should.be.a('object');
55
+
56
+ expect(res.body.sender).to.equal(savedUser._id.toString());
57
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
58
+ // expect(res.body.senderFullname).to.equal("senderFullname");
59
+ expect(res.body.recipient).to.equal("req123");
60
+ expect(res.body.text).to.equal("text");
61
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
62
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
63
+ expect(res.body.status).to.equal(0);
64
+ expect(res.body.request.request_id).to.equal("req123");
65
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
66
+ // expect(res.body.request.requester_id).to.equal("sender");
67
+ expect(res.body.request.first_text).to.equal("text");
68
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
69
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
70
+ // expect(res.body.request.messages_count).to.equal(1);
71
+ expect(res.body.request.status).to.equal(200);
72
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
73
+ expect(res.body.request.participants.length).to.equal(1);
74
+ expect(res.body.request.department).to.not.equal(null);
75
+ expect(res.body.request.lead).to.not.equal(null);
76
+ expect(res.body.channel_type).to.equal("group");
77
+ expect(res.body.channel.name).to.equal("chat21");
78
+ expect(res.body.request.channel.name).to.equal("chat21");
79
+ expect(res.body.request.location).to.equal(undefined);
80
+
81
+ done();
82
+ });
83
+ });
89
84
  });
90
85
  });
91
- });
92
-
93
-
94
- // mocha test/messageRoute.js --grep 'createSimpleEmptyText'
95
86
 
87
+ // mocha test/messageRoute.js --grep 'createSimpleEmptyText'
96
88
  it('createSimpleEmptyText', function (done) {
97
- // this.timeout(10000);
98
89
 
99
90
  var email = "test-message-create-" + Date.now() + "@email.com";
100
91
  var pwd = "pwd";
101
92
 
102
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
103
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
104
-
105
- var savedProject = savedProjectAndPU.project;
106
-
107
- chai.request(server)
108
- .post('/'+ savedProject._id + '/requests/req123/messages')
109
- .auth(email, pwd)
110
- .set('content-type', 'application/json')
111
- .send({"text":""})
112
- .end(function(err, res) {
113
- //console.log("res", res);
114
- console.log("res.body", res.body);
115
- res.should.have.status(422);
116
-
117
- done();
118
- });
119
- });
120
- });
121
- }).timeout(20000);
122
-
93
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
94
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
123
95
 
96
+ var savedProject = savedProjectAndPU.project;
124
97
 
98
+ chai.request(server)
99
+ .post('/' + savedProject._id + '/requests/req123/messages')
100
+ .auth(email, pwd)
101
+ .set('content-type', 'application/json')
102
+ .send({ "text": "" })
103
+ .end(function (err, res) {
104
+
105
+ if (err) { console.error("err", err); }
106
+ if (log) { console.log("res.body", res.body); }
107
+
108
+ res.should.have.status(422);
125
109
 
110
+ done();
111
+ });
112
+ });
113
+ });
114
+ }).timeout(20000);
126
115
 
127
- // mocha test/messageRoute.js --grep 'createSimpleNoText'
116
+ // mocha test/messageRoute.js --grep 'createSimpleNoText'
117
+ it('createSimpleNoText', function (done) {
128
118
 
129
- it('createSimpleNoText', function (done) {
130
- // this.timeout(10000);
119
+ var email = "test-message-create-" + Date.now() + "@email.com";
120
+ var pwd = "pwd";
131
121
 
132
- var email = "test-message-create-" + Date.now() + "@email.com";
133
- var pwd = "pwd";
122
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
123
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
134
124
 
135
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
136
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
137
-
138
- var savedProject = savedProjectAndPU.project;
125
+ var savedProject = savedProjectAndPU.project;
139
126
 
140
127
  chai.request(server)
141
- .post('/'+ savedProject._id + '/requests/req123/messages')
128
+ .post('/' + savedProject._id + '/requests/req123/messages')
142
129
  .auth(email, pwd)
143
130
  .set('content-type', 'application/json')
144
131
  .send({})
145
- .end(function(err, res) {
146
- //console.log("res", res);
147
- console.log("res.body", res.body);
148
- res.should.have.status(422);
149
-
150
- done();
132
+ .end(function (err, res) {
133
+
134
+ if (err) { console.error("err", err); }
135
+ if (log) { console.log("res.body", res.body); }
136
+
137
+ res.should.have.status(422);
138
+
139
+ done();
151
140
  });
141
+ });
142
+ });
152
143
  });
153
- });
154
- });
155
-
156
-
157
-
158
144
 
159
- // mocha test/messageRoute.js --grep 'createSimpleWithAttributes'
145
+ // mocha test/messageRoute.js --grep 'createSimpleWithAttributes'
146
+ it('createSimpleWithAttributes', function (done) {
160
147
 
161
- it('createSimpleWithAttributes', function (done) {
162
- // this.timeout(10000);
148
+ var email = "test-message-create-" + Date.now() + "@email.com";
149
+ var pwd = "pwd";
163
150
 
164
- var email = "test-message-create-" + Date.now() + "@email.com";
165
- var pwd = "pwd";
151
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
152
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
166
153
 
167
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
168
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
169
-
170
- var savedProject = savedProjectAndPU.project;
154
+ var savedProject = savedProjectAndPU.project;
171
155
 
172
156
  chai.request(server)
173
- .post('/'+ savedProject._id + '/requests/req123-createSimpleWithAttributes/messages')
157
+ .post('/' + savedProject._id + '/requests/req123-createSimpleWithAttributes/messages')
174
158
  .auth(email, pwd)
175
159
  .set('content-type', 'application/json')
176
- .send({"text":"text","attributes": {"a":"b"}})
177
- .end(function(err, res) {
178
- //console.log("res", res);
179
- console.log("res.body", res.body);
180
- res.should.have.status(200);
181
- res.body.should.be.a('object');
182
-
183
- expect(res.body.sender).to.equal(savedUser._id.toString());
184
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
185
- // expect(res.body.senderFullname).to.equal("senderFullname");
186
- expect(res.body.recipient).to.equal("req123-createSimpleWithAttributes");
187
- expect(res.body.text).to.equal("text");
188
- expect(res.body.id_project).to.equal(savedProject._id.toString());
189
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
190
- expect(res.body.status).to.equal(0);
191
- expect(res.body.attributes.a).to.equal("b");
192
-
193
- expect(res.body.request.request_id).to.equal("req123-createSimpleWithAttributes");
194
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
195
- // expect(res.body.request.requester_id).to.equal("sender");
196
- expect(res.body.request.first_text).to.equal("text");
197
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
198
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
199
-
200
- // expect(res.body.request.messages_count).to.equal(1);
201
-
202
- expect(res.body.request.status).to.equal(200);
203
- expect(res.body.request.snapshot.agents.length).to.equal(1);
204
- expect(res.body.request.participants.length).to.equal(1);
205
- expect(res.body.request.department).to.not.equal(null);
206
- expect(res.body.request.lead).to.not.equal(null);
207
-
208
- expect(res.body.request.attributes.a).to.equal("b");
209
-
210
- expect(res.body.channel_type).to.equal("group");
211
- expect(res.body.channel.name).to.equal("chat21");
212
- expect(res.body.request.channel.name).to.equal("chat21");
213
-
214
-
215
- expect(res.body.request.location).to.equal(undefined);
216
-
217
-
218
- done();
160
+ .send({ "text": "text", "attributes": { "a": "b" } })
161
+ .end(function (err, res) {
162
+
163
+ if (err) { console.error("err", err); }
164
+ if (log) { console.log("res.body", res.body); }
165
+
166
+ res.should.have.status(200);
167
+ res.body.should.be.a('object');
168
+ expect(res.body.sender).to.equal(savedUser._id.toString());
169
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
170
+ // expect(res.body.senderFullname).to.equal("senderFullname");
171
+ expect(res.body.recipient).to.equal("req123-createSimpleWithAttributes");
172
+ expect(res.body.text).to.equal("text");
173
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
174
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
175
+ expect(res.body.status).to.equal(0);
176
+ expect(res.body.attributes.a).to.equal("b");
177
+ expect(res.body.request.request_id).to.equal("req123-createSimpleWithAttributes");
178
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
179
+ // expect(res.body.request.requester_id).to.equal("sender");
180
+ expect(res.body.request.first_text).to.equal("text");
181
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
182
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
183
+ // expect(res.body.request.messages_count).to.equal(1);
184
+ expect(res.body.request.status).to.equal(200);
185
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
186
+ expect(res.body.request.participants.length).to.equal(1);
187
+ expect(res.body.request.department).to.not.equal(null);
188
+ expect(res.body.request.lead).to.not.equal(null);
189
+ expect(res.body.request.attributes.a).to.equal("b");
190
+ expect(res.body.channel_type).to.equal("group");
191
+ expect(res.body.channel.name).to.equal("chat21");
192
+ expect(res.body.request.channel.name).to.equal("chat21");
193
+ expect(res.body.request.location).to.equal(undefined);
194
+
195
+ done();
219
196
  });
197
+ });
198
+ });
220
199
  });
221
- });
222
- });
223
-
224
-
225
-
226
-
227
- // mocha test/messageRoute.js --grep 'createWithSender'
228
-
229
- it('createWithSender', function (done) {
230
- // this.timeout(10000);
231
-
232
- var email = "test-message-createwithsender-" + Date.now() + "@email.com";
233
- var pwd = "pwd";
234
-
235
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
236
-
237
200
 
238
- var email2 = "test-message-createwithsender22-" + Date.now() + "@email.com";
239
- var pwd2 = "pwd";
240
-
241
- userService.signup( email2 ,pwd2, "Test Firstname22", "Test lastname22").then(function(savedUser2) {
242
201
 
243
- projectService.createAndReturnProjectAndProjectUser("message-createwithsender", savedUser._id).then(function(savedProjectAndPU) {
244
-
245
- var savedProject = savedProjectAndPU.project;
246
-
247
-
248
- var pu2 = new Project_user({
249
- // _id: new mongoose.Types.ObjectId(),
250
- id_project: savedProject._id,
251
- id_user: savedUser2._id,
252
- role: roleConstants.AGENT,
253
- user_available: true,
254
- createdBy: savedUser2._id,
255
- updatedBy: savedUser2._id,
256
- });
257
- pu2.save(function (err, savedProject_user2) {
258
-
259
- chai.request(server)
260
- .post('/'+ savedProject._id + '/requests/req123-createwithsender/messages')
261
- .auth(email, pwd)
262
- .set('content-type', 'application/json')
263
- .send({"text":"text", "sender": savedUser2._id.toString()})
264
- .end(function(err, res) {
265
- //console.log("res", res);
266
- console.log("res.body", res.body);
267
- res.should.have.status(200);
268
- res.body.should.be.a('object');
269
-
270
- expect(res.body.sender).to.equal(savedUser2._id.toString());
271
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
272
- expect(res.body.senderFullname).to.equal("Test Firstname22 Test lastname22");
273
- expect(res.body.recipient).to.equal("req123-createwithsender");
274
- expect(res.body.text).to.equal("text");
275
- expect(res.body.id_project).to.equal(savedProject._id.toString());
276
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
277
- expect(res.body.status).to.equal(0);
278
-
279
- expect(res.body.request.request_id).to.equal("req123-createwithsender");
280
- expect(res.body.request.requester._id).to.equal(savedProject_user2._id.toString());
281
- expect(res.body.request.requester.id_user.email).to.equal(email2);
282
- expect(res.body.request.requester.id_user.firstname).to.equal("Test Firstname22");
283
- expect(res.body.request.requester.id_user.lastname).to.equal("Test lastname22");
284
- // expect(res.body.request.requester._id).to.equal(savedProject_user2._id.toString());
285
- // expect(res.body.request.requester_id).to.equal("sender");
286
- expect(res.body.request.first_text).to.equal("text");
287
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
288
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
289
-
290
- // expect(res.body.request.messages_count).to.equal(1);
291
-
292
- expect(res.body.request.status).to.equal(200);
293
- expect(res.body.request.snapshot.agents.length).to.equal(2);
294
- expect(res.body.request.participants.length).to.equal(1);
295
- expect(res.body.request.department).to.not.equal(null);
296
- expect(res.body.request.lead).to.not.equal(null);
297
-
298
- expect(res.body.channel_type).to.equal("group");
299
- expect(res.body.channel.name).to.equal("chat21");
300
- expect(res.body.request.channel.name).to.equal("chat21");
301
-
302
-
303
- expect(res.body.request.location).to.equal(undefined);
304
-
305
-
306
- done();
307
- });
308
- });
309
- });
310
- });
311
- });
312
- });
202
+ // mocha test/messageRoute.js --grep 'createWithSender'
203
+ it('createWithSender', function (done) {
313
204
 
205
+ var email = "test-message-createwithsender-" + Date.now() + "@email.com";
206
+ var pwd = "pwd";
314
207
 
208
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
315
209
 
210
+ var email2 = "test-message-createwithsender22-" + Date.now() + "@email.com";
211
+ var pwd2 = "pwd";
316
212
 
317
- // mocha test/messageRoute.js --grep 'createWithSenderFromLead'
318
-
319
- it('createWithSenderFromLead', function (done) {
320
- // this.timeout(10000);
321
-
322
- var email = "test-message-createwithsenderfromlead-" + Date.now() + "@email.com";
323
- var pwd = "pwd";
324
-
325
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
326
-
327
-
328
-
213
+ userService.signup(email2, pwd2, "Test Firstname22", "Test lastname22").then(function (savedUser2) {
214
+ projectService.createAndReturnProjectAndProjectUser("message-createwithsender", savedUser._id).then(function (savedProjectAndPU) {
329
215
 
330
- projectService.createAndReturnProjectAndProjectUser("message-createwithsender", savedUser._id).then(function(savedProjectAndPU) {
331
-
332
216
  var savedProject = savedProjectAndPU.project;
333
217
 
334
- var uid = uuidv4();
335
- var pu = new Project_user({
218
+ var pu2 = new Project_user({
336
219
  // _id: new mongoose.Types.ObjectId(),
337
220
  id_project: savedProject._id,
338
- uuid_user:uid,
339
- role: roleConstants.USER,
221
+ id_user: savedUser2._id,
222
+ role: roleConstants.AGENT,
340
223
  user_available: true,
341
- createdBy: savedUser._id,
342
- updatedBy: savedUser._id,
224
+ createdBy: savedUser2._id,
225
+ updatedBy: savedUser2._id,
343
226
  });
344
- pu.save(function (err, savedProject_user) {
345
-
346
- // createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy, attributes, status) {
347
- leadService.createIfNotExistsWithLeadId(uid,"leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
348
- // console.log("createdLead",createdLead);
349
-
350
- var now = Date.now();
351
- chai.request(server)
352
- .post('/'+ savedProject._id + '/requests/req123-createwithsender-'+now+'/messages')
353
- .auth(email, pwd)
354
- .set('content-type', 'application/json')
355
- .send({"text":"text", "sender": uid})
356
- .end(function(err, res) {
357
- // console.log("res", res);
358
- console.log("res.body", res.body);
359
- res.should.have.status(200);
360
- res.body.should.be.a('object');
361
-
362
- expect(res.body.sender).to.equal(uid);
363
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
364
- expect(res.body.senderFullname).to.equal("leadfullname");
365
- expect(res.body.recipient).to.equal("req123-createwithsender-"+now);
366
- expect(res.body.text).to.equal("text");
367
- expect(res.body.id_project).to.equal(savedProject._id.toString());
368
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
369
- expect(res.body.status).to.equal(0);
370
-
371
- expect(res.body.request.request_id).to.equal("req123-createwithsender-"+now);
372
- expect(res.body.request.requester._id).to.equal(savedProject_user._id.toString());
373
- expect(res.body.request.requester.uuid_user).to.equal(uid);
374
- // expect(res.body.request.requester.id_user.firstname).to.equal("Test Firstname22");
375
- // expect(res.body.request.requester.id_user.lastname).to.equal("Test lastname22");
376
- // expect(res.body.request.requester._id).to.equal(savedProject_user2._id.toString());
377
- // expect(res.body.request.requester_id).to.equal("sender");
378
- expect(res.body.request.first_text).to.equal("text");
379
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
380
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
381
-
382
- // expect(res.body.request.messages_count).to.equal(1);
383
-
384
- expect(res.body.request.status).to.equal(200);
385
- expect(res.body.request.snapshot.agents.length).to.equal(1);
386
- expect(res.body.request.participants.length).to.equal(1);
387
- expect(res.body.request.department).to.not.equal(null);
388
- expect(res.body.request.lead).to.not.equal(null);
389
-
390
- expect(res.body.channel_type).to.equal("group");
391
- expect(res.body.channel.name).to.equal("chat21");
392
- expect(res.body.request.channel.name).to.equal("chat21");
227
+ pu2.save(function (err, savedProject_user2) {
393
228
 
229
+ chai.request(server)
230
+ .post('/' + savedProject._id + '/requests/req123-createwithsender/messages')
231
+ .auth(email, pwd)
232
+ .set('content-type', 'application/json')
233
+ .send({ "text": "text", "sender": savedUser2._id.toString() })
234
+ .end(function (err, res) {
235
+
236
+ if (err) { console.error("err", err); }
237
+ if (log) { console.log("res.body", res.body); }
238
+
239
+ res.should.have.status(200);
240
+ res.body.should.be.a('object');
241
+ expect(res.body.sender).to.equal(savedUser2._id.toString());
242
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
243
+ expect(res.body.senderFullname).to.equal("Test Firstname22 Test lastname22");
244
+ expect(res.body.recipient).to.equal("req123-createwithsender");
245
+ expect(res.body.text).to.equal("text");
246
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
247
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
248
+ expect(res.body.status).to.equal(0);
249
+ expect(res.body.request.request_id).to.equal("req123-createwithsender");
250
+ expect(res.body.request.requester._id).to.equal(savedProject_user2._id.toString());
251
+ expect(res.body.request.requester.id_user.email).to.equal(email2);
252
+ expect(res.body.request.requester.id_user.firstname).to.equal("Test Firstname22");
253
+ expect(res.body.request.requester.id_user.lastname).to.equal("Test lastname22");
254
+ // expect(res.body.request.requester._id).to.equal(savedProject_user2._id.toString());
255
+ // expect(res.body.request.requester_id).to.equal("sender");
256
+ expect(res.body.request.first_text).to.equal("text");
257
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
258
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
259
+ // expect(res.body.request.messages_count).to.equal(1);
260
+ expect(res.body.request.status).to.equal(200);
261
+ expect(res.body.request.snapshot.agents.length).to.equal(2);
262
+ expect(res.body.request.participants.length).to.equal(1);
263
+ expect(res.body.request.department).to.not.equal(null);
264
+ expect(res.body.request.lead).to.not.equal(null);
265
+ expect(res.body.channel_type).to.equal("group");
266
+ expect(res.body.channel.name).to.equal("chat21");
267
+ expect(res.body.request.channel.name).to.equal("chat21");
268
+ expect(res.body.request.location).to.equal(undefined);
394
269
 
395
- expect(res.body.request.location).to.equal(undefined);
396
-
397
-
398
- done();
399
- });
270
+ done();
400
271
  });
401
- });
402
- });
403
- });
404
- });
405
-
406
-
407
- // mocha test/messageRoute.js --grep 'createWithLocation'
408
- it('createWithLocation', function (done) {
409
- // this.timeout(10000);
410
-
411
- var email = "test-message-create-" + Date.now() + "@email.com";
412
- var pwd = "pwd";
413
-
414
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
415
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
416
-
417
- var savedProject = savedProjectAndPU.project;
418
-
419
- chai.request(server)
420
- .post('/'+ savedProject._id + '/requests/req-createWithLocation/messages')
421
- .auth(email, pwd)
422
- .set('content-type', 'application/json')
423
- .send({text:"text", location: {country: "Italy", streetAddress: "Via Roma, 767b", ipAddress: "192.168.1.1", geometry: {type: "Point", coordinates: [-109, 41]} } })
424
- .end(function(err, res) {
425
- //console.log("res", res);
426
- console.log("res.body", res.body);
427
- res.should.have.status(200);
428
- res.body.should.be.a('object');
429
-
430
- expect(res.body.sender).to.equal(savedUser._id.toString());
431
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
432
- // expect(res.body.senderFullname).to.equal("senderFullname");
433
- expect(res.body.recipient).to.equal("req-createWithLocation");
434
- expect(res.body.text).to.equal("text");
435
- expect(res.body.id_project).to.equal(savedProject._id.toString());
436
-
437
- expect(res.body.request.request_id).to.equal("req-createWithLocation");
438
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
439
- // expect(res.body.request.requester_id).to.equal("sender");
440
- expect(res.body.request.first_text).to.equal("text");
441
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
442
-
443
-
444
- expect(res.body.request.location.country).to.equal("Italy");
445
- expect(res.body.request.location.streetAddress).to.equal("Via Roma, 767b");
446
- expect(res.body.request.location.ipAddress).to.equal("192.168.1.1");
447
- expect(res.body.request.location.geometry.type).to.equal("Point");
448
- expect(res.body.request.location.geometry.coordinates[0]).to.equal(-109);
449
- expect(res.body.request.location.geometry.coordinates[1]).to.equal(41);
450
-
451
- done();
452
272
  });
273
+ });
274
+ });
275
+ });
453
276
  });
454
- });
455
- });
456
-
457
277
 
458
278
 
279
+ // mocha test/messageRoute.js --grep 'createWithSenderFromLead'
280
+ it('createWithSenderFromLead', function (done) {
459
281
 
460
- // mocha test/messageRoute.js --grep 'createWithLocationAsAttributes'
461
- it('createWithLocationAsAttributes', function (done) {
462
- // this.timeout(10000);
282
+ var email = "test-message-createwithsenderfromlead-" + Date.now() + "@email.com";
283
+ var pwd = "pwd";
463
284
 
464
- var email = "test-message-create-" + Date.now() + "@email.com";
465
- var pwd = "pwd";
285
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
286
+ projectService.createAndReturnProjectAndProjectUser("message-createwithsender", savedUser._id).then(function (savedProjectAndPU) {
466
287
 
467
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
468
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
469
-
470
- var savedProject = savedProjectAndPU.project;
288
+ var savedProject = savedProjectAndPU.project;
471
289
 
472
- chai.request(server)
473
- .post('/'+ savedProject._id + '/requests/req-createWithLocationAsAttributes/messages')
474
- .auth(email, pwd)
475
- .set('content-type', 'application/json')
476
- .send({text:"text", attributes: {ipAddress: "95.255.73.34"} })
477
- .end(function(err, res) {
478
- //console.log("res", res);
479
- console.log("res.body", res.body);
480
- res.should.have.status(200);
481
- res.body.should.be.a('object');
482
-
483
- expect(res.body.sender).to.equal(savedUser._id.toString());
484
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
485
- // expect(res.body.senderFullname).to.equal("senderFullname");
486
- expect(res.body.recipient).to.equal("req-createWithLocationAsAttributes");
487
- expect(res.body.text).to.equal("text");
488
- expect(res.body.id_project).to.equal(savedProject._id.toString());
489
-
490
- expect(res.body.request.request_id).to.equal("req-createWithLocationAsAttributes");
491
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
492
- // expect(res.body.request.requester_id).to.equal("sender");
493
- expect(res.body.request.first_text).to.equal("text");
494
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
495
-
290
+ var uid = uuidv4();
291
+ var pu = new Project_user({
292
+ // _id: new mongoose.Types.ObjectId(),
293
+ id_project: savedProject._id,
294
+ uuid_user: uid,
295
+ role: roleConstants.USER,
296
+ user_available: true,
297
+ createdBy: savedUser._id,
298
+ updatedBy: savedUser._id,
299
+ });
300
+ pu.save(function (err, savedProject_user) {
301
+ // createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy, attributes, status) {
302
+ leadService.createIfNotExistsWithLeadId(uid, "leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
496
303
 
497
- chai.request(server)
498
- .get('/'+ savedProject._id + '/requests/req-createWithLocationAsAttributes')
304
+ var now = Date.now();
305
+ chai.request(server)
306
+ .post('/' + savedProject._id + '/requests/req123-createwithsender-' + now + '/messages')
499
307
  .auth(email, pwd)
500
308
  .set('content-type', 'application/json')
501
- .send()
502
- .end(function(err, res) {
503
- //console.log("res", res);
504
- console.log("res.body", res.body);
505
- res.should.have.status(200);
506
- res.body.should.be.a('object');
507
-
508
- expect(res.body.request_id).to.equal("req-createWithLocationAsAttributes");
509
-
510
- expect(res.body.location.country).to.equal("IT");
511
- expect(res.body.location.ipAddress).to.equal("95.255.73.34");
512
- expect(res.body.location.geometry.type).to.equal("Point");
513
- expect(res.body.location.geometry.coordinates[0]).to.equal(42.6716);
514
- expect(res.body.location.geometry.coordinates[1]).to.equal(14.0148);
515
-
516
- done();
517
- });
518
- });
519
- });
520
- });
521
- });
522
-
523
- it('createDifferentChannel', function (done) {
524
- // this.timeout(10000);
309
+ .send({ "text": "text", "sender": uid })
310
+ .end(function (err, res) {
311
+ // console.log("res", res);
312
+ if (log) { console.log("res.body", res.body); }
313
+ res.should.have.status(200);
314
+ res.body.should.be.a('object');
525
315
 
526
- var email = "test-message-createdifferentchannel-" + Date.now() + "@email.com";
527
- var pwd = "pwd";
316
+ expect(res.body.sender).to.equal(uid);
317
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
318
+ expect(res.body.senderFullname).to.equal("leadfullname");
319
+ expect(res.body.recipient).to.equal("req123-createwithsender-" + now);
320
+ expect(res.body.text).to.equal("text");
321
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
322
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
323
+ expect(res.body.status).to.equal(0);
528
324
 
529
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
530
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
531
-
532
- var savedProject = savedProjectAndPU.project;
325
+ expect(res.body.request.request_id).to.equal("req123-createwithsender-" + now);
326
+ expect(res.body.request.requester._id).to.equal(savedProject_user._id.toString());
327
+ expect(res.body.request.requester.uuid_user).to.equal(uid);
328
+ // expect(res.body.request.requester.id_user.firstname).to.equal("Test Firstname22");
329
+ // expect(res.body.request.requester.id_user.lastname).to.equal("Test lastname22");
330
+ // expect(res.body.request.requester._id).to.equal(savedProject_user2._id.toString());
331
+ // expect(res.body.request.requester_id).to.equal("sender");
332
+ expect(res.body.request.first_text).to.equal("text");
333
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
334
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
335
+ // expect(res.body.request.messages_count).to.equal(1);
336
+ expect(res.body.request.status).to.equal(200);
337
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
338
+ expect(res.body.request.participants.length).to.equal(1);
339
+ expect(res.body.request.department).to.not.equal(null);
340
+ expect(res.body.request.lead).to.not.equal(null);
341
+ expect(res.body.channel_type).to.equal("group");
342
+ expect(res.body.channel.name).to.equal("chat21");
343
+ expect(res.body.request.channel.name).to.equal("chat21");
344
+ expect(res.body.request.location).to.equal(undefined);
533
345
 
534
- chai.request(server)
535
- .post('/'+ savedProject._id + '/requests/req123-channel1/messages')
536
- .auth(email, pwd)
537
- .set('content-type', 'application/json')
538
- .send({text:"text", channel: {name:"channel1"}})
539
- .end(function(err, res) {
540
- //console.log("res", res);
541
- console.log("res.body", res.body);
542
- res.should.have.status(200);
543
- res.body.should.be.a('object');
544
-
545
- expect(res.body.sender).to.equal(savedUser._id.toString());
546
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
547
- // expect(res.body.senderFullname).to.equal("senderFullname");
548
- expect(res.body.recipient).to.equal("req123-channel1");
549
- expect(res.body.text).to.equal("text");
550
- expect(res.body.id_project).to.equal(savedProject._id.toString());
551
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
552
- expect(res.body.status).to.equal(0);
553
-
554
- expect(res.body.request.request_id).to.equal("req123-channel1");
555
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
556
- // expect(res.body.request.requester_id).to.equal("sender");
557
- expect(res.body.request.first_text).to.equal("text");
558
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
559
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
560
-
561
- // expect(res.body.request.messages_count).to.equal(1);
562
-
563
- expect(res.body.request.status).to.equal(200);
564
- expect(res.body.request.snapshot.agents.length).to.equal(1);
565
- expect(res.body.request.participants.length).to.equal(1);
566
- expect(res.body.request.department).to.not.equal(undefined);
567
- expect(res.body.request.lead).to.not.equal(null);
568
-
569
- expect(res.body.channel_type).to.equal("group");
570
- expect(res.body.channel.name).to.equal("channel1");
571
- expect(res.body.request.channel.name).to.equal("channel1");
572
-
573
- done();
346
+ done();
347
+ });
574
348
  });
349
+ });
350
+ });
351
+ });
575
352
  });
576
- });
577
- });
578
-
579
-
580
353
 
581
354
 
582
- // mocha test/messageRoute.js --grep 'createWithMessageStatus'
583
-
584
- it('createWithMessageStatus', function (done) {
585
- // this.timeout(10000);
355
+ // mocha test/messageRoute.js --grep 'createWithLocation'
356
+ it('createWithLocation', function (done) {
357
+
358
+ var email = "test-message-create-" + Date.now() + "@email.com";
359
+ var pwd = "pwd";
586
360
 
587
- var email = "test-message-create-" + Date.now() + "@email.com";
588
- var pwd = "pwd";
361
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
362
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
589
363
 
590
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
591
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
592
-
593
- var savedProject = savedProjectAndPU.project;
364
+ var savedProject = savedProjectAndPU.project;
594
365
 
595
366
  chai.request(server)
596
- .post('/'+ savedProject._id + '/requests/req123-createWithMessageStatus/messages')
367
+ .post('/' + savedProject._id + '/requests/req-createWithLocation/messages')
597
368
  .auth(email, pwd)
598
369
  .set('content-type', 'application/json')
599
- .send({"text":"text", "status":999})
600
- .end(function(err, res) {
601
- //console.log("res", res);
602
- console.log("res.body", res.body);
603
- res.should.have.status(200);
604
- res.body.should.be.a('object');
605
-
606
- expect(res.body.sender).to.equal(savedUser._id.toString());
607
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
608
- // expect(res.body.senderFullname).to.equal("senderFullname");
609
- expect(res.body.recipient).to.equal("req123-createWithMessageStatus");
610
- expect(res.body.text).to.equal("text");
611
- expect(res.body.id_project).to.equal(savedProject._id.toString());
612
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
613
- expect(res.body.status).to.equal(999);
614
-
615
- expect(res.body.request.request_id).to.equal("req123-createWithMessageStatus");
616
-
617
- console.log("res.body.request.requester",JSON.stringify(res.body.request.requester));
618
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
619
- // expect(res.body.request.requester_id).to.equal("sender");
620
- expect(res.body.request.first_text).to.equal("text");
621
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
622
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
623
-
624
- // expect(res.body.request.messages_count).to.equal(1);
625
-
626
- expect(res.body.request.status).to.equal(200);
627
- expect(res.body.request.snapshot.agents.length).to.equal(1);
628
- expect(res.body.request.participants.length).to.equal(1);
629
- expect(res.body.request.department).to.not.equal(null);
630
- expect(res.body.request.lead).to.not.equal(null);
631
-
632
- expect(res.body.channel_type).to.equal("group");
633
- expect(res.body.channel.name).to.equal("chat21");
634
- expect(res.body.request.channel.name).to.equal("chat21");
635
-
636
-
637
- expect(res.body.request.location).to.equal(undefined);
638
-
639
-
640
- done();
370
+ .send({ text: "text", location: { country: "Italy", streetAddress: "Via Roma, 767b", ipAddress: "192.168.1.1", geometry: { type: "Point", coordinates: [-109, 41] } } })
371
+ .end(function (err, res) {
372
+
373
+ if (err) { console.error("err", err); }
374
+ if (log) { console.log("res.body", res.body); }
375
+
376
+ res.should.have.status(200);
377
+ res.body.should.be.a('object');
378
+
379
+ expect(res.body.sender).to.equal(savedUser._id.toString());
380
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
381
+ // expect(res.body.senderFullname).to.equal("senderFullname");
382
+ expect(res.body.recipient).to.equal("req-createWithLocation");
383
+ expect(res.body.text).to.equal("text");
384
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
385
+ expect(res.body.request.request_id).to.equal("req-createWithLocation");
386
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
387
+ // expect(res.body.request.requester_id).to.equal("sender");
388
+ expect(res.body.request.first_text).to.equal("text");
389
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
390
+ expect(res.body.request.location.country).to.equal("Italy");
391
+ expect(res.body.request.location.streetAddress).to.equal("Via Roma, 767b");
392
+ expect(res.body.request.location.ipAddress).to.equal("192.168.1.1");
393
+ expect(res.body.request.location.geometry.type).to.equal("Point");
394
+ expect(res.body.request.location.geometry.coordinates[0]).to.equal(-109);
395
+ expect(res.body.request.location.geometry.coordinates[1]).to.equal(41);
396
+
397
+ done();
641
398
  });
399
+ });
400
+ });
642
401
  });
643
- });
644
- });
645
-
646
-
647
402
 
403
+ // mocha test/messageRoute.js --grep 'createWithLocationAsAttributes'
404
+ it('createWithLocationAsAttributes', function (done) {
648
405
 
406
+ var email = "test-message-create-" + Date.now() + "@email.com";
407
+ var pwd = "pwd";
649
408
 
409
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
410
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
650
411
 
651
-
652
- // mocha test/messageRoute.js --grep 'createWithParticipants'
653
-
654
- it('createWithParticipants', function (done) {
655
- // this.timeout(10000);
656
-
657
- var email = "test-message-create-" + Date.now() + "@email.com";
658
- var pwd = "pwd";
659
-
660
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
661
-
662
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
663
-
664
- var savedProject = savedProjectAndPU.project;
412
+ var savedProject = savedProjectAndPU.project;
665
413
 
666
414
  chai.request(server)
667
- .post('/'+ savedProject._id + '/requests/req123-createWithParticipants/messages')
415
+ .post('/' + savedProject._id + '/requests/req-createWithLocationAsAttributes/messages')
668
416
  .auth(email, pwd)
669
417
  .set('content-type', 'application/json')
670
- .send({"text":"text", "participants":[savedUser._id] })
671
- .end(function(err, res) {
672
- //console.log("res", res);
673
- console.log("res.body", res.body);
674
- res.should.have.status(200);
675
- res.body.should.be.a('object');
676
-
677
- expect(res.body.sender).to.equal(savedUser._id.toString());
678
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
679
- // expect(res.body.senderFullname).to.equal("senderFullname");
680
- expect(res.body.recipient).to.equal("req123-createWithParticipants");
681
- expect(res.body.text).to.equal("text");
682
- expect(res.body.id_project).to.equal(savedProject._id.toString());
683
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
684
- expect(res.body.status).to.equal(0);
685
-
686
- expect(res.body.request.request_id).to.equal("req123-createWithParticipants");
687
- // expect(res.body.request.requester).to.equal(savedProjectAndPU.project_user._id.toString());
688
- // expect(res.body.request.requester_id).to.equal("sender");
689
- expect(res.body.request.first_text).to.equal("text");
690
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
691
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
692
-
693
- // expect(res.body.request.messages_count).to.equal(1);
694
-
695
- expect(res.body.request.status).to.equal(200);
696
- expect(res.body.request.snapshot.agents.length).to.equal(1);
697
- expect(res.body.request.participants.length).to.equal(1);
698
- expect(res.body.request.participants[0]).to.equal(savedUser._id.toString());
699
-
700
- console.log("res.body.request.participatingAgents[0]",JSON.stringify(res.body.request.participatingAgents[0]))
701
- expect(res.body.request.participatingAgents[0]._id).to.equal(savedUser._id.toString());
702
- expect(res.body.request.department).to.equal(undefined);
703
- expect(res.body.request.lead).to.not.equal(null);
704
-
705
- expect(res.body.channel_type).to.equal("group");
706
- expect(res.body.channel.name).to.equal("chat21");
707
- expect(res.body.request.channel.name).to.equal("chat21");
708
-
418
+ .send({ text: "text", attributes: { ipAddress: "95.255.73.34" } })
419
+ .end(function (err, res) {
420
+
421
+ if (err) { console.error("err", err); }
422
+ if (log) { console.log("res.body", res.body); }
423
+
424
+ res.should.have.status(200);
425
+ res.body.should.be.a('object');
426
+
427
+ expect(res.body.sender).to.equal(savedUser._id.toString());
428
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
429
+ // expect(res.body.senderFullname).to.equal("senderFullname");
430
+ expect(res.body.recipient).to.equal("req-createWithLocationAsAttributes");
431
+ expect(res.body.text).to.equal("text");
432
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
433
+ expect(res.body.request.request_id).to.equal("req-createWithLocationAsAttributes");
434
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
435
+ // expect(res.body.request.requester_id).to.equal("sender");
436
+ expect(res.body.request.first_text).to.equal("text");
437
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
709
438
 
710
- expect(res.body.request.location).to.equal(undefined);
711
-
712
-
713
- done();
439
+ chai.request(server)
440
+ .get('/' + savedProject._id + '/requests/req-createWithLocationAsAttributes')
441
+ .auth(email, pwd)
442
+ .set('content-type', 'application/json')
443
+ .send()
444
+ .end(function (err, res) {
445
+
446
+ if (err) { console.error("err", err); }
447
+ if (log) { console.log("res.body", res.body); }
448
+
449
+ res.should.have.status(200);
450
+ res.body.should.be.a('object');
451
+ expect(res.body.request_id).to.equal("req-createWithLocationAsAttributes");
452
+ expect(res.body.location.country).to.equal("IT");
453
+ expect(res.body.location.ipAddress).to.equal("95.255.73.34");
454
+ expect(res.body.location.geometry.type).to.equal("Point");
455
+ expect(res.body.location.geometry.coordinates[0]).to.equal(42.6716);
456
+ expect(res.body.location.geometry.coordinates[1]).to.equal(14.0148);
457
+
458
+ done();
459
+ });
714
460
  });
461
+ });
462
+ });
715
463
  });
716
- });
717
- });
718
-
719
-
720
464
 
465
+ it('createDifferentChannel', function (done) {
721
466
 
467
+ var email = "test-message-createdifferentchannel-" + Date.now() + "@email.com";
468
+ var pwd = "pwd";
722
469
 
723
- // mocha test/messageRoute.js --grep 'createWithPriority'
724
-
725
- it('createWithPriority', function (done) {
726
- // this.timeout(10000);
727
-
728
- var email = "test-message-create-" + Date.now() + "@email.com";
729
- var pwd = "pwd";
730
-
731
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
732
- projectService.createAndReturnProjectAndProjectUser("message-createWithPriority", savedUser._id).then(function(savedProjectAndPU) {
733
-
734
- var savedProject = savedProjectAndPU.project;
470
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
471
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
735
472
 
736
- var reqid = 'req123-createWithPriority' + Date.now();
473
+ var savedProject = savedProjectAndPU.project;
737
474
 
738
475
  chai.request(server)
739
- .post('/'+ savedProject._id + '/requests/'+reqid +'/messages')
476
+ .post('/' + savedProject._id + '/requests/req123-channel1/messages')
740
477
  .auth(email, pwd)
741
478
  .set('content-type', 'application/json')
742
- .send({"text":"text", "priority": "hight"})
743
- .end(function(err, res) {
744
- //console.log("res", res);
745
- console.log("res.body", res.body);
746
- res.should.have.status(200);
747
- res.body.should.be.a('object');
748
-
749
- expect(res.body.sender).to.equal(savedUser._id.toString());
750
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
751
- // expect(res.body.senderFullname).to.equal("senderFullname");
752
- expect(res.body.recipient).to.equal(reqid);
753
- expect(res.body.text).to.equal("text");
754
- expect(res.body.id_project).to.equal(savedProject._id.toString());
755
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
756
- expect(res.body.status).to.equal(0);
757
-
758
- expect(res.body.request.request_id).to.equal(reqid);
759
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
760
- // expect(res.body.request.requester_id).to.equal("sender");
761
- expect(res.body.request.first_text).to.equal("text");
762
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
763
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
764
-
765
- // expect(res.body.request.messages_count).to.equal(1);
766
-
767
- expect(res.body.request.status).to.equal(200);
768
- expect(res.body.request.snapshot.agents.length).to.equal(1);
769
- expect(res.body.request.participants.length).to.equal(1);
770
- expect(res.body.request.department).to.not.equal(null);
771
- expect(res.body.request.lead).to.not.equal(null);
772
- expect(res.body.request.priority).to.equal("hight");
773
-
774
-
775
- expect(res.body.channel_type).to.equal("group");
776
- expect(res.body.channel.name).to.equal("chat21");
777
- expect(res.body.request.channel.name).to.equal("chat21");
778
-
779
-
780
- expect(res.body.request.location).to.equal(undefined);
781
-
782
-
783
- done();
479
+ .send({ text: "text", channel: { name: "channel1" } })
480
+ .end(function (err, res) {
481
+
482
+ if (err) { console.error("err", err); }
483
+ if (log) { console.log("res.body", res.body); }
484
+
485
+ res.should.have.status(200);
486
+ res.body.should.be.a('object');
487
+ expect(res.body.sender).to.equal(savedUser._id.toString());
488
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
489
+ // expect(res.body.senderFullname).to.equal("senderFullname");
490
+ expect(res.body.recipient).to.equal("req123-channel1");
491
+ expect(res.body.text).to.equal("text");
492
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
493
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
494
+ expect(res.body.status).to.equal(0);
495
+ expect(res.body.request.request_id).to.equal("req123-channel1");
496
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
497
+ // expect(res.body.request.requester_id).to.equal("sender");
498
+ expect(res.body.request.first_text).to.equal("text");
499
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
500
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
501
+ // expect(res.body.request.messages_count).to.equal(1);
502
+ expect(res.body.request.status).to.equal(200);
503
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
504
+ expect(res.body.request.participants.length).to.equal(1);
505
+ expect(res.body.request.department).to.not.equal(undefined);
506
+ expect(res.body.request.lead).to.not.equal(null);
507
+ expect(res.body.channel_type).to.equal("group");
508
+ expect(res.body.channel.name).to.equal("channel1");
509
+ expect(res.body.request.channel.name).to.equal("channel1");
510
+
511
+ done();
784
512
  });
513
+ });
514
+ });
785
515
  });
786
- });
787
- });
788
-
789
-
790
516
 
791
517
 
518
+ // mocha test/messageRoute.js --grep 'createWithMessageStatus'
519
+ it('createWithMessageStatus', function (done) {
792
520
 
521
+ var email = "test-message-create-" + Date.now() + "@email.com";
522
+ var pwd = "pwd";
793
523
 
794
- // mocha test/messageRoute.js --grep 'createSimpleWithFollowers'
795
-
796
- it('createSimpleWithFollowers', function (done) {
797
- // this.timeout(10000);
798
-
799
- var email = "test-message-create-" + Date.now() + "@email.com";
800
- var pwd = "pwd";
524
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
525
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
801
526
 
802
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
803
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
804
-
805
- var savedProject = savedProjectAndPU.project;
527
+ var savedProject = savedProjectAndPU.project;
806
528
 
807
529
  chai.request(server)
808
- .post('/'+ savedProject._id + '/requests/req123-createSimpleWithFollowers/messages')
530
+ .post('/' + savedProject._id + '/requests/req123-createWithMessageStatus/messages')
809
531
  .auth(email, pwd)
810
532
  .set('content-type', 'application/json')
811
- .send({"text":"text", "followers": [savedProjectAndPU.project_user._id.toString()]})
812
- .end(function(err, res) {
813
- //console.log("res", res);
814
- console.log("res.body", JSON.stringify(res.body));
815
- res.should.have.status(200);
816
- res.body.should.be.a('object');
817
-
818
- expect(res.body.sender).to.equal(savedUser._id.toString());
819
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
820
- // expect(res.body.senderFullname).to.equal("senderFullname");
821
- expect(res.body.recipient).to.equal("req123-createSimpleWithFollowers");
822
- expect(res.body.text).to.equal("text");
823
- expect(res.body.id_project).to.equal(savedProject._id.toString());
824
- expect(res.body.createdBy).to.equal(savedUser._id.toString());
825
- expect(res.body.status).to.equal(0);
826
-
827
- expect(res.body.request.request_id).to.equal("req123-createSimpleWithFollowers");
828
- expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
829
- // expect(res.body.request.requester_id).to.equal("sender");
830
- expect(res.body.request.first_text).to.equal("text");
831
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
832
- expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
833
-
834
- // expect(res.body.request.messages_count).to.equal(1);
835
-
836
- expect(res.body.request.status).to.equal(200);
837
- expect(res.body.request.snapshot.agents.length).to.equal(1);
838
- expect(res.body.request.participants.length).to.equal(1);
839
- expect(res.body.request.department).to.not.equal(null);
840
- expect(res.body.request.lead).to.not.equal(null);
841
-
842
- expect(res.body.channel_type).to.equal("group");
843
- expect(res.body.channel.name).to.equal("chat21");
844
- expect(res.body.request.channel.name).to.equal("chat21");
845
-
846
-
847
- expect(res.body.request.location).to.equal(undefined);
848
-
849
- expect(res.body.request.followers[0]).to.equal(savedProjectAndPU.project_user._id.toString());
850
-
851
-
852
- done();
533
+ .send({ "text": "text", "status": 999 })
534
+ .end(function (err, res) {
535
+
536
+ if (err) { console.error("err", err); }
537
+ if (log) { console.log("res.body", res.body); }
538
+
539
+ res.should.have.status(200);
540
+ res.body.should.be.a('object');
541
+ expect(res.body.sender).to.equal(savedUser._id.toString());
542
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
543
+ // expect(res.body.senderFullname).to.equal("senderFullname");
544
+ expect(res.body.recipient).to.equal("req123-createWithMessageStatus");
545
+ expect(res.body.text).to.equal("text");
546
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
547
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
548
+ expect(res.body.status).to.equal(999);
549
+ expect(res.body.request.request_id).to.equal("req123-createWithMessageStatus");
550
+ if (log) { console.log("res.body.request.requester", JSON.stringify(res.body.request.requester)); }
551
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
552
+ // expect(res.body.request.requester_id).to.equal("sender");
553
+ expect(res.body.request.first_text).to.equal("text");
554
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
555
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
556
+ // expect(res.body.request.messages_count).to.equal(1);
557
+ expect(res.body.request.status).to.equal(200);
558
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
559
+ expect(res.body.request.participants.length).to.equal(1);
560
+ expect(res.body.request.department).to.not.equal(null);
561
+ expect(res.body.request.lead).to.not.equal(null);
562
+ expect(res.body.channel_type).to.equal("group");
563
+ expect(res.body.channel.name).to.equal("chat21");
564
+ expect(res.body.request.channel.name).to.equal("chat21");
565
+ expect(res.body.request.location).to.equal(undefined);
566
+
567
+ done();
853
568
  });
569
+ });
570
+ });
854
571
  });
855
- });
856
- });
857
-
858
-
859
-
860
-
861
-
862
-
863
572
 
573
+ // mocha test/messageRoute.js --grep 'createWithParticipants'
574
+ it('createWithParticipants', function (done) {
864
575
 
576
+ var email = "test-message-create-" + Date.now() + "@email.com";
577
+ var pwd = "pwd";
865
578
 
579
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
580
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
866
581
 
867
- // mocha test/messageRoute.js --grep 'createMultiTextNoSender1'
868
-
869
- it('createMultiTextNoSender1', function (done) {
870
-
871
- var email = "test-message-create-" + Date.now() + "@email.com";
872
- var pwd = "pwd";
873
-
874
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
875
- projectService.createAndReturnProjectAndProjectUser("message-createMultiText", savedUser._id).then(function(savedProjectAndPU) {
876
-
877
- var savedProject = savedProjectAndPU.project;
878
-
879
-
880
- chai.request(server)
881
- .post('/'+ savedProject._id + '/requests')
882
- .auth(email, pwd)
883
- .set('content-type', 'application/json')
884
- .send({"first_text":"first_text"})
885
- .end(function(err, res) {
886
-
887
- console.log("res.body", res.body);
888
- res.should.have.status(200);
889
- res.body.should.be.a('object');
890
- res.body.should.have.property('first_text').eql('first_text');
891
-
892
- var request_id = res.body.request_id;
893
- console.log("request_id",request_id);
582
+ var savedProject = savedProjectAndPU.project;
894
583
 
895
584
  chai.request(server)
896
- .post('/'+ savedProject._id + '/requests/'+request_id+'/messages/multi')
585
+ .post('/' + savedProject._id + '/requests/req123-createWithParticipants/messages')
897
586
  .auth(email, pwd)
898
587
  .set('content-type', 'application/json')
899
- .send([{"text":"text1"}, {"text":"text2"}])
900
- .end(function(err, res) {
901
- //console.log("res", res);
902
- console.log("res.body", res.body);
903
- res.should.have.status(200);
904
- res.body.should.be.a('array');
905
-
906
- expect(res.body[0].sender).to.equal(savedUser._id.toString());
907
- expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
908
- expect(res.body[0].recipient).to.equal(request_id);
909
- expect(res.body[0].text).to.equal("text1");
910
- expect(res.body[0].id_project).to.equal(savedProject._id.toString());
911
- expect(res.body[0].createdBy).to.equal(savedUser._id.toString());
912
- expect(res.body[0].status).to.equal(0);
913
- expect(res.body[0].channel_type).to.equal("group");
914
- expect(res.body[0].channel.name).to.equal("chat21");
915
-
916
-
917
-
918
- expect(res.body[1].sender).to.equal(savedUser._id.toString());
919
- expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
920
- expect(res.body[1].recipient).to.equal(request_id);
921
- expect(res.body[1].text).to.equal("text2");
922
- expect(res.body[1].id_project).to.equal(savedProject._id.toString());
923
- expect(res.body[1].createdBy).to.equal(savedUser._id.toString());
924
- expect(res.body[1].status).to.equal(0);
925
- expect(res.body[1].channel_type).to.equal("group");
926
- expect(res.body[1].channel.name).to.equal("chat21");
927
-
928
- done();
588
+ .send({ "text": "text", "participants": [savedUser._id] })
589
+ .end(function (err, res) {
590
+
591
+ if (err) { console.error("err", err); }
592
+ if (log) { console.log("res.body", res.body); }
593
+
594
+ res.should.have.status(200);
595
+ res.body.should.be.a('object');
596
+ expect(res.body.sender).to.equal(savedUser._id.toString());
597
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
598
+ // expect(res.body.senderFullname).to.equal("senderFullname");
599
+ expect(res.body.recipient).to.equal("req123-createWithParticipants");
600
+ expect(res.body.text).to.equal("text");
601
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
602
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
603
+ expect(res.body.status).to.equal(0);
604
+ expect(res.body.request.request_id).to.equal("req123-createWithParticipants");
605
+ // expect(res.body.request.requester).to.equal(savedProjectAndPU.project_user._id.toString());
606
+ // expect(res.body.request.requester_id).to.equal("sender");
607
+ expect(res.body.request.first_text).to.equal("text");
608
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
609
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
610
+ // expect(res.body.request.messages_count).to.equal(1);
611
+ expect(res.body.request.status).to.equal(200);
612
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
613
+ expect(res.body.request.participants.length).to.equal(1);
614
+ expect(res.body.request.participants[0]).to.equal(savedUser._id.toString());
615
+ if (log) { console.log("res.body.request.participatingAgents[0]", JSON.stringify(res.body.request.participatingAgents[0])); }
616
+ expect(res.body.request.participatingAgents[0]._id).to.equal(savedUser._id.toString());
617
+ expect(res.body.request.department).to.equal(undefined);
618
+ expect(res.body.request.lead).to.not.equal(null);
619
+ expect(res.body.channel_type).to.equal("group");
620
+ expect(res.body.channel.name).to.equal("chat21");
621
+ expect(res.body.request.channel.name).to.equal("chat21");
622
+ expect(res.body.request.location).to.equal(undefined);
623
+
624
+ done();
929
625
  });
930
- });
626
+ });
627
+ });
931
628
  });
932
- });
933
- });
934
-
935
-
936
-
937
-
938
-
939
- // mocha test/messageRoute.js --grep 'createMultiTextNoSenderNoText'
940
629
 
941
- it('createMultiTextNoSenderNoText', function (done) {
942
630
 
943
- var email = "test-message-create-" + Date.now() + "@email.com";
944
- var pwd = "pwd";
631
+ // mocha test/messageRoute.js --grep 'createWithPriority'
632
+ it('createWithPriority', function (done) {
945
633
 
946
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
947
- projectService.createAndReturnProjectAndProjectUser("message-createMultiText", savedUser._id).then(function(savedProjectAndPU) {
948
-
949
- var savedProject = savedProjectAndPU.project;
950
-
951
-
952
- chai.request(server)
953
- .post('/'+ savedProject._id + '/requests')
954
- .auth(email, pwd)
955
- .set('content-type', 'application/json')
956
- .send({"first_text":"first_text"})
957
- .end(function(err, res) {
634
+ var email = "test-message-create-" + Date.now() + "@email.com";
635
+ var pwd = "pwd";
958
636
 
959
- console.log("res.body", res.body);
960
- res.should.have.status(200);
961
- res.body.should.be.a('object');
962
- res.body.should.have.property('first_text').eql('first_text');
637
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
638
+ projectService.createAndReturnProjectAndProjectUser("message-createWithPriority", savedUser._id).then(function (savedProjectAndPU) {
963
639
 
964
- var request_id = res.body.request_id;
965
- console.log("request_id",request_id);
640
+ var savedProject = savedProjectAndPU.project;
641
+ var reqid = 'req123-createWithPriority' + Date.now();
966
642
 
967
643
  chai.request(server)
968
- .post('/'+ savedProject._id + '/requests/'+request_id+'/messages/multi')
644
+ .post('/' + savedProject._id + '/requests/' + reqid + '/messages')
969
645
  .auth(email, pwd)
970
646
  .set('content-type', 'application/json')
971
- .send([{}, {"text":"text2"}])
972
- .end(function(err, res) {
973
- //console.log("res", res);
974
- console.log("res.body", res.body);
975
- res.should.have.status(200);
976
-
977
- done();
647
+ .send({ "text": "text", "priority": "hight" })
648
+ .end(function (err, res) {
649
+
650
+ if (err) { console.error("err", err); }
651
+ if (log) { console.log("res.body", res.body); }
652
+
653
+ res.should.have.status(200);
654
+ res.body.should.be.a('object');
655
+ expect(res.body.sender).to.equal(savedUser._id.toString());
656
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
657
+ // expect(res.body.senderFullname).to.equal("senderFullname");
658
+ expect(res.body.recipient).to.equal(reqid);
659
+ expect(res.body.text).to.equal("text");
660
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
661
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
662
+ expect(res.body.status).to.equal(0);
663
+ expect(res.body.request.request_id).to.equal(reqid);
664
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
665
+ // expect(res.body.request.requester_id).to.equal("sender");
666
+ expect(res.body.request.first_text).to.equal("text");
667
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
668
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
669
+ // expect(res.body.request.messages_count).to.equal(1);
670
+ expect(res.body.request.status).to.equal(200);
671
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
672
+ expect(res.body.request.participants.length).to.equal(1);
673
+ expect(res.body.request.department).to.not.equal(null);
674
+ expect(res.body.request.lead).to.not.equal(null);
675
+ expect(res.body.request.priority).to.equal("hight");
676
+ expect(res.body.channel_type).to.equal("group");
677
+ expect(res.body.channel.name).to.equal("chat21");
678
+ expect(res.body.request.channel.name).to.equal("chat21");
679
+ expect(res.body.request.location).to.equal(undefined);
680
+ done();
978
681
  });
979
- });
980
- });
981
- });
982
- });
983
-
984
-
985
-
986
-
987
-
988
- // mocha test/messageRoute.js --grep 'createMultiTextWithSender'
989
-
990
- it('createMultiTextWithSender', function (done) {
991
-
992
- var email = "test-message-create-" + Date.now() + "@email.com";
993
- var pwd = "pwd";
682
+ });
683
+ });
684
+ });
994
685
 
995
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
996
686
 
997
- var email2 = "test-message-createwithsender22-" + Date.now() + "@email.com";
998
- var pwd2 = "pwd";
999
-
1000
- userService.signup( email2 ,pwd2, "Test Firstname22", "Test lastname22").then(function(savedUser2) {
1001
-
687
+ // mocha test/messageRoute.js --grep 'createSimpleWithFollowers'
688
+ it('createSimpleWithFollowers', function (done) {
1002
689
 
1003
- projectService.createAndReturnProjectAndProjectUser("message-createMultiText", savedUser._id).then(function(savedProjectAndPU) {
1004
-
1005
- var savedProject = savedProjectAndPU.project;
690
+ var email = "test-message-create-" + Date.now() + "@email.com";
691
+ var pwd = "pwd";
1006
692
 
693
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
694
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
1007
695
 
696
+ var savedProject = savedProjectAndPU.project;
1008
697
 
1009
- var pu2 = new Project_user({
1010
- // _id: new mongoose.Types.ObjectId(),
1011
- id_project: savedProject._id,
1012
- id_user: savedUser2._id,
1013
- role: roleConstants.USER,
1014
- user_available: true,
1015
- createdBy: savedUser2._id,
1016
- updatedBy: savedUser2._id,
698
+ chai.request(server)
699
+ .post('/' + savedProject._id + '/requests/req123-createSimpleWithFollowers/messages')
700
+ .auth(email, pwd)
701
+ .set('content-type', 'application/json')
702
+ .send({ "text": "text", "followers": [savedProjectAndPU.project_user._id.toString()] })
703
+ .end(function (err, res) {
704
+
705
+ if (err) { console.error("err", err); }
706
+ if (log) { console.log("res.body", JSON.stringify(res.body)); }
707
+
708
+ res.should.have.status(200);
709
+ res.body.should.be.a('object');
710
+ expect(res.body.sender).to.equal(savedUser._id.toString());
711
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
712
+ // expect(res.body.senderFullname).to.equal("senderFullname");
713
+ expect(res.body.recipient).to.equal("req123-createSimpleWithFollowers");
714
+ expect(res.body.text).to.equal("text");
715
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
716
+ expect(res.body.createdBy).to.equal(savedUser._id.toString());
717
+ expect(res.body.status).to.equal(0);
718
+ expect(res.body.request.request_id).to.equal("req123-createSimpleWithFollowers");
719
+ expect(res.body.request.requester._id).to.equal(savedProjectAndPU.project_user._id.toString());
720
+ // expect(res.body.request.requester_id).to.equal("sender");
721
+ expect(res.body.request.first_text).to.equal("text");
722
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
723
+ expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
724
+ // expect(res.body.request.messages_count).to.equal(1);
725
+ expect(res.body.request.status).to.equal(200);
726
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
727
+ expect(res.body.request.participants.length).to.equal(1);
728
+ expect(res.body.request.department).to.not.equal(null);
729
+ expect(res.body.request.lead).to.not.equal(null);
730
+ expect(res.body.channel_type).to.equal("group");
731
+ expect(res.body.channel.name).to.equal("chat21");
732
+ expect(res.body.request.channel.name).to.equal("chat21");
733
+ expect(res.body.request.location).to.equal(undefined);
734
+ expect(res.body.request.followers[0]).to.equal(savedProjectAndPU.project_user._id.toString());
735
+
736
+ done();
737
+ });
738
+ });
1017
739
  });
1018
- pu2.save(function (err, savedProject_user2) {
1019
-
740
+ });
1020
741
 
1021
- chai.request(server)
1022
- .post('/'+ savedProject._id + '/requests')
1023
- .auth(email, pwd)
1024
- .set('content-type', 'application/json')
1025
- .send({"first_text":"first_text"})
1026
- .end(function(err, res) {
742
+ // mocha test/messageRoute.js --grep 'createMultiTextNoSender1'
743
+ it('createMultiTextNoSender1', function (done) {
1027
744
 
1028
- console.log("res.body", res.body);
1029
- res.should.have.status(200);
1030
- res.body.should.be.a('object');
745
+ var email = "test-message-create-" + Date.now() + "@email.com";
746
+ var pwd = "pwd";
1031
747
 
1032
- res.body.should.have.property('first_text').eql('first_text');
748
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
749
+ projectService.createAndReturnProjectAndProjectUser("message-createMultiText", savedUser._id).then(function (savedProjectAndPU) {
1033
750
 
1034
- var request_id = res.body.request_id;
1035
- console.log("request_id",request_id);
751
+ var savedProject = savedProjectAndPU.project;
1036
752
 
1037
753
  chai.request(server)
1038
- .post('/'+ savedProject._id + '/requests/'+request_id+'/messages/multi')
754
+ .post('/' + savedProject._id + '/requests')
1039
755
  .auth(email, pwd)
1040
756
  .set('content-type', 'application/json')
1041
- .send([{"sender":savedUser2._id,"text":"text1"}, {"sender":savedUser2._id,"text":"text2"}])
1042
- .end(function(err, res) {
1043
- //console.log("res", res);
1044
- console.log("res.body", res.body);
1045
- res.should.have.status(200);
1046
- res.body.should.be.a('array');
1047
-
1048
- expect(res.body[0].sender).to.equal(savedUser2._id.toString());
1049
- expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
1050
- expect(res.body[0].recipient).to.equal(request_id);
1051
- expect(res.body[0].text).to.equal("text1");
1052
- expect(res.body[0].id_project).to.equal(savedProject._id.toString());
1053
- expect(res.body[0].createdBy).to.equal(savedUser2._id.toString());
1054
- expect(res.body[0].status).to.equal(0);
1055
- expect(res.body[0].channel_type).to.equal("group");
1056
- expect(res.body[0].channel.name).to.equal("chat21");
1057
-
1058
-
757
+ .send({ "first_text": "first_text" })
758
+ .end(function (err, res) {
759
+
760
+ if (log) { console.log("res.body", res.body); }
761
+ res.should.have.status(200);
762
+ res.body.should.be.a('object');
763
+ res.body.should.have.property('first_text').eql('first_text');
764
+
765
+ var request_id = res.body.request_id;
766
+ if (log) { console.log("request_id", request_id); }
1059
767
 
1060
- expect(res.body[1].sender).to.equal(savedUser2._id.toString());
1061
- expect(res.body[1].senderFullname).to.equal("Test Firstname Test lastname");
1062
- expect(res.body[1].recipient).to.equal(request_id);
1063
- expect(res.body[1].text).to.equal("text2");
1064
- expect(res.body[1].id_project).to.equal(savedProject._id.toString());
1065
- expect(res.body[1].createdBy).to.equal(savedUser2._id.toString());
1066
- expect(res.body[1].status).to.equal(0);
1067
- expect(res.body[1].channel_type).to.equal("group");
1068
- expect(res.body[1].channel.name).to.equal("chat21");
1069
-
1070
- done();
768
+ chai.request(server)
769
+ .post('/' + savedProject._id + '/requests/' + request_id + '/messages/multi')
770
+ .auth(email, pwd)
771
+ .set('content-type', 'application/json')
772
+ .send([{ "text": "text1" }, { "text": "text2" }])
773
+ .end(function (err, res) {
774
+ if (err) { console.error("err", err); }
775
+ if (log) { console.log("res.body", res.body); }
776
+ res.should.have.status(200);
777
+ res.body.should.be.a('array');
778
+
779
+ expect(res.body[0].sender).to.equal(savedUser._id.toString());
780
+ expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
781
+ expect(res.body[0].recipient).to.equal(request_id);
782
+ expect(res.body[0].text).to.equal("text1");
783
+ expect(res.body[0].id_project).to.equal(savedProject._id.toString());
784
+ expect(res.body[0].createdBy).to.equal(savedUser._id.toString());
785
+ expect(res.body[0].status).to.equal(0);
786
+ expect(res.body[0].channel_type).to.equal("group");
787
+ expect(res.body[0].channel.name).to.equal("chat21");
788
+ expect(res.body[1].sender).to.equal(savedUser._id.toString());
789
+ expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
790
+ expect(res.body[1].recipient).to.equal(request_id);
791
+ expect(res.body[1].text).to.equal("text2");
792
+ expect(res.body[1].id_project).to.equal(savedProject._id.toString());
793
+ expect(res.body[1].createdBy).to.equal(savedUser._id.toString());
794
+ expect(res.body[1].status).to.equal(0);
795
+ expect(res.body[1].channel_type).to.equal("group");
796
+ expect(res.body[1].channel.name).to.equal("chat21");
797
+
798
+ done();
799
+ });
1071
800
  });
1072
- });
1073
- });
1074
- });
1075
- });
801
+ });
802
+ });
1076
803
  });
1077
- });
1078
804
 
805
+ // mocha test/messageRoute.js --grep 'createMultiTextNoSenderNoText'
806
+ it('createMultiTextNoSenderNoText', function (done) {
1079
807
 
808
+ var email = "test-message-create-" + Date.now() + "@email.com";
809
+ var pwd = "pwd";
1080
810
 
811
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
812
+ projectService.createAndReturnProjectAndProjectUser("message-createMultiText", savedUser._id).then(function (savedProjectAndPU) {
1081
813
 
814
+ var savedProject = savedProjectAndPU.project;
1082
815
 
816
+ chai.request(server)
817
+ .post('/' + savedProject._id + '/requests')
818
+ .auth(email, pwd)
819
+ .set('content-type', 'application/json')
820
+ .send({ "first_text": "first_text" })
821
+ .end(function (err, res) {
1083
822
 
823
+ if (log) { console.log("res.body", res.body); }
824
+ res.should.have.status(200);
825
+ res.body.should.be.a('object');
826
+ res.body.should.have.property('first_text').eql('first_text');
1084
827
 
828
+ var request_id = res.body.request_id;
829
+ if (log) { console.log("request_id", request_id); }
1085
830
 
831
+ chai.request(server)
832
+ .post('/' + savedProject._id + '/requests/' + request_id + '/messages/multi')
833
+ .auth(email, pwd)
834
+ .set('content-type', 'application/json')
835
+ .send([{}, { "text": "text2" }])
836
+ .end(function (err, res) {
837
+
838
+ if (err) { console.error("err", err); }
839
+ if (log) { console.log("res.body", res.body); }
840
+
841
+ res.should.have.status(200);
842
+ done();
843
+ });
844
+ });
845
+ });
846
+ });
847
+ });
1086
848
 
1087
- // mocha test/messageRoute.js --grep 'createMultiTextWithHardcodedSender'
849
+ // mocha test/messageRoute.js --grep 'createMultiTextWithSender'
850
+ it('createMultiTextWithSender', function (done) {
1088
851
 
1089
- it('createMultiTextWithHardcodedSender', function (done) {
852
+ var email = "test-message-create-" + Date.now() + "@email.com";
853
+ var pwd = "pwd";
1090
854
 
1091
- var email = "test-message-create-" + Date.now() + "@email.com";
1092
- var pwd = "pwd";
855
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1093
856
 
1094
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
857
+ var email2 = "test-message-createwithsender22-" + Date.now() + "@email.com";
858
+ var pwd2 = "pwd";
1095
859
 
1096
-
1097
-
860
+ userService.signup(email2, pwd2, "Test Firstname22", "Test lastname22").then(function (savedUser2) {
861
+ projectService.createAndReturnProjectAndProjectUser("message-createMultiText", savedUser._id).then(function (savedProjectAndPU) {
1098
862
 
1099
- projectService.createAndReturnProjectAndProjectUser("message-createMultiTextWithHardcodedSender", savedUser._id).then(function(savedProjectAndPU) {
1100
-
1101
- var savedProject = savedProjectAndPU.project;
863
+ var savedProject = savedProjectAndPU.project;
1102
864
 
1103
- chai.request(server)
1104
- .post('/'+ savedProject._id + '/requests')
1105
- .auth(email, pwd)
1106
- .set('content-type', 'application/json')
1107
- .send({"first_text":"first_text"})
1108
- .end(function(err, res) {
865
+ var pu2 = new Project_user({
866
+ // _id: new mongoose.Types.ObjectId(),
867
+ id_project: savedProject._id,
868
+ id_user: savedUser2._id,
869
+ role: roleConstants.USER,
870
+ user_available: true,
871
+ createdBy: savedUser2._id,
872
+ updatedBy: savedUser2._id,
873
+ });
874
+ pu2.save(function (err, savedProject_user2) {
1109
875
 
1110
- console.log("res.body", res.body);
1111
- res.should.have.status(200);
1112
- res.body.should.be.a('object');
876
+ chai.request(server)
877
+ .post('/' + savedProject._id + '/requests')
878
+ .auth(email, pwd)
879
+ .set('content-type', 'application/json')
880
+ .send({ "first_text": "first_text" })
881
+ .end(function (err, res) {
1113
882
 
1114
- res.body.should.have.property('first_text').eql('first_text');
883
+ if (log) { console.log("res.body", res.body); }
884
+ res.should.have.status(200);
885
+ res.body.should.be.a('object');
1115
886
 
1116
- var request_id = res.body.request_id;
1117
- console.log("request_id",request_id);
887
+ res.body.should.have.property('first_text').eql('first_text');
1118
888
 
1119
- chai.request(server)
1120
- .post('/'+ savedProject._id + '/requests/'+request_id+'/messages/multi')
1121
- .auth(email, pwd)
1122
- .set('content-type', 'application/json')
1123
- .send([{"sender":"andrealeo","text":"text1"}, {"sender":"rocco","text":"text2"}])
1124
- .end(function(err, res) {
1125
- //console.log("res", res);
1126
- console.log("res.body", res.body);
1127
- res.should.have.status(200);
1128
- res.body.should.be.a('array');
1129
-
1130
- expect(res.body[0].sender).to.equal("andrealeo");
1131
- expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
1132
- expect(res.body[0].recipient).to.equal(request_id);
1133
- expect(res.body[0].text).to.equal("text1");
1134
- expect(res.body[0].id_project).to.equal(savedProject._id.toString());
1135
- expect(res.body[0].createdBy).to.equal("andrealeo");
1136
- expect(res.body[0].status).to.equal(0);
1137
- expect(res.body[0].channel_type).to.equal("group");
1138
- expect(res.body[0].channel.name).to.equal("chat21");
1139
-
1140
-
889
+ var request_id = res.body.request_id;
890
+ if (log) { console.log("request_id", request_id); }
891
+
892
+ chai.request(server)
893
+ .post('/' + savedProject._id + '/requests/' + request_id + '/messages/multi')
894
+ .auth(email, pwd)
895
+ .set('content-type', 'application/json')
896
+ .send([{ "sender": savedUser2._id, "text": "text1" }, { "sender": savedUser2._id, "text": "text2" }])
897
+ .end(function (err, res) {
898
+
899
+ if (err) { console.error("err", err); }
900
+ if (log) { console.log("res.body", res.body); }
901
+
902
+ res.should.have.status(200);
903
+ res.body.should.be.a('array');
904
+ expect(res.body[0].sender).to.equal(savedUser2._id.toString());
905
+ expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
906
+ expect(res.body[0].recipient).to.equal(request_id);
907
+ expect(res.body[0].text).to.equal("text1");
908
+ expect(res.body[0].id_project).to.equal(savedProject._id.toString());
909
+ expect(res.body[0].createdBy).to.equal(savedUser2._id.toString());
910
+ expect(res.body[0].status).to.equal(0);
911
+ expect(res.body[0].channel_type).to.equal("group");
912
+ expect(res.body[0].channel.name).to.equal("chat21");
913
+ expect(res.body[1].sender).to.equal(savedUser2._id.toString());
914
+ expect(res.body[1].senderFullname).to.equal("Test Firstname Test lastname");
915
+ expect(res.body[1].recipient).to.equal(request_id);
916
+ expect(res.body[1].text).to.equal("text2");
917
+ expect(res.body[1].id_project).to.equal(savedProject._id.toString());
918
+ expect(res.body[1].createdBy).to.equal(savedUser2._id.toString());
919
+ expect(res.body[1].status).to.equal(0);
920
+ expect(res.body[1].channel_type).to.equal("group");
921
+ expect(res.body[1].channel.name).to.equal("chat21");
1141
922
 
1142
- expect(res.body[1].sender).to.equal("rocco");
1143
- expect(res.body[1].senderFullname).to.equal("Test Firstname Test lastname");
1144
- expect(res.body[1].recipient).to.equal(request_id);
1145
- expect(res.body[1].text).to.equal("text2");
1146
- expect(res.body[1].id_project).to.equal(savedProject._id.toString());
1147
- expect(res.body[1].createdBy).to.equal("rocco");
1148
- expect(res.body[1].status).to.equal(0);
1149
- expect(res.body[1].channel_type).to.equal("group");
1150
- expect(res.body[1].channel.name).to.equal("chat21");
1151
-
1152
- done();
923
+ done();
924
+ });
925
+ });
1153
926
  });
927
+ });
928
+ });
1154
929
  });
1155
- });
1156
- });
1157
- });
1158
-
1159
-
930
+ });
1160
931
 
1161
932
 
933
+ // mocha test/messageRoute.js --grep 'createMultiTextWithHardcodedSender'
934
+ it('createMultiTextWithHardcodedSender', function (done) {
1162
935
 
936
+ var email = "test-message-create-" + Date.now() + "@email.com";
937
+ var pwd = "pwd";
1163
938
 
939
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
940
+ projectService.createAndReturnProjectAndProjectUser("message-createMultiTextWithHardcodedSender", savedUser._id).then(function (savedProjectAndPU) {
1164
941
 
1165
- // mocha test/messageRoute.js --grep 'createMultiTextWithHardcodedSenderAndSenderFullname'
942
+ var savedProject = savedProjectAndPU.project;
1166
943
 
1167
- it('createMultiTextWithHardcodedSenderAndSenderFullname', function (done) {
944
+ chai.request(server)
945
+ .post('/' + savedProject._id + '/requests')
946
+ .auth(email, pwd)
947
+ .set('content-type', 'application/json')
948
+ .send({ "first_text": "first_text" })
949
+ .end(function (err, res) {
1168
950
 
1169
- var email = "test-message-create-" + Date.now() + "@email.com";
1170
- var pwd = "pwd";
951
+ if (log) { console.log("res.body", res.body); }
952
+ res.should.have.status(200);
953
+ res.body.should.be.a('object');
954
+ res.body.should.have.property('first_text').eql('first_text');
1171
955
 
1172
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
956
+ var request_id = res.body.request_id;
957
+ if (log) { console.log("request_id", request_id); }
1173
958
 
1174
-
1175
-
959
+ chai.request(server)
960
+ .post('/' + savedProject._id + '/requests/' + request_id + '/messages/multi')
961
+ .auth(email, pwd)
962
+ .set('content-type', 'application/json')
963
+ .send([{ "sender": "andrealeo", "text": "text1" }, { "sender": "rocco", "text": "text2" }])
964
+ .end(function (err, res) {
965
+
966
+ if (err) { console.error("err", err); }
967
+ if (log) { console.log("res.body", res.body); }
968
+ res.should.have.status(200);
969
+ res.body.should.be.a('array');
970
+
971
+ expect(res.body[0].sender).to.equal("andrealeo");
972
+ expect(res.body[0].senderFullname).to.equal("Test Firstname Test lastname");
973
+ expect(res.body[0].recipient).to.equal(request_id);
974
+ expect(res.body[0].text).to.equal("text1");
975
+ expect(res.body[0].id_project).to.equal(savedProject._id.toString());
976
+ expect(res.body[0].createdBy).to.equal("andrealeo");
977
+ expect(res.body[0].status).to.equal(0);
978
+ expect(res.body[0].channel_type).to.equal("group");
979
+ expect(res.body[0].channel.name).to.equal("chat21");
980
+ expect(res.body[1].sender).to.equal("rocco");
981
+ expect(res.body[1].senderFullname).to.equal("Test Firstname Test lastname");
982
+ expect(res.body[1].recipient).to.equal(request_id);
983
+ expect(res.body[1].text).to.equal("text2");
984
+ expect(res.body[1].id_project).to.equal(savedProject._id.toString());
985
+ expect(res.body[1].createdBy).to.equal("rocco");
986
+ expect(res.body[1].status).to.equal(0);
987
+ expect(res.body[1].channel_type).to.equal("group");
988
+ expect(res.body[1].channel.name).to.equal("chat21");
989
+
990
+ done();
991
+ });
992
+ });
993
+ });
994
+ });
995
+ });
1176
996
 
1177
- projectService.createAndReturnProjectAndProjectUser("message-createMultiTextWithHardcodedSenderAndSenderFullname", savedUser._id).then(function(savedProjectAndPU) {
1178
-
1179
- var savedProject = savedProjectAndPU.project;
1180
997
 
1181
- chai.request(server)
1182
- .post('/'+ savedProject._id + '/requests')
1183
- .auth(email, pwd)
1184
- .set('content-type', 'application/json')
1185
- .send({"first_text":"first_text"})
1186
- .end(function(err, res) {
998
+ // mocha test/messageRoute.js --grep 'createMultiTextWithHardcodedSenderAndSenderFullname'
999
+ it('createMultiTextWithHardcodedSenderAndSenderFullname', function (done) {
1187
1000
 
1188
- console.log("res.body", res.body);
1189
- res.should.have.status(200);
1190
- res.body.should.be.a('object');
1001
+ var email = "test-message-create-" + Date.now() + "@email.com";
1002
+ var pwd = "pwd";
1191
1003
 
1192
- res.body.should.have.property('first_text').eql('first_text');
1004
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1005
+ projectService.createAndReturnProjectAndProjectUser("message-createMultiTextWithHardcodedSenderAndSenderFullname", savedUser._id).then(function (savedProjectAndPU) {
1193
1006
 
1194
- var request_id = res.body.request_id;
1195
- console.log("request_id",request_id);
1007
+ var savedProject = savedProjectAndPU.project;
1196
1008
 
1197
1009
  chai.request(server)
1198
- .post('/'+ savedProject._id + '/requests/'+request_id+'/messages/multi')
1010
+ .post('/' + savedProject._id + '/requests')
1199
1011
  .auth(email, pwd)
1200
1012
  .set('content-type', 'application/json')
1201
- .send([{"sender":"andrealeo", "senderFullname":"Andrea","text":"text1"}, {"sender":"rocco", "senderFullname":"Rocco", "text":"text2"}])
1202
- .end(function(err, res) {
1203
- //console.log("res", res);
1204
- console.log("res.body", res.body);
1205
- res.should.have.status(200);
1206
- res.body.should.be.a('array');
1207
-
1208
- expect(res.body[0].sender).to.equal("andrealeo");
1209
- expect(res.body[0].senderFullname).to.equal("Andrea");
1210
- expect(res.body[0].recipient).to.equal(request_id);
1211
- expect(res.body[0].text).to.equal("text1");
1212
- expect(res.body[0].id_project).to.equal(savedProject._id.toString());
1213
- expect(res.body[0].createdBy).to.equal("andrealeo");
1214
- expect(res.body[0].status).to.equal(0);
1215
- expect(res.body[0].channel_type).to.equal("group");
1216
- expect(res.body[0].channel.name).to.equal("chat21");
1217
-
1218
-
1219
-
1220
- expect(res.body[1].sender).to.equal("rocco");
1221
- expect(res.body[1].senderFullname).to.equal("Rocco");
1222
- expect(res.body[1].recipient).to.equal(request_id);
1223
- expect(res.body[1].text).to.equal("text2");
1224
- expect(res.body[1].id_project).to.equal(savedProject._id.toString());
1225
- expect(res.body[1].createdBy).to.equal("rocco");
1226
- expect(res.body[1].status).to.equal(0);
1227
- expect(res.body[1].channel_type).to.equal("group");
1228
- expect(res.body[1].channel.name).to.equal("chat21");
1229
-
1230
- done();
1231
- });
1232
- });
1233
- });
1234
- });
1235
- });
1236
-
1013
+ .send({ "first_text": "first_text" })
1014
+ .end(function (err, res) {
1237
1015
 
1016
+ if (log) { console.log("res.body", res.body); }
1017
+ res.should.have.status(200);
1018
+ res.body.should.be.a('object');
1238
1019
 
1020
+ res.body.should.have.property('first_text').eql('first_text');
1239
1021
 
1022
+ var request_id = res.body.request_id;
1023
+ if (log) { console.log("request_id", request_id); }
1240
1024
 
1025
+ chai.request(server)
1026
+ .post('/' + savedProject._id + '/requests/' + request_id + '/messages/multi')
1027
+ .auth(email, pwd)
1028
+ .set('content-type', 'application/json')
1029
+ .send([{ "sender": "andrealeo", "senderFullname": "Andrea", "text": "text1" }, { "sender": "rocco", "senderFullname": "Rocco", "text": "text2" }])
1030
+ .end(function (err, res) {
1031
+ if (err) { console.error("err", err); }
1032
+ if (log) { console.log("res.body", res.body); }
1033
+ res.should.have.status(200);
1034
+ res.body.should.be.a('array');
1035
+
1036
+ expect(res.body[0].sender).to.equal("andrealeo");
1037
+ expect(res.body[0].senderFullname).to.equal("Andrea");
1038
+ expect(res.body[0].recipient).to.equal(request_id);
1039
+ expect(res.body[0].text).to.equal("text1");
1040
+ expect(res.body[0].id_project).to.equal(savedProject._id.toString());
1041
+ expect(res.body[0].createdBy).to.equal("andrealeo");
1042
+ expect(res.body[0].status).to.equal(0);
1043
+ expect(res.body[0].channel_type).to.equal("group");
1044
+ expect(res.body[0].channel.name).to.equal("chat21");
1045
+ expect(res.body[1].sender).to.equal("rocco");
1046
+ expect(res.body[1].senderFullname).to.equal("Rocco");
1047
+ expect(res.body[1].recipient).to.equal(request_id);
1048
+ expect(res.body[1].text).to.equal("text2");
1049
+ expect(res.body[1].id_project).to.equal(savedProject._id.toString());
1050
+ expect(res.body[1].createdBy).to.equal("rocco");
1051
+ expect(res.body[1].status).to.equal(0);
1052
+ expect(res.body[1].channel_type).to.equal("group");
1053
+ expect(res.body[1].channel.name).to.equal("chat21");
1054
+
1055
+ done();
1056
+ });
1057
+ });
1058
+ });
1059
+ });
1060
+ });
1241
1061
 
1242
1062
 
1243
- it('getall', function (done) {
1244
- // this.timeout(10000);
1063
+ it('getall', function (done) {
1245
1064
 
1246
- var email = "test-ssa-" + Date.now() + "@email.com";
1247
- var pwd = "pwd";
1065
+ var email = "test-ssa-" + Date.now() + "@email.com";
1066
+ var pwd = "pwd";
1248
1067
 
1249
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1250
- // projectService.create("message-create", savedUser._id).then(function(savedProject) {
1251
- projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function(savedProjectAndPU) {
1068
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1069
+ // projectService.create("message-create", savedUser._id).then(function(savedProject) {
1070
+ projectService.createAndReturnProjectAndProjectUser("message-create", savedUser._id).then(function (savedProjectAndPU) {
1252
1071
  var savedProject = savedProjectAndPU.project;
1253
1072
 
1254
- leadService.createIfNotExists("leadfullname-message-getall", "andrea.leo@-subscription-message-getall.it", savedProject._id).then(function(createdLead) {
1255
- // requestService.createWithId("request_id-message-getall", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
1256
- requestService.createWithIdAndRequester("request_id-message-getall", savedProjectAndPU.project_user._id,null, savedProject._id, "first_text").then(function(savedRequest) {
1257
-
1073
+ leadService.createIfNotExists("leadfullname-message-getall", "andrea.leo@-subscription-message-getall.it", savedProject._id).then(function (createdLead) {
1074
+ // requestService.createWithId("request_id-message-getall", createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
1075
+ requestService.createWithIdAndRequester("request_id-message-getall", savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1258
1076
  messageService.create(savedUser._id, "senderFullname", savedRequest.request_id, "hello",
1259
- savedProject._id, savedUser._id).then(function(savedMessage){
1260
- expect(savedMessage.text).to.equal("hello");
1261
-
1077
+ savedProject._id, savedUser._id).then(function (savedMessage) {
1078
+ expect(savedMessage.text).to.equal("hello");
1262
1079
 
1263
-
1264
- chai.request(server)
1265
- .get('/'+ savedProject._id + '/requests/request_id-message-getall/messages')
1080
+ chai.request(server)
1081
+ .get('/' + savedProject._id + '/requests/request_id-message-getall/messages')
1266
1082
  .auth(email, pwd)
1267
1083
  .set('content-type', 'application/json')
1268
- .end(function(err, res) {
1269
- //console.log("res", res);
1270
- console.log("res.body", res.body);
1271
- res.should.have.status(200);
1272
- res.body.should.be.a('array');
1273
-
1274
- expect(res.body[0].sender).to.equal(savedUser._id.toString());
1275
- expect(res.body[0].senderFullname).to.equal("senderFullname");
1276
- expect(res.body[0].recipient).to.equal("request_id-message-getall");
1277
- expect(res.body[0].text).to.equal("hello");
1278
- expect(res.body[0].id_project).to.equal(savedProject._id.toString());
1279
- expect(res.body[0].createdBy).to.equal(savedUser._id.toString());
1280
- expect(res.body[0].status).to.equal(200);
1281
-
1282
- expect(res.body[0].channel_type).to.equal("group");
1283
- expect(res.body[0].channel.name).to.equal("chat21");
1284
-
1285
-
1286
- // expect(res.body.request.request_id).to.equal("req123");
1287
- // expect(res.body.request.requester_id).to.equal("sender");
1288
- // expect(res.body.request.first_text).to.equal("text");
1289
- // expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1290
- // expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
1291
- // expect(res.body.request.messages_count).to.equal(1);
1292
- // expect(res.body.request.status).to.equal(200);
1293
- // expect(res.body.request.agents.length).to.equal(1);
1294
- // expect(res.body.request.participants.length).to.equal(1);
1295
- // expect(res.body.request.department).to.not.equal(null);
1296
- // expect(res.body.request.lead).to.equal(null);
1297
-
1298
-
1084
+ .end(function (err, res) {
1085
+ if (err) { console.error("err", err); }
1086
+ if (log) { console.log("res.body", res.body); }
1087
+ res.should.have.status(200);
1088
+ res.body.should.be.a('array');
1089
+
1090
+ expect(res.body[0].sender).to.equal(savedUser._id.toString());
1091
+ expect(res.body[0].senderFullname).to.equal("senderFullname");
1092
+ expect(res.body[0].recipient).to.equal("request_id-message-getall");
1093
+ expect(res.body[0].text).to.equal("hello");
1094
+ expect(res.body[0].id_project).to.equal(savedProject._id.toString());
1095
+ expect(res.body[0].createdBy).to.equal(savedUser._id.toString());
1096
+ expect(res.body[0].status).to.equal(200);
1097
+ expect(res.body[0].channel_type).to.equal("group");
1098
+ expect(res.body[0].channel.name).to.equal("chat21");
1099
+ // expect(res.body.request.request_id).to.equal("req123");
1100
+ // expect(res.body.request.requester_id).to.equal("sender");
1101
+ // expect(res.body.request.first_text).to.equal("text");
1102
+ // expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1103
+ // expect(res.body.request.createdBy).to.equal(savedUser._id.toString());
1104
+ // expect(res.body.request.messages_count).to.equal(1);
1105
+ // expect(res.body.request.status).to.equal(200);
1106
+ // expect(res.body.request.agents.length).to.equal(1);
1107
+ // expect(res.body.request.participants.length).to.equal(1);
1108
+ // expect(res.body.request.department).to.not.equal(null);
1109
+ // expect(res.body.request.lead).to.equal(null);
1299
1110
  done();
1300
1111
  });
1301
-
1302
-
1303
- });
1304
- });
1112
+ });
1113
+ });
1305
1114
  });
1115
+ });
1306
1116
  });
1307
- });
1308
-
1309
-
1310
-
1311
- });
1312
1117
 
1118
+ });
1313
1119
 
1314
1120
 
1315
- describe('/SendMessageSigninWithCustomToken', () => {
1316
-
1317
- // mocha test/messageRoute.js --grep 'sendMessageSigninWithCustomTokenOk'
1121
+ describe('/SendMessageSigninWithCustomToken', () => {
1318
1122
 
1319
- it('sendMessageSigninWithCustomTokenOk', (done) => {
1123
+ // mocha test/messageRoute.js --grep 'sendMessageSigninWithCustomTokenOk'
1124
+ it('sendMessageSigninWithCustomTokenOk', (done) => {
1320
1125
 
1321
-
1322
1126
  var email = "test-sendmessagesigninwithcustomtokenok-" + Date.now() + "@email.com";
1323
1127
  var pwd = "pwd";
1324
1128
 
1325
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1326
- // create(name, createdBy, settings)
1327
- projectService.create("test-sendMessageSigninWithCustomTokenOk", savedUser._id).then(function(savedProject) {
1328
-
1329
- chai.request(server)
1330
- .post('/'+ savedProject._id + '/keys/generate')
1331
- .auth(email, pwd)
1332
- .send()
1333
- .end((err, res) => {
1334
- //console.log("res", res);
1335
- console.log("res.body", res.body);
1336
- res.should.have.status(200);
1337
- res.body.should.be.a('object');
1338
- expect(res.body.jwtSecret).to.not.equal(null);
1339
-
1340
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
1341
- var externalUserId = "123";
1342
- var externalUserObj = {_id: externalUserId, firstname:"andrea", lastname:"leo", email: "email2@email.com"};
1343
-
1344
- console.log("externalUserObj", externalUserObj);
1345
-
1346
-
1347
- var signOptions = {
1348
- subject: 'userexternal',
1349
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
1350
- };
1351
-
1129
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1130
+ // create(name, createdBy, settings)
1131
+ projectService.create("test-sendMessageSigninWithCustomTokenOk", savedUser._id).then(function (savedProject) {
1352
1132
 
1353
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
1354
-
1355
- console.log("jwtToken", jwtToken);
1133
+ chai.request(server)
1134
+ .post('/' + savedProject._id + '/keys/generate')
1135
+ .auth(email, pwd)
1136
+ .send()
1137
+ .end((err, res) => {
1138
+ if (err) { console.error("err", err); }
1139
+ if (log) { console.log("res.body", res.body); }
1140
+ res.should.have.status(200);
1141
+ res.body.should.be.a('object');
1142
+ expect(res.body.jwtSecret).to.not.equal(null);
1356
1143
 
1144
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
1145
+ var externalUserId = "123";
1146
+ var externalUserObj = { _id: externalUserId, firstname: "andrea", lastname: "leo", email: "email2@email.com" };
1147
+ if (log) { console.log("externalUserObj", externalUserObj); }
1357
1148
 
1358
- chai.request(server)
1359
- .post('/auth/signinWithCustomToken' )
1360
- .set('Authorization', 'JWT '+jwtToken)
1361
- //.send({ id_project: savedProject._id})
1362
- .send()
1363
- .end((err, res) => {
1364
- //console.log("res", res);
1365
- console.log("res.body", res.body);
1366
- res.should.have.status(200);
1367
- res.body.should.be.a('object');
1368
- expect(res.body.success).to.equal(true);
1369
- expect(res.body.user.email).to.equal("email2@email.com");
1370
- expect(res.body.user.firstname).to.equal("andrea");
1371
-
1372
- expect(res.body.token).to.not.equal(undefined);
1373
- expect(res.body.token).to.equal('JWT '+jwtToken);
1374
-
1375
-
1376
- chai.request(server)
1377
- .post('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenOk/messages')
1378
- .set('Authorization', 'JWT '+jwtToken)
1379
- .set('content-type', 'application/json')
1380
- .send({"text":"text"})
1381
- .end(function(err, res) {
1382
- //console.log("res", res);
1383
- console.log("res.body", res.body);
1384
- res.should.have.status(200);
1385
- res.body.should.be.a('object');
1386
-
1387
- expect(res.body.sender).to.equal(externalUserId);
1388
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1389
- // expect(res.body.senderFullname).to.equal("senderFullname");
1390
- expect(res.body.recipient).to.equal("sendMessageSigninWithCustomTokenOk");
1391
- expect(res.body.text).to.equal("text");
1392
- expect(res.body.id_project).to.equal(savedProject._id.toString());
1393
- expect(res.body.createdBy).to.equal(externalUserId);
1394
- expect(res.body.status).to.equal(0);
1395
-
1396
- expect(res.body.request.request_id).to.equal("sendMessageSigninWithCustomTokenOk");
1397
- expect(res.body.request.first_text).to.equal("text");
1398
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1399
- expect(res.body.request.createdBy).to.equal(externalUserId);
1400
-
1401
- // expect(res.body.request.messages_count).to.equal(1);
1402
-
1403
- expect(res.body.request.status).to.equal(200);
1404
- expect(res.body.request.snapshot.agents.length).to.equal(1);
1405
- expect(res.body.request.participants.length).to.equal(1);
1406
- expect(res.body.request.department).to.not.equal(null);
1407
- expect(res.body.request.lead).to.not.equal(null);
1408
-
1409
-
1410
- chai.request(server)
1411
- .get('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenOk')
1412
- .auth(email, pwd)
1413
- .set('content-type', 'application/json')
1414
- .end(function(err, res) {
1415
- //console.log("res", res);
1416
- console.log("res.body", res.body);
1417
- expect(res.body.lead.lead_id).to.equal(externalUserId);
1418
- expect(res.body.lead.email).to.equal("email2@email.com");
1419
- expect(res.body.lead.fullname).to.equal("andrea leo");
1420
- expect(res.body.requester.role).to.equal("user");
1421
- expect(res.body.requester.uuid_user).to.equal(externalUserId);
1422
- expect(res.body.requester.id_user).to.equal(undefined);
1423
- done()
1424
- });
1425
-
1426
- });
1427
- });
1428
- });
1429
- });
1430
- });
1431
-
1432
- });
1149
+ var signOptions = {
1150
+ subject: 'userexternal',
1151
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
1152
+ };
1433
1153
 
1154
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
1155
+ if (log) { console.log("jwtToken", jwtToken); }
1434
1156
 
1157
+ chai.request(server)
1158
+ .post('/auth/signinWithCustomToken')
1159
+ .set('Authorization', 'JWT ' + jwtToken)
1160
+ //.send({ id_project: savedProject._id})
1161
+ .send()
1162
+ .end((err, res) => {
1163
+ if (err) { console.error("err", err); }
1164
+ if (log) { console.log("res.body", res.body); }
1165
+ res.should.have.status(200);
1166
+ res.body.should.be.a('object');
1167
+ expect(res.body.success).to.equal(true);
1168
+ expect(res.body.user.email).to.equal("email2@email.com");
1169
+ expect(res.body.user.firstname).to.equal("andrea");
1435
1170
 
1171
+ expect(res.body.token).to.not.equal(undefined);
1172
+ expect(res.body.token).to.equal('JWT ' + jwtToken);
1436
1173
 
1174
+ chai.request(server)
1175
+ .post('/' + savedProject._id + '/requests/sendMessageSigninWithCustomTokenOk/messages')
1176
+ .set('Authorization', 'JWT ' + jwtToken)
1177
+ .set('content-type', 'application/json')
1178
+ .send({ "text": "text" })
1179
+ .end(function (err, res) {
1180
+ if (err) { console.error("err", err); }
1181
+ if (log) { console.log("res.body", res.body); }
1182
+ res.should.have.status(200);
1183
+ res.body.should.be.a('object');
1184
+
1185
+ expect(res.body.sender).to.equal(externalUserId);
1186
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1187
+ // expect(res.body.senderFullname).to.equal("senderFullname");
1188
+ expect(res.body.recipient).to.equal("sendMessageSigninWithCustomTokenOk");
1189
+ expect(res.body.text).to.equal("text");
1190
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
1191
+ expect(res.body.createdBy).to.equal(externalUserId);
1192
+ expect(res.body.status).to.equal(0);
1193
+ expect(res.body.request.request_id).to.equal("sendMessageSigninWithCustomTokenOk");
1194
+ expect(res.body.request.first_text).to.equal("text");
1195
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1196
+ expect(res.body.request.createdBy).to.equal(externalUserId);
1197
+ // expect(res.body.request.messages_count).to.equal(1);
1198
+ expect(res.body.request.status).to.equal(200);
1199
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
1200
+ expect(res.body.request.participants.length).to.equal(1);
1201
+ expect(res.body.request.department).to.not.equal(null);
1202
+ expect(res.body.request.lead).to.not.equal(null);
1437
1203
 
1204
+ chai.request(server)
1205
+ .get('/' + savedProject._id + '/requests/sendMessageSigninWithCustomTokenOk')
1206
+ .auth(email, pwd)
1207
+ .set('content-type', 'application/json')
1208
+ .end(function (err, res) {
1209
+
1210
+ if (err) { console.error("err", err); }
1211
+ if (log) { console.log("res.body", res.body); }
1212
+
1213
+ expect(res.body.lead.lead_id).to.equal(externalUserId);
1214
+ expect(res.body.lead.email).to.equal("email2@email.com");
1215
+ expect(res.body.lead.fullname).to.equal("andrea leo");
1216
+ expect(res.body.requester.role).to.equal("user");
1217
+ expect(res.body.requester.uuid_user).to.equal(externalUserId);
1218
+ expect(res.body.requester.id_user).to.equal(undefined);
1219
+ done()
1220
+ });
1221
+ });
1222
+ });
1223
+ });
1224
+ });
1225
+ });
1226
+ });
1438
1227
 
1439
- // mocha test/messageRoute.js --grep 'sendMessageSigninWithCustomTokenModified'
1440
1228
 
1441
- it('sendMessageSigninWithCustomTokenModified', (done) => {
1229
+ // mocha test/messageRoute.js --grep 'sendMessageSigninWithCustomTokenModified'
1230
+ it('sendMessageSigninWithCustomTokenModified', (done) => {
1442
1231
 
1443
-
1444
- var email = "test-sendmessagesigninwithcustomtokenModified-" + Date.now() + "@email.com";
1445
- var pwd = "pwd";
1232
+ var email = "test-sendmessagesigninwithcustomtokenModified-" + Date.now() + "@email.com";
1233
+ var pwd = "pwd";
1446
1234
 
1447
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1235
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1448
1236
  // create(name, createdBy, settings)
1449
- projectService.create("test-sendMessageSigninWithCustomTokenModified", savedUser._id).then(function(savedProject) {
1450
-
1451
- chai.request(server)
1452
- .post('/'+ savedProject._id + '/keys/generate')
1237
+ projectService.create("test-sendMessageSigninWithCustomTokenModified", savedUser._id).then(function (savedProject) {
1238
+
1239
+ chai.request(server)
1240
+ .post('/' + savedProject._id + '/keys/generate')
1453
1241
  .auth(email, pwd)
1454
1242
  .send()
1455
1243
  .end((err, res) => {
1456
- //console.log("res", res);
1457
- console.log("res.body", res.body);
1458
- res.should.have.status(200);
1459
- res.body.should.be.a('object');
1460
- expect(res.body.jwtSecret).to.not.equal(null);
1461
-
1462
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
1463
- var externalUserId = "123";
1464
- var externalUserObj = {_id: externalUserId, firstname:"andrea", lastname:"leo", email: "email2@email.com"};
1465
-
1466
- console.log("externalUserObj", externalUserObj);
1244
+ if (err) { console.error("err", err); }
1245
+ if (log) { console.log("res.body", res.body); }
1246
+ res.should.have.status(200);
1247
+ res.body.should.be.a('object');
1248
+ expect(res.body.jwtSecret).to.not.equal(null);
1467
1249
 
1250
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
1251
+ var externalUserId = "123";
1252
+ var externalUserObj = { _id: externalUserId, firstname: "andrea", lastname: "leo", email: "email2@email.com" };
1468
1253
 
1469
- var signOptions = {
1470
- subject: 'userexternal',
1471
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
1472
- };
1254
+ if (log) { console.log("externalUserObj", externalUserObj); }
1473
1255
 
1256
+ var signOptions = {
1257
+ subject: 'userexternal',
1258
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
1259
+ };
1474
1260
 
1475
- var secret = res.body.jwtSecret;
1476
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
1477
-
1478
- console.log("jwtToken", jwtToken);
1261
+ var secret = res.body.jwtSecret;
1262
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
1479
1263
 
1264
+ if (log) { console.log("jwtToken", jwtToken); }
1480
1265
 
1481
- chai.request(server)
1482
- .post('/auth/signinWithCustomToken' )
1483
- .set('Authorization', 'JWT '+jwtToken)
1484
- //.send({ id_project: savedProject._id})
1485
- .send()
1486
- .end((err, res) => {
1487
- //console.log("res", res);
1488
- console.log("res.body", res.body);
1489
- res.should.have.status(200);
1490
- res.body.should.be.a('object');
1491
- expect(res.body.success).to.equal(true);
1492
- expect(res.body.user.email).to.equal("email2@email.com");
1493
- expect(res.body.user.firstname).to.equal("andrea");
1494
-
1495
- expect(res.body.token).to.not.equal(undefined);
1496
- expect(res.body.token).to.equal('JWT '+jwtToken);
1497
-
1498
-
1499
- chai.request(server)
1500
- .post('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified/messages')
1501
- .set('Authorization', 'JWT '+jwtToken)
1502
- .set('content-type', 'application/json')
1503
- .send({"text":"text"})
1504
- .end(function(err, res) {
1505
- //console.log("res", res);
1506
- console.log("res.body", res.body);
1507
- res.should.have.status(200);
1508
- res.body.should.be.a('object');
1509
-
1510
- expect(res.body.sender).to.equal(externalUserId);
1511
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1512
- // expect(res.body.senderFullname).to.equal("senderFullname");
1513
- expect(res.body.recipient).to.equal("sendMessageSigninWithCustomTokenModified");
1514
- expect(res.body.text).to.equal("text");
1515
- expect(res.body.id_project).to.equal(savedProject._id.toString());
1516
- expect(res.body.createdBy).to.equal(externalUserId);
1517
- expect(res.body.status).to.equal(0);
1518
-
1519
- expect(res.body.request.request_id).to.equal("sendMessageSigninWithCustomTokenModified");
1520
- expect(res.body.request.first_text).to.equal("text");
1521
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1522
- expect(res.body.request.createdBy).to.equal(externalUserId);
1523
-
1524
- // expect(res.body.request.messages_count).to.equal(1);
1525
-
1526
- expect(res.body.request.status).to.equal(200);
1527
- expect(res.body.request.snapshot.agents.length).to.equal(1);
1528
- expect(res.body.request.participants.length).to.equal(1);
1529
- expect(res.body.request.department).to.not.equal(null);
1530
- expect(res.body.request.lead).to.not.equal(null);
1531
- expect(res.body.request.lead.email).to.equal("email2@email.com");
1266
+ chai.request(server)
1267
+ .post('/auth/signinWithCustomToken')
1268
+ .set('Authorization', 'JWT ' + jwtToken)
1269
+ //.send({ id_project: savedProject._id})
1270
+ .send()
1271
+ .end((err, res) => {
1272
+
1273
+ if (err) { console.error("err", err); }
1274
+ if (log) { console.log("res.body", res.body); }
1275
+
1276
+ res.should.have.status(200);
1277
+ res.body.should.be.a('object');
1278
+ expect(res.body.success).to.equal(true);
1279
+ expect(res.body.user.email).to.equal("email2@email.com");
1280
+ expect(res.body.user.firstname).to.equal("andrea");
1281
+ expect(res.body.token).to.not.equal(undefined);
1282
+ expect(res.body.token).to.equal('JWT ' + jwtToken);
1532
1283
 
1533
-
1534
- chai.request(server)
1535
- .get('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified')
1536
- .auth(email, pwd)
1537
- .set('content-type', 'application/json')
1538
- .end(function(err, res) {
1539
- //console.log("res", res);
1540
- console.log("res.body", res.body);
1541
- expect(res.body.lead.lead_id).to.equal(externalUserId);
1542
- expect(res.body.lead.email).to.equal("email2@email.com");
1543
- expect(res.body.lead.fullname).to.equal("andrea leo");
1544
- expect(res.body.requester.role).to.equal("user");
1545
- expect(res.body.requester.uuid_user).to.equal(externalUserId);
1546
- expect(res.body.requester.id_user).to.equal(undefined);
1547
-
1548
-
1549
-
1550
-
1551
- externalUserObj.email = "email33@email.com";
1552
-
1553
- jwtToken = jwt.sign(externalUserObj,secret, signOptions);
1554
- console.log("jwtToken2", jwtToken);
1555
-
1556
- chai.request(server)
1557
- .post('/auth/signinWithCustomToken' )
1558
- .set('Authorization', 'JWT '+jwtToken)
1559
- //.send({ id_project: savedProject._id})
1560
- .send()
1561
- .end((err, res) => {
1562
- //console.log("res", res);
1563
- console.log("res.body", res.body);
1564
- res.should.have.status(200);
1565
- res.body.should.be.a('object');
1566
- expect(res.body.success).to.equal(true);
1567
- expect(res.body.user.email).to.equal("email33@email.com");
1568
- expect(res.body.user.firstname).to.equal("andrea");
1569
-
1570
- chai.request(server)
1571
- .post('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified33/messages')
1572
- .set('Authorization', 'JWT '+jwtToken)
1573
- .set('content-type', 'application/json')
1574
- .send({"text":"text"})
1575
- .end(function(err, res) {
1576
- //console.log("res", res);
1577
- console.log("res.body", res.body);
1578
- res.should.have.status(200);
1579
- res.body.should.be.a('object');
1580
-
1581
- expect(res.body.request.lead.email).to.equal("email33@email.com");
1582
- done()
1583
-
1584
-
1585
- });
1586
-
1587
-
1588
- });
1589
-
1590
-
1591
- });
1592
-
1284
+ chai.request(server)
1285
+ .post('/' + savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified/messages')
1286
+ .set('Authorization', 'JWT ' + jwtToken)
1287
+ .set('content-type', 'application/json')
1288
+ .send({ "text": "text" })
1289
+ .end(function (err, res) {
1290
+ if (err) { console.error("err", err); }
1291
+ if (log) { console.log("res.body", res.body); }
1292
+ res.should.have.status(200);
1293
+ res.body.should.be.a('object');
1294
+
1295
+ expect(res.body.sender).to.equal(externalUserId);
1296
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1297
+ // expect(res.body.senderFullname).to.equal("senderFullname");
1298
+ expect(res.body.recipient).to.equal("sendMessageSigninWithCustomTokenModified");
1299
+ expect(res.body.text).to.equal("text");
1300
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
1301
+ expect(res.body.createdBy).to.equal(externalUserId);
1302
+ expect(res.body.status).to.equal(0);
1303
+ expect(res.body.request.request_id).to.equal("sendMessageSigninWithCustomTokenModified");
1304
+ expect(res.body.request.first_text).to.equal("text");
1305
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1306
+ expect(res.body.request.createdBy).to.equal(externalUserId);
1307
+ // expect(res.body.request.messages_count).to.equal(1);
1308
+ expect(res.body.request.status).to.equal(200);
1309
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
1310
+ expect(res.body.request.participants.length).to.equal(1);
1311
+ expect(res.body.request.department).to.not.equal(null);
1312
+ expect(res.body.request.lead).to.not.equal(null);
1313
+ expect(res.body.request.lead.email).to.equal("email2@email.com");
1314
+
1315
+ chai.request(server)
1316
+ .get('/' + savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified')
1317
+ .auth(email, pwd)
1318
+ .set('content-type', 'application/json')
1319
+ .end(function (err, res) {
1320
+ if (err) { console.error("err", err); }
1321
+ if (log) { console.log("res.body", res.body); }
1322
+ expect(res.body.lead.lead_id).to.equal(externalUserId);
1323
+ expect(res.body.lead.email).to.equal("email2@email.com");
1324
+ expect(res.body.lead.fullname).to.equal("andrea leo");
1325
+ expect(res.body.requester.role).to.equal("user");
1326
+ expect(res.body.requester.uuid_user).to.equal(externalUserId);
1327
+ expect(res.body.requester.id_user).to.equal(undefined);
1328
+
1329
+ externalUserObj.email = "email33@email.com";
1330
+
1331
+ jwtToken = jwt.sign(externalUserObj, secret, signOptions);
1332
+ if (log) { console.log("jwtToken2", jwtToken); }
1333
+
1334
+ chai.request(server)
1335
+ .post('/auth/signinWithCustomToken')
1336
+ .set('Authorization', 'JWT ' + jwtToken)
1337
+ //.send({ id_project: savedProject._id})
1338
+ .send()
1339
+ .end((err, res) => {
1340
+ if (err) { console.error("err", err); }
1341
+ if (log) { console.log("res.body", res.body); }
1342
+ res.should.have.status(200);
1343
+ res.body.should.be.a('object');
1344
+ expect(res.body.success).to.equal(true);
1345
+ expect(res.body.user.email).to.equal("email33@email.com");
1346
+ expect(res.body.user.firstname).to.equal("andrea");
1347
+
1348
+ chai.request(server)
1349
+ .post('/' + savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified33/messages')
1350
+ .set('Authorization', 'JWT ' + jwtToken)
1351
+ .set('content-type', 'application/json')
1352
+ .send({ "text": "text" })
1353
+ .end(function (err, res) {
1354
+
1355
+ if (err) { console.error("err", err); }
1356
+ if (log) { console.log("res.body", res.body); }
1357
+
1358
+ res.should.have.status(200);
1359
+ res.body.should.be.a('object');
1360
+ expect(res.body.request.lead.email).to.equal("email33@email.com");
1361
+ done()
1362
+
1363
+ });
1593
1364
  });
1365
+ });
1594
1366
  });
1595
1367
  });
1596
1368
  });
1597
1369
  });
1598
-
1599
- });
1600
-
1601
-
1602
-
1603
-
1604
- });
1605
-
1606
-
1607
-
1370
+ });
1371
+ });
1608
1372
 
1373
+ });
1609
1374
 
1610
1375
 
1376
+ // mocha test/messageRoute.js --grep 'sendMessageSigninAnonym'
1377
+ describe('/SendMessageSigninAnonym', () => {
1611
1378
 
1612
- // mocha test/messageRoute.js --grep 'sendMessageSigninAnonym'
1379
+ it('sendMessageSigninAnonym', (done) => {
1613
1380
 
1381
+ var email = "test-sendmessagesigninanonym-" + Date.now() + "@email.com";
1382
+ var pwd = "pwd";
1614
1383
 
1384
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1385
+ // create(name, createdBy, settings)
1386
+ projectService.create("test-sendMessageSigninAnonym", savedUser._id).then(function (savedProject) {
1615
1387
 
1616
- describe('/SendMessageSigninAnonym', () => {
1617
-
1388
+ chai.request(server)
1389
+ .post('/auth/signinAnonymously')
1390
+ .send({ id_project: savedProject._id })
1391
+ .end((err, res) => {
1392
+
1393
+ if (err) { console.error("err", err); }
1394
+ if (log) { console.log("res.body", res.body); }
1395
+
1396
+ res.should.have.status(200);
1397
+ res.body.should.be.a('object');
1398
+
1399
+ var userId = res.body.user._id;
1400
+ expect(res.body.success).to.equal(true);
1401
+ expect(res.body.user.email).to.equal(undefined);
1402
+ expect(res.body.user.firstname).to.contains("guest#"); // guest_here
1403
+ expect(res.body.token).to.not.equal(undefined);
1618
1404
 
1619
- it('sendMessageSigninAnonym', (done) => {
1405
+ var rid = 'support-group-' + Date.now();
1620
1406
 
1621
-
1622
- var email = "test-sendmessagesigninanonym-" + Date.now() + "@email.com";
1623
- var pwd = "pwd";
1407
+ chai.request(server)
1408
+ .post('/' + savedProject._id + '/requests/' + rid + '/messages')
1409
+ .set('Authorization', res.body.token)
1410
+ .set('content-type', 'application/json')
1411
+ .send({ "text": "text" })
1412
+ .end(function (err, res) {
1413
+ if (err) { console.error("err", err); }
1414
+ if (log) { console.log("res.body", res.body); }
1415
+ res.should.have.status(200);
1416
+ res.body.should.be.a('object');
1624
1417
 
1625
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1626
- // create(name, createdBy, settings)
1627
- projectService.create("test-sendMessageSigninAnonym", savedUser._id).then(function(savedProject) {
1628
-
1629
-
1418
+ expect(res.body.sender).to.equal(userId);
1419
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1420
+ // expect(res.body.senderFullname).to.equal("senderFullname");
1421
+ expect(res.body.recipient).to.equal(rid);
1422
+ expect(res.body.text).to.equal("text");
1423
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
1424
+ expect(res.body.createdBy).to.equal(userId);
1425
+ expect(res.body.status).to.equal(0);
1426
+ expect(res.body.request.request_id).to.equal(rid);
1427
+ expect(res.body.request.first_text).to.equal("text");
1428
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1429
+ expect(res.body.request.createdBy).to.equal(userId);
1430
+ // expect(res.body.request.messages_count).to.equal(1);
1431
+ expect(res.body.request.status).to.equal(200);
1432
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
1433
+ expect(res.body.request.participants.length).to.equal(1);
1434
+ expect(res.body.request.department).to.not.equal(null);
1435
+ expect(res.body.request.lead).to.not.equal(null);
1630
1436
 
1631
1437
  chai.request(server)
1632
- .post('/auth/signinAnonymously' )
1633
- .send({ id_project: savedProject._id})
1634
- .end((err, res) => {
1635
- //console.log("res", res);
1636
- console.log("res.body", res.body);
1637
- res.should.have.status(200);
1638
- res.body.should.be.a('object');
1639
- var userId = res.body.user._id;
1640
- expect(res.body.success).to.equal(true);
1641
- expect(res.body.user.email).to.equal(undefined);
1642
- expect(res.body.user.firstname).to.contains("guest#"); // guest_here
1643
-
1644
- expect(res.body.token).to.not.equal(undefined);
1645
-
1646
- var rid = 'support-group-'+ Date.now();
1647
-
1648
- chai.request(server)
1649
- .post('/'+ savedProject._id + '/requests/'+rid+'/messages')
1650
- .set('Authorization', res.body.token)
1651
- .set('content-type', 'application/json')
1652
- .send({"text":"text"})
1653
- .end(function(err, res) {
1654
- //console.log("res", res);
1655
- console.log("res.body", res.body);
1656
- res.should.have.status(200);
1657
- res.body.should.be.a('object');
1658
-
1659
- expect(res.body.sender).to.equal(userId);
1660
- // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1661
- // expect(res.body.senderFullname).to.equal("senderFullname");
1662
- expect(res.body.recipient).to.equal(rid);
1663
- expect(res.body.text).to.equal("text");
1664
- expect(res.body.id_project).to.equal(savedProject._id.toString());
1665
- expect(res.body.createdBy).to.equal(userId);
1666
- expect(res.body.status).to.equal(0);
1667
-
1668
- expect(res.body.request.request_id).to.equal(rid);
1669
- expect(res.body.request.first_text).to.equal("text");
1670
- expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1671
- expect(res.body.request.createdBy).to.equal(userId);
1672
-
1673
- // expect(res.body.request.messages_count).to.equal(1);
1674
-
1675
- expect(res.body.request.status).to.equal(200);
1676
- expect(res.body.request.snapshot.agents.length).to.equal(1);
1677
- expect(res.body.request.participants.length).to.equal(1);
1678
- expect(res.body.request.department).to.not.equal(null);
1679
- expect(res.body.request.lead).to.not.equal(null);
1680
-
1681
-
1682
- chai.request(server)
1683
- .get('/'+ savedProject._id + '/requests/'+rid)
1684
- .auth(email, pwd)
1685
- .set('content-type', 'application/json')
1686
- .end(function(err, res) {
1687
- //console.log("res", res);
1688
- console.log("res.body", res.body);
1689
- expect(res.body.lead.lead_id).to.equal(userId);
1690
- expect(res.body.lead.email).to.equal(undefined);
1691
- expect(res.body.lead.fullname).to.contains("guest#"); // guest_here
1692
- expect(res.body.requester.role).to.equal("guest");
1693
- expect(res.body.requester.uuid_user).to.equal(userId);
1694
- expect(res.body.requester.id_user).to.equal(undefined);
1695
- done()
1696
- });
1697
-
1698
- });
1699
- });
1700
-
1701
- });
1702
- });
1703
-
1704
- });
1438
+ .get('/' + savedProject._id + '/requests/' + rid)
1439
+ .auth(email, pwd)
1440
+ .set('content-type', 'application/json')
1441
+ .end(function (err, res) {
1442
+ if (err) { console.error("err", err); }
1443
+ if (log) { console.log("res.body", res.body); }
1444
+ expect(res.body.lead.lead_id).to.equal(userId);
1445
+ expect(res.body.lead.email).to.equal(undefined);
1446
+ expect(res.body.lead.fullname).to.contains("guest#"); // guest_here
1447
+ expect(res.body.requester.role).to.equal("guest");
1448
+ expect(res.body.requester.uuid_user).to.equal(userId);
1449
+ expect(res.body.requester.id_user).to.equal(undefined);
1450
+ done()
1451
+ });
1452
+ });
1453
+ });
1454
+ });
1455
+ });
1456
+ });
1705
1457
 
1706
- });
1458
+ });
1707
1459
 
1708
1460
  });
1709
1461