@tiledesk/tiledesk-server 2.4.100 → 2.4.101

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
3
 
4
- var chai = require("chai");
4
+ let chai = require('chai');
5
5
  chai.config.includeStack = true;
6
6
 
7
7
  var expect = chai.expect;
8
- var assert = require('chai').assert;
8
+ var assert = chai.assert;
9
+ let should = chai.should();
9
10
  var config = require('../config/database');
10
11
  var mongoose = require('mongoose');
11
12
  var winston = require('../config/winston');
@@ -22,6 +23,7 @@ require('../services/mongoose-cache-fn')(mongoose);
22
23
  var requestService = require('../services/requestService');
23
24
  var messageService = require('../services/messageService');
24
25
  var projectService = require('../services/projectService');
26
+ var projectUserService = require('../services/projectUserService');
25
27
  var departmentService = require('../services/departmentService');
26
28
  var leadService = require('../services/leadService');
27
29
  var userService = require('../services/userService');
@@ -32,89 +34,198 @@ var Project_user = require("../models/project_user");
32
34
  // var Tag = require('../models/tag');
33
35
  var requestEvent = require('../event/requestEvent');
34
36
 
37
+ var { QuoteManager } = require('../services/QuoteManager');
38
+ const projectMock = require('./mock/projectMock');
39
+
40
+ // CONNECT REDIS - CHECK IT
41
+ const { TdCache } = require('../utils/TdCache');
42
+ let tdCache = new TdCache({
43
+ host: '127.0.0.1',
44
+ port: '6379'
45
+ });
46
+
47
+ tdCache.connect();
48
+
49
+ // var redis = require('redis')
50
+ // var redis_client;
51
+
52
+ // connectRedis();
53
+
54
+ // function connectRedis() {
55
+ // console.log(">>> connectRedis for test")
56
+ // redis_client = redis.createClient({
57
+ // host: "127.0.0.1",
58
+ // port: 6379,
59
+ // });
60
+
61
+ // redis_client.on('error', err => {
62
+ // winston.info('(wab) Connect Redis Error ' + err);
63
+ // })
64
+
65
+ // redis_client.on('ready', () => {
66
+ // winston.info("(wab) Redis ready!")
67
+ // })
68
+
69
+ // }
70
+
35
71
  describe('RequestService', function () {
36
72
 
37
73
  // var userid = "5badfe5d553d1844ad654072";
38
74
 
39
75
  // mocha test/requestService.js --grep 'createObjSimple'
40
-
41
- it('createObjSimple', function (done) {
76
+ it('createObjSimpleQuote', function (done) {
42
77
  // this.timeout(10000);
43
78
  var email = "test-request-create-" + Date.now() + "@email.com";
44
79
  var pwd = "pwd";
45
80
 
46
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
81
+
82
+ let qm = new QuoteManager({ tdCache: tdCache });
83
+ qm.start();
84
+
85
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
47
86
  var userid = savedUser.id;
48
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
49
- var savedProject = savedProjectAndPU.project;
87
+ projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser.id).then(function (savedProjectAndPU) {
88
+ var savedProject = savedProjectAndPU.project;
50
89
 
51
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
52
- var now = Date.now();
53
- var request = {
54
- request_id:"request_id-createObjSimple-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
55
- id_project:savedProject._id, first_text: "first_text",
56
- lead:createdLead, requester: savedProjectAndPU.project_user };
57
-
58
- requestService.create(request).then(function(savedRequest) {
59
- winston.info("resolve", savedRequest.toObject());
60
- expect(savedRequest.request_id).to.equal("request_id-createObjSimple-"+now);
61
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
62
- expect(savedRequest.first_text).to.equal("first_text");
63
- expect(savedRequest.department).to.not.equal(null);
64
- expect(savedRequest.ticket_id).to.equal(1);
65
- expect(savedRequest.status).to.equal(200);
66
- expect(savedRequest.participants).to.have.lengthOf(1);
67
- expect(savedRequest.participants).to.contains(userid);
68
- expect(savedRequest.participantsAgents).to.contains(userid);
69
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
70
- expect(savedRequest.hasBot).to.equal(false);
71
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
72
- expect(savedRequest.participants[0].toString()).to.equal(userid);
73
- expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
74
- expect(savedRequest.assigned_at).to.not.equal(null);
75
- console.log("savedRequest.participants1");
90
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
91
+ var now = Date.now();
92
+ var request = {
93
+ request_id: "request_id-createObjSimple-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
94
+ id_project: savedProject._id, first_text: "first_text",
95
+ lead: createdLead, requester: savedProjectAndPU.project_user
96
+ };
97
+
98
+ requestService.create(request).then(async function (savedRequest) {
99
+ winston.verbose("resolve", savedRequest.toObject());
100
+ expect(savedRequest.request_id).to.equal("request_id-createObjSimple-" + now);
101
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
102
+ expect(savedRequest.first_text).to.equal("first_text");
103
+ expect(savedRequest.department).to.not.equal(null);
104
+ expect(savedRequest.ticket_id).to.equal(1);
105
+ expect(savedRequest.status).to.equal(200);
106
+ expect(savedRequest.participants).to.have.lengthOf(1);
107
+ expect(savedRequest.participants).to.contains(userid);
108
+ expect(savedRequest.participantsAgents).to.contains(userid);
109
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
110
+ expect(savedRequest.hasBot).to.equal(false);
111
+
112
+ expect(savedRequest.participants[0].toString()).to.equal(userid);
113
+ expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
114
+ expect(savedRequest.assigned_at).to.not.equal(null);
115
+
116
+ expect(savedRequest.snapshot.department.name).to.not.equal(null);
117
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
118
+ expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
119
+ expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
120
+ expect(savedRequest.snapshot.requester.role).to.equal("owner");
121
+ expect(savedRequest.snapshot.requester.isAuthenticated).to.equal(true);
122
+ expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
123
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
124
+
125
+
126
+ setTimeout(async () => {
127
+ let obj = { createdAt: new Date() }
128
+
129
+ let quotes = await qm.getAllQuotes(savedProject, obj);
130
+ console.log("quotes: ", quotes);
131
+ quotes.requests.quote.should.be.a('string');
132
+ expect(quotes.requests.quote).to.equal('1');
133
+
134
+ done();
135
+ }, 200);
76
136
 
77
- expect(savedRequest.snapshot.department.name).to.not.equal(null);
78
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
79
- expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
80
- expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
81
- expect(savedRequest.snapshot.requester.role).to.equal("owner");
82
- expect(savedRequest.snapshot.requester.isAuthenticated).to.equal(true);
83
- // expect(savedRequest.snapshot.requester.role).to.equal("owner");
84
- console.log("savedRequest.participants2");
85
137
 
86
- expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
138
+ }).catch(function (err) {
139
+ console.log("test reject", err);
140
+ assert.isNotOk(err, 'Promise error');
141
+ // done();
142
+ });
143
+ });
144
+ });
145
+ });
146
+ }).timeout(10000);
147
+
148
+ it('createObjSimple', function (done) {
149
+ // this.timeout(10000);
150
+ var email = "test-request-create-" + Date.now() + "@email.com";
151
+ var pwd = "pwd";
152
+
87
153
 
88
- // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
89
- // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
154
+ let qm = new QuoteManager({ tdCache: tdCache });
155
+ qm.start();
90
156
 
91
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
92
- console.log("savedRequest.participants3");
93
- // aiuto
94
- // expect(savedRequest.department).to.equal("requester_id1");
157
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
158
+ var userid = savedUser.id;
159
+ projectService.createAndReturnProjectAndProjectUser("createWithId", savedUser.id).then(function (savedProjectAndPU) {
160
+ var savedProject = savedProjectAndPU.project;
95
161
 
96
- requestService.create(request).then(function(savedRequest) {
97
- // assert.isNotOk('No duplicate check index');
98
- console.log("no index check ???");
162
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
163
+ var now = Date.now();
164
+ var request = {
165
+ request_id: "request_id-createObjSimple-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
166
+ id_project: savedProject._id, first_text: "first_text",
167
+ lead: createdLead, requester: savedProjectAndPU.project_user
168
+ };
169
+
170
+ requestService.create(request).then(function (savedRequest) {
171
+ winston.verbose("resolve", savedRequest.toObject());
172
+ expect(savedRequest.request_id).to.equal("request_id-createObjSimple-" + now);
173
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
174
+ expect(savedRequest.first_text).to.equal("first_text");
175
+ expect(savedRequest.department).to.not.equal(null);
176
+ expect(savedRequest.ticket_id).to.equal(1);
177
+ expect(savedRequest.status).to.equal(200);
178
+ expect(savedRequest.participants).to.have.lengthOf(1);
179
+ expect(savedRequest.participants).to.contains(userid);
180
+ expect(savedRequest.participantsAgents).to.contains(userid);
181
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
182
+ expect(savedRequest.hasBot).to.equal(false);
183
+ console.log("savedRequest.participants[0]", savedRequest.participants[0]);
184
+ expect(savedRequest.participants[0].toString()).to.equal(userid);
185
+ expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
186
+ expect(savedRequest.assigned_at).to.not.equal(null);
187
+ console.log("savedRequest.participants1");
188
+
189
+ expect(savedRequest.snapshot.department.name).to.not.equal(null);
190
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
191
+ expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
192
+ expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
193
+ expect(savedRequest.snapshot.requester.role).to.equal("owner");
194
+ expect(savedRequest.snapshot.requester.isAuthenticated).to.equal(true);
195
+ // expect(savedRequest.snapshot.requester.role).to.equal("owner");
196
+ console.log("savedRequest.participants2");
197
+
198
+ expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
199
+
200
+ // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
201
+ // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
202
+
203
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
204
+ console.log("savedRequest.participants3");
205
+ // aiuto
206
+ // expect(savedRequest.department).to.equal("requester_id1");
207
+
208
+ requestService.create(request).then(function (savedRequest) {
209
+ // assert.isNotOk('No duplicate check index');
210
+ console.log("no index check ???");
211
+ // done();
212
+ }).catch(function (err) {
213
+ console.log("ok duplicate check index ", err);
214
+ done();
215
+ });
216
+ }).catch(function (err) {
217
+ console.log("test reject", err);
218
+ assert.isNotOk(err, 'Promise error');
99
219
  // done();
100
- }).catch(function(err) {
101
- console.log("ok duplicate check index ", err);
102
- done();
103
220
  });
104
- }).catch(function(err) {
105
- console.log("test reject",err);
106
- assert.isNotOk(err,'Promise error');
107
- // done();
108
221
  });
109
- });
110
- });
222
+ });
111
223
  });
112
224
  });
113
225
 
114
226
 
115
227
 
116
228
 
117
-
118
229
  // mocha test/requestService.js --grep 'createObjSimpleUpdateLeadUpdateSnapshot'
119
230
 
120
231
  it('createObjSimpleUpdateLeadUpdateSnapshot', function (done) {
@@ -122,82 +233,83 @@ describe('RequestService', function () {
122
233
  var email = "test-request-create-" + Date.now() + "@email.com";
123
234
  var pwd = "pwd";
124
235
 
125
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
236
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
126
237
  var userid = savedUser.id;
127
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
128
- var savedProject = savedProjectAndPU.project;
129
-
130
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
131
- var now = Date.now();
132
- var request = {
133
- request_id:"request_idcreateObjSimpleUpdateLeadUpdateSnapshot-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
134
- id_project:savedProject._id, first_text: "first_text",
135
- lead:createdLead, requester: savedProjectAndPU.project_user };
136
-
137
- requestService.create(request).then(function(savedRequest) {
138
- winston.info("resolve", savedRequest.toObject());
139
- expect(savedRequest.request_id).to.equal("request_idcreateObjSimpleUpdateLeadUpdateSnapshot-"+now);
140
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
141
- expect(savedRequest.first_text).to.equal("first_text");
142
- expect(savedRequest.department).to.not.equal(null);
143
- expect(savedRequest.status).to.equal(200);
144
- expect(savedRequest.participants).to.have.lengthOf(1);
145
- expect(savedRequest.participants).to.contains(userid);
146
- expect(savedRequest.participantsAgents).to.contains(userid);
147
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
148
- expect(savedRequest.hasBot).to.equal(false);
149
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
150
- expect(savedRequest.participants[0].toString()).to.equal(userid);
151
- expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
152
- expect(savedRequest.assigned_at).to.not.equal(null);
153
-
154
- expect(savedRequest.snapshot.department.name).to.not.equal(null);
155
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
156
- expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
157
- expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
158
- expect(savedRequest.snapshot.requester.role).to.equal("owner");
159
- expect(savedRequest.snapshot.requester.isAuthenticated).to.equal(true);
160
- // expect(savedRequest.snapshot.requester.role).to.equal("owner");
161
-
162
- expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
163
-
164
- // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
165
- // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
238
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
239
+ var savedProject = savedProjectAndPU.project;
166
240
 
167
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
168
-
241
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
242
+ var now = Date.now();
243
+ var request = {
244
+ request_id: "request_idcreateObjSimpleUpdateLeadUpdateSnapshot-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
245
+ id_project: savedProject._id, first_text: "first_text",
246
+ lead: createdLead, requester: savedProjectAndPU.project_user
247
+ };
248
+
249
+ requestService.create(request).then(function (savedRequest) {
250
+ winston.info("resolve", savedRequest.toObject());
251
+ expect(savedRequest.request_id).to.equal("request_idcreateObjSimpleUpdateLeadUpdateSnapshot-" + now);
252
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
253
+ expect(savedRequest.first_text).to.equal("first_text");
254
+ expect(savedRequest.department).to.not.equal(null);
255
+ expect(savedRequest.status).to.equal(200);
256
+ expect(savedRequest.participants).to.have.lengthOf(1);
257
+ expect(savedRequest.participants).to.contains(userid);
258
+ expect(savedRequest.participantsAgents).to.contains(userid);
259
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
260
+ expect(savedRequest.hasBot).to.equal(false);
261
+ console.log("savedRequest.participants[0]", savedRequest.participants[0]);
262
+ expect(savedRequest.participants[0].toString()).to.equal(userid);
263
+ expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
264
+ expect(savedRequest.assigned_at).to.not.equal(null);
265
+
266
+ expect(savedRequest.snapshot.department.name).to.not.equal(null);
267
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
268
+ expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
269
+ expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
270
+ expect(savedRequest.snapshot.requester.role).to.equal("owner");
271
+ expect(savedRequest.snapshot.requester.isAuthenticated).to.equal(true);
272
+ // expect(savedRequest.snapshot.requester.role).to.equal("owner");
273
+
274
+ expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
275
+
276
+ // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
277
+ // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
278
+
279
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
280
+
281
+
282
+ leadService.updateWitId(createdLead.lead_id, "fullname2", "email2@email2.com", savedProject._id).then(function (updatedLead) {
283
+
284
+ expect(updatedLead.fullname).to.equal("fullname2");
285
+ expect(updatedLead.email).to.equal("email2@email2.com");
286
+ expect(updatedLead.id_project).to.equal(savedProject._id.toString());
287
+ expect(updatedLead.lead_id).to.not.equal(createdLead.id);
288
+ console.log("updatedLead", updatedLead);
289
+
290
+ requestEvent.on('request.update.snapshot.lead', function (data) {
291
+
292
+ Request.findById(savedRequest._id, function (err, request) {
293
+ console.log("err", err);
294
+ expect(request.request_id).to.equal("request_idcreateObjSimpleUpdateLeadUpdateSnapshot-" + now);
295
+ expect(request.snapshot.lead.fullname).to.equal("fullname2");
296
+ done();
297
+ });
169
298
 
170
- leadService.updateWitId(createdLead.lead_id, "fullname2", "email2@email2.com", savedProject._id).then(function(updatedLead) {
299
+ });
171
300
 
172
- expect(updatedLead.fullname).to.equal("fullname2");
173
- expect(updatedLead.email).to.equal("email2@email2.com");
174
- expect(updatedLead.id_project).to.equal(savedProject._id.toString());
175
- expect(updatedLead.lead_id).to.not.equal(createdLead.id);
176
- console.log("updatedLead",updatedLead);
177
301
 
178
- requestEvent.on('request.update.snapshot.lead', function(data) {
179
302
 
180
- Request.findById(savedRequest._id, function(err, request) {
181
- console.log("err",err);
182
- expect(request.request_id).to.equal("request_idcreateObjSimpleUpdateLeadUpdateSnapshot-"+now);
183
- expect(request.snapshot.lead.fullname).to.equal("fullname2");
184
- done();
185
303
  });
186
304
 
187
- });
188
-
189
-
190
305
 
191
- });
192
-
193
-
194
- }).catch(function(err) {
195
- console.log("test reject",err);
196
- assert.isNotOk(err,'Promise error');
306
+ }).catch(function (err) {
307
+ console.log("test reject", err);
308
+ assert.isNotOk(err, 'Promise error');
197
309
  done();
310
+ });
198
311
  });
199
- });
200
- });
312
+ });
201
313
  });
202
314
  });
203
315
 
@@ -205,136 +317,138 @@ describe('RequestService', function () {
205
317
 
206
318
 
207
319
 
208
- // mocha test/requestService.js --grep 'createObjParticipantsAgent'
320
+ // mocha test/requestService.js --grep 'createObjParticipantsAgent'
209
321
 
210
- it('createObjParticipantsAgent', function (done) {
322
+ it('createObjParticipantsAgent', function (done) {
211
323
  // this.timeout(10000);
212
324
  var email = "test-request-create-" + Date.now() + "@email.com";
213
325
  var pwd = "pwd";
214
326
 
215
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
327
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
216
328
  var userid = savedUser.id;
217
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
218
- var savedProject = savedProjectAndPU.project;
219
-
220
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
221
- var now = Date.now();
222
- var request = {
223
- request_id:"request_id-createObjParticipantsAgent-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
224
- id_project:savedProject._id, first_text: "first_text",
225
- lead:createdLead, requester: savedProjectAndPU.project_user,
226
- participants: [userid.toString()] };
227
-
228
- requestService.create(request).then(function(savedRequest) {
229
- winston.debug("resolve", savedRequest.toObject());
230
- expect(savedRequest.request_id).to.equal("request_id-createObjParticipantsAgent-"+now);
231
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
232
- expect(savedRequest.first_text).to.equal("first_text");
233
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
234
- expect(savedRequest.department).to.equal(undefined);
235
- expect(savedRequest.status).to.equal(200);
236
- expect(savedRequest.participants).to.have.lengthOf(1);
237
- expect(savedRequest.participants).to.contains(userid);
238
- expect(savedRequest.participantsAgents).to.contains(userid);
239
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
240
- expect(savedRequest.hasBot).to.equal(false);
241
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
242
- expect(savedRequest.participants[0].toString()).to.equal(userid);
243
- expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
244
- expect(savedRequest.assigned_at).to.not.equal(null);
245
-
246
- expect(savedRequest.snapshot.department).to.equal(undefined);
247
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
248
- expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
249
- expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
250
- expect(savedRequest.snapshot.requester.role).to.equal("owner");
251
- // expect(savedRequest.snapshot.requester.role).to.equal("owner");
252
-
253
- expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
254
-
255
- // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
256
- // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
257
-
258
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
329
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
330
+ var savedProject = savedProjectAndPU.project;
259
331
 
260
- // aiuto
261
- // expect(savedRequest.department).to.equal("requester_id1");
262
- done();
263
- }).catch(function(err) {
264
- console.log("test reject",err);
265
- assert.isNotOk(err,'Promise error');
332
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
333
+ var now = Date.now();
334
+ var request = {
335
+ request_id: "request_id-createObjParticipantsAgent-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
336
+ id_project: savedProject._id, first_text: "first_text",
337
+ lead: createdLead, requester: savedProjectAndPU.project_user,
338
+ participants: [userid.toString()]
339
+ };
340
+
341
+ requestService.create(request).then(function (savedRequest) {
342
+ winston.debug("resolve", savedRequest.toObject());
343
+ expect(savedRequest.request_id).to.equal("request_id-createObjParticipantsAgent-" + now);
344
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
345
+ expect(savedRequest.first_text).to.equal("first_text");
346
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
347
+ expect(savedRequest.department).to.equal(undefined);
348
+ expect(savedRequest.status).to.equal(200);
349
+ expect(savedRequest.participants).to.have.lengthOf(1);
350
+ expect(savedRequest.participants).to.contains(userid);
351
+ expect(savedRequest.participantsAgents).to.contains(userid);
352
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
353
+ expect(savedRequest.hasBot).to.equal(false);
354
+ console.log("savedRequest.participants[0]", savedRequest.participants[0]);
355
+ expect(savedRequest.participants[0].toString()).to.equal(userid);
356
+ expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
357
+ expect(savedRequest.assigned_at).to.not.equal(null);
358
+
359
+ expect(savedRequest.snapshot.department).to.equal(undefined);
360
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
361
+ expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
362
+ expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
363
+ expect(savedRequest.snapshot.requester.role).to.equal("owner");
364
+ // expect(savedRequest.snapshot.requester.role).to.equal("owner");
365
+
366
+ expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
367
+
368
+ // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
369
+ // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
370
+
371
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
372
+
373
+ // aiuto
374
+ // expect(savedRequest.department).to.equal("requester_id1");
266
375
  done();
376
+ }).catch(function (err) {
377
+ console.log("test reject", err);
378
+ assert.isNotOk(err, 'Promise error');
379
+ done();
380
+ });
267
381
  });
268
- });
269
- });
382
+ });
270
383
  });
271
384
  });
272
385
 
273
386
 
274
387
 
275
388
 
276
-
277
389
 
278
390
 
279
- // mocha test/requestService.js --grep 'createObjTemp'
280
391
 
281
- it('createObjTemp', function (done) {
392
+ // mocha test/requestService.js --grep 'createObjTemp'
393
+
394
+ it('createObjTemp', function (done) {
282
395
  // this.timeout(10000);
283
396
  var email = "test-request-create-" + Date.now() + "@email.com";
284
397
  var pwd = "pwd";
285
398
 
286
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
399
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
287
400
  var userid = savedUser.id;
288
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
289
- var savedProject = savedProjectAndPU.project;
290
-
291
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
292
- var now = Date.now();
293
- var request = {
294
- request_id:"request_id-createObjTemp-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
295
- id_project:savedProject._id, first_text: "first_text",
296
- lead:createdLead, requester: savedProjectAndPU.project_user,
297
- status:50 };
298
-
299
- requestService.create(request).then(function(savedRequest) {
300
- winston.debug("resolve", savedRequest.toObject());
301
- expect(savedRequest.request_id).to.equal("request_id-createObjTemp-"+now);
302
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
303
- expect(savedRequest.first_text).to.equal("first_text");
304
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
305
- expect(savedRequest.department).to.not.equal(undefined);
306
- expect(savedRequest.status).to.equal(50);
307
- expect(savedRequest.participants).to.have.lengthOf(0);
308
- expect(savedRequest.participantsAgents).to.have.lengthOf(0);
309
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
310
- expect(savedRequest.hasBot).to.equal(false);
311
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
312
- expect(savedRequest.assigned_at).to.equal(undefined);
313
-
314
- expect(savedRequest.snapshot.department.name).to.not.equal(null);
315
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
316
- expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
317
- expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
318
- expect(savedRequest.snapshot.requester.role).to.equal("owner");
319
- // expect(savedRequest.snapshot.requester.role).to.equal("owner");
320
-
321
- expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
322
-
323
- // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
324
- // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
325
-
326
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
401
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
402
+ var savedProject = savedProjectAndPU.project;
327
403
 
328
- // aiuto
329
- // expect(savedRequest.department).to.equal("requester_id1");
330
- done();
331
- }).catch(function(err) {
332
- console.log("test reject",err);
333
- assert.isNotOk(err,'Promise error');
404
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
405
+ var now = Date.now();
406
+ var request = {
407
+ request_id: "request_id-createObjTemp-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
408
+ id_project: savedProject._id, first_text: "first_text",
409
+ lead: createdLead, requester: savedProjectAndPU.project_user,
410
+ status: 50
411
+ };
412
+
413
+ requestService.create(request).then(function (savedRequest) {
414
+ winston.debug("resolve", savedRequest.toObject());
415
+ expect(savedRequest.request_id).to.equal("request_id-createObjTemp-" + now);
416
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
417
+ expect(savedRequest.first_text).to.equal("first_text");
418
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
419
+ expect(savedRequest.department).to.not.equal(undefined);
420
+ expect(savedRequest.status).to.equal(50);
421
+ expect(savedRequest.participants).to.have.lengthOf(0);
422
+ expect(savedRequest.participantsAgents).to.have.lengthOf(0);
423
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
424
+ expect(savedRequest.hasBot).to.equal(false);
425
+ console.log("savedRequest.participants[0]", savedRequest.participants[0]);
426
+ expect(savedRequest.assigned_at).to.equal(undefined);
427
+
428
+ expect(savedRequest.snapshot.department.name).to.not.equal(null);
429
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
430
+ expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
431
+ expect(savedRequest.snapshot.lead.fullname).to.equal("leadfullname");
432
+ expect(savedRequest.snapshot.requester.role).to.equal("owner");
433
+ // expect(savedRequest.snapshot.requester.role).to.equal("owner");
434
+
435
+ expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
436
+
437
+ // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
438
+ // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
439
+
440
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
441
+
442
+ // aiuto
443
+ // expect(savedRequest.department).to.equal("requester_id1");
334
444
  done();
445
+ }).catch(function (err) {
446
+ console.log("test reject", err);
447
+ assert.isNotOk(err, 'Promise error');
448
+ done();
449
+ });
335
450
  });
336
- });
337
- });
451
+ });
338
452
  });
339
453
  });
340
454
 
@@ -343,50 +457,50 @@ describe('RequestService', function () {
343
457
  var email = "test-request-create-" + Date.now() + "@email.com";
344
458
  var pwd = "pwd";
345
459
 
346
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
460
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
347
461
  var userid = savedUser.id;
348
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
349
- var savedProject = savedProjectAndPU.project;
350
-
351
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
352
- var now = Date.now();
353
- requestService.createWithIdAndRequester("request_id-createWithIdAndCreateNewLead-"+now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
354
- winston.debug("resolve", savedRequest.toObject());
355
- expect(savedRequest.request_id).to.equal("request_id-createWithIdAndCreateNewLead-"+now);
356
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
357
- expect(savedRequest.first_text).to.equal("first_text");
358
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
359
- expect(savedRequest.status).to.equal(200);
360
- expect(savedRequest.participants).to.have.lengthOf(1);
361
- expect(savedRequest.participants).to.contains(userid);
362
- expect(savedRequest.participantsAgents).to.contains(userid);
363
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
364
- expect(savedRequest.hasBot).to.equal(false);
365
- console.log("savedRequest.participants[0]", savedRequest.participants[0]);
366
- expect(savedRequest.participants[0].toString()).to.equal(userid);
367
- expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
368
- expect(savedRequest.assigned_at).to.not.equal(null);
369
-
370
- expect(savedRequest.snapshot.department.name).to.not.equal(null);
371
- expect(savedRequest.snapshot.agents).to.not.equal(null);
372
- expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
373
- expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
374
-
375
- // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
376
- // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
377
-
378
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
462
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
463
+ var savedProject = savedProjectAndPU.project;
379
464
 
380
- // aiuto
381
- // expect(savedRequest.department).to.equal("requester_id1");
382
- done();
383
- }).catch(function(err) {
384
- console.log("test reject",err);
385
- assert.isNotOk(err,'Promise error');
465
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
466
+ var now = Date.now();
467
+ requestService.createWithIdAndRequester("request_id-createWithIdAndCreateNewLead-" + now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function (savedRequest) {
468
+ winston.debug("resolve", savedRequest.toObject());
469
+ expect(savedRequest.request_id).to.equal("request_id-createWithIdAndCreateNewLead-" + now);
470
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
471
+ expect(savedRequest.first_text).to.equal("first_text");
472
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
473
+ expect(savedRequest.status).to.equal(200);
474
+ expect(savedRequest.participants).to.have.lengthOf(1);
475
+ expect(savedRequest.participants).to.contains(userid);
476
+ expect(savedRequest.participantsAgents).to.contains(userid);
477
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
478
+ expect(savedRequest.hasBot).to.equal(false);
479
+ console.log("savedRequest.participants[0]", savedRequest.participants[0]);
480
+ expect(savedRequest.participants[0].toString()).to.equal(userid);
481
+ expect(savedRequest.participantsAgents[0].toString()).to.equal(userid);
482
+ expect(savedRequest.assigned_at).to.not.equal(null);
483
+
484
+ expect(savedRequest.snapshot.department.name).to.not.equal(null);
485
+ expect(savedRequest.snapshot.agents).to.not.equal(null);
486
+ expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
487
+ expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
488
+
489
+ // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
490
+ // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
491
+
492
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
493
+
494
+ // aiuto
495
+ // expect(savedRequest.department).to.equal("requester_id1");
496
+ done();
497
+ }).catch(function (err) {
498
+ console.log("test reject", err);
499
+ assert.isNotOk(err, 'Promise error');
386
500
  done();
501
+ });
387
502
  });
388
- });
389
- });
503
+ });
390
504
  });
391
505
  });
392
506
 
@@ -400,23 +514,23 @@ describe('RequestService', function () {
400
514
  var email = "test-request-create-" + Date.now() + "@email.com";
401
515
  var pwd = "pwd";
402
516
 
403
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
517
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
404
518
  var userid = savedUser.id;
405
519
 
406
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
407
- var savedProject = savedProjectAndPU.project;
408
- var now = Date.now();
409
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
520
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
521
+ var savedProject = savedProjectAndPU.project;
522
+ var now = Date.now();
523
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
524
+
525
+ requestEvent.on('request.create', function (savedRequest) {
410
526
 
411
- requestEvent.on('request.create', function(savedRequest) {
527
+ if (savedRequest.request_id === "createWithIdAndCreateNewLeadAndCheckRequestEvent-" + now) {
412
528
 
413
- if (savedRequest.request_id === "createWithIdAndCreateNewLeadAndCheckRequestEvent-"+now ) {
414
529
 
415
-
416
- console.log("savedRequest",savedRequest.toJSON());
530
+ console.log("savedRequest", savedRequest.toJSON());
417
531
 
418
532
  winston.debug("resolve", savedRequest.toObject());
419
- expect(savedRequest.request_id).to.equal("createWithIdAndCreateNewLeadAndCheckRequestEvent-"+now);
533
+ expect(savedRequest.request_id).to.equal("createWithIdAndCreateNewLeadAndCheckRequestEvent-" + now);
420
534
  expect(savedRequest.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
421
535
  expect(savedRequest.first_text).to.equal("first_text");
422
536
  expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
@@ -428,13 +542,13 @@ describe('RequestService', function () {
428
542
  expect(savedRequest.hasBot).to.equal(false);
429
543
  console.log("savedRequest.participants[0]", savedRequest.participants[0]);
430
544
  expect(savedRequest.participants[0].toString()).to.equal(userid);
431
-
545
+
432
546
  expect(savedRequest.createdBy).to.equal(savedProjectAndPU.project_user._id.toString());
433
547
 
434
- expect(savedRequest.participatingAgents.length).to.equal(1);
548
+ expect(savedRequest.participatingAgents.length).to.equal(1);
435
549
  expect(savedRequest.participatingBots.length).to.equal(0);
436
550
  expect(savedRequest.snapshot.availableAgentsCount).to.equal(1);
437
-
551
+
438
552
  // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
439
553
  // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
440
554
 
@@ -443,19 +557,19 @@ describe('RequestService', function () {
443
557
  // aiuto
444
558
  // expect(savedRequest.department).to.equal("requester_id1");
445
559
  done();
446
- }
560
+ }
447
561
 
448
- });
449
- requestService.createWithIdAndRequester("createWithIdAndCreateNewLeadAndCheckRequestEvent-"+now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
450
-
451
- }).catch(function(err) {
452
- console.log("test reject",err);
453
- assert.isNotOk(err,'Promise error');
562
+ });
563
+ requestService.createWithIdAndRequester("createWithIdAndCreateNewLeadAndCheckRequestEvent-" + now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function (savedRequest) {
564
+
565
+ }).catch(function (err) {
566
+ console.log("test reject", err);
567
+ assert.isNotOk(err, 'Promise error');
454
568
  done();
569
+ });
455
570
  });
571
+ });
456
572
  });
457
- });
458
- });
459
573
 
460
574
  });
461
575
 
@@ -509,15 +623,15 @@ describe('RequestService', function () {
509
623
  var email = "test-request-create-" + Date.now() + "@email.com";
510
624
  var pwd = "pwd";
511
625
 
512
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
626
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
513
627
  var userid = savedUser.id;
514
- projectService.createAndReturnProjectAndProjectUser("createWithIdAndCreatedBy", userid).then(function(savedProjectAndPU) {
515
- var savedProject = savedProjectAndPU.project;
516
- var now = Date.now();
517
- // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
518
- requestService.createWithIdAndRequester("request_id-createWithIdAndCreatedBy-"+now,savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", null, null, null,null,null, "user1").then(function(savedRequest) {
628
+ projectService.createAndReturnProjectAndProjectUser("createWithIdAndCreatedBy", userid).then(function (savedProjectAndPU) {
629
+ var savedProject = savedProjectAndPU.project;
630
+ var now = Date.now();
631
+ // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
632
+ requestService.createWithIdAndRequester("request_id-createWithIdAndCreatedBy-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", null, null, null, null, null, "user1").then(function (savedRequest) {
519
633
  console.log("test resolve");
520
- expect(savedRequest.request_id).to.equal("request_id-createWithIdAndCreatedBy-"+now);
634
+ expect(savedRequest.request_id).to.equal("request_id-createWithIdAndCreatedBy-" + now);
521
635
  expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
522
636
  expect(savedRequest.first_text).to.equal("first_text");
523
637
  expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
@@ -527,7 +641,7 @@ describe('RequestService', function () {
527
641
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
528
642
  expect(savedRequest.hasBot).to.equal(false);
529
643
  expect(savedRequest.createdBy).to.equal("user1");
530
-
644
+
531
645
  // console.log("savedProject._id", savedProject._id, typeof savedProject._id);
532
646
  // console.log("savedRequest.id_project", savedRequest.id_project, typeof savedRequest.id_project);
533
647
 
@@ -537,14 +651,14 @@ describe('RequestService', function () {
537
651
  // expect(savedRequest.department).to.equal("requester_id1");
538
652
  done();
539
653
  })
540
- .catch(function(err) {
541
- console.log("test reject",err);
542
- assert.isNotOk(err,'Promise error');
654
+ .catch(function (err) {
655
+ console.log("test reject", err);
656
+ assert.isNotOk(err, 'Promise error');
543
657
  done();
544
- });
658
+ });
659
+ });
545
660
  });
546
661
  });
547
- });
548
662
 
549
663
 
550
664
 
@@ -556,22 +670,22 @@ describe('RequestService', function () {
556
670
  var email = "test-request-create-" + Date.now() + "@email.com";
557
671
  var pwd = "pwd";
558
672
 
559
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
673
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
560
674
  var userid = savedUser.id;
561
- projectService.createAndReturnProjectAndProjectUser("createWithWrongDepartmentId", userid).then(function(savedProjectAndPU) {
562
- var savedProject = savedProjectAndPU.project;
563
- var now = Date.now();
564
- // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
565
- requestService.createWithIdAndRequester("request_idcreateWithWrongDepartmentId-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", "5ebd890b3f2702001915c89e", null, null,null,null, "user1").then(function(savedRequest) {
566
-
675
+ projectService.createAndReturnProjectAndProjectUser("createWithWrongDepartmentId", userid).then(function (savedProjectAndPU) {
676
+ var savedProject = savedProjectAndPU.project;
677
+ var now = Date.now();
678
+ // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
679
+ requestService.createWithIdAndRequester("request_idcreateWithWrongDepartmentId-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", "5ebd890b3f2702001915c89e", null, null, null, null, "user1").then(function (savedRequest) {
680
+
567
681
  })
568
- .catch(function(err) {
569
- console.log("test reject",err);
682
+ .catch(function (err) {
683
+ console.log("test reject", err);
570
684
  done();
571
- });
685
+ });
686
+ });
572
687
  });
573
688
  });
574
- });
575
689
 
576
690
 
577
691
 
@@ -581,137 +695,137 @@ describe('RequestService', function () {
581
695
  var email = "test-request-create-" + Date.now() + "@email.com";
582
696
  var pwd = "pwd";
583
697
 
584
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
698
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
585
699
  var userid = savedUser.id;
586
700
 
587
- projectService.createAndReturnProjectAndProjectUser("createWithIdWithPooledDepartment", userid).then(function(savedProjectAndPU) {
588
- var savedProject = savedProjectAndPU.project;
589
- departmentService.create("PooledDepartment-for-createWithIdWith-createWithIdWithPooledDepartment", savedProject._id, 'pooled', userid).then(function(createdDepartment) {
590
- var now = Date.now();
591
- requestService.createWithIdAndRequester("request_id-createWithIdWithPooledDepartment-"+now,savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", createdDepartment._id).then(function(savedRequest) {
592
- winston.debug("resolve savedRequest");
593
- expect(savedRequest.request_id).to.equal("request_id-createWithIdWithPooledDepartment-"+now);
594
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
595
- expect(savedRequest.first_text).to.equal("first_text");
596
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
597
- expect(savedRequest.status).to.equal(100);
598
- expect(savedRequest.participants).to.have.lengthOf(0);
599
- expect(savedRequest.participantsAgents).to.have.lengthOf(0);
600
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
601
- expect(savedRequest.hasBot).to.equal(false);
602
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
603
- expect(savedRequest.department.toString()).to.equal(createdDepartment._id.toString());
604
- done();
605
- }).catch(function(err) {
606
- console.log("test reject",err);
607
- assert.isNotOk(err,'Promise error');
701
+ projectService.createAndReturnProjectAndProjectUser("createWithIdWithPooledDepartment", userid).then(function (savedProjectAndPU) {
702
+ var savedProject = savedProjectAndPU.project;
703
+ departmentService.create("PooledDepartment-for-createWithIdWith-createWithIdWithPooledDepartment", savedProject._id, 'pooled', userid).then(function (createdDepartment) {
704
+ var now = Date.now();
705
+ requestService.createWithIdAndRequester("request_id-createWithIdWithPooledDepartment-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text", createdDepartment._id).then(function (savedRequest) {
706
+ winston.debug("resolve savedRequest");
707
+ expect(savedRequest.request_id).to.equal("request_id-createWithIdWithPooledDepartment-" + now);
708
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
709
+ expect(savedRequest.first_text).to.equal("first_text");
710
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
711
+ expect(savedRequest.status).to.equal(100);
712
+ expect(savedRequest.participants).to.have.lengthOf(0);
713
+ expect(savedRequest.participantsAgents).to.have.lengthOf(0);
714
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
715
+ expect(savedRequest.hasBot).to.equal(false);
716
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
717
+ expect(savedRequest.department.toString()).to.equal(createdDepartment._id.toString());
608
718
  done();
719
+ }).catch(function (err) {
720
+ console.log("test reject", err);
721
+ assert.isNotOk(err, 'Promise error');
722
+ done();
723
+ });
609
724
  });
725
+ });
610
726
  });
611
- });
612
- });
613
727
  });
614
728
 
615
- // mocha test/requestService.js --grep 'updateWaitingTimeRequest'
729
+ // mocha test/requestService.js --grep 'updateWaitingTimeRequest'
616
730
 
617
731
  it('updateWaitingTimeRequest', function (done) {
618
732
  this.timeout(1000);
619
733
  var email = "test-request-create-" + Date.now() + "@email.com";
620
734
  var pwd = "pwd";
621
735
 
622
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
736
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
623
737
  var userid = savedUser.id;
624
738
 
625
- var messageSender = "5badfe5d553d1844ad654072";
626
- projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function(savedProjectAndPU) {
627
- var savedProject = savedProjectAndPU.project;
628
- var now = Date.now();
629
- requestService.createWithIdAndRequester("request_id-waitingTimeRequest-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
739
+ var messageSender = "5badfe5d553d1844ad654072";
740
+ projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
741
+ var savedProject = savedProjectAndPU.project;
742
+ var now = Date.now();
743
+ requestService.createWithIdAndRequester("request_id-waitingTimeRequest-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
630
744
  setTimeout(function () {
631
- Promise.all([
632
- messageService.create(messageSender, "test sender", savedRequest.request_id, "hello1",
745
+ Promise.all([
746
+ messageService.create(messageSender, "test sender", savedRequest.request_id, "hello1",
633
747
  savedProject._id, messageSender),
634
- messageService.create(messageSender, "test sender", savedRequest.request_id, "hello2",
635
- savedProject._id, messageSender)]).then(function(all) {
636
- requestService.updateWaitingTimeByRequestId(savedRequest.request_id, savedProject._id, true).then(function(upRequest) {
637
- var maxWaitingTime = Date.now() - upRequest.createdAt;
638
- console.log("resolve closedRequest", upRequest.toObject(),maxWaitingTime);
639
-
640
- expect(upRequest.status).to.equal(200);
641
- // console.log("1")
642
- // expect(upRequest.status).to.equal(300);
643
- expect(upRequest.waiting_time).to.not.equal(null);
644
- // console.log("2")
645
- expect(upRequest.waiting_time).to.gte(300);
646
- // console.log("3")
647
- expect(upRequest.waiting_time).to.lte(maxWaitingTime);
648
- // console.log("4")
649
- expect(upRequest.first_response_at).to.not.equal(null);
650
- // console.log("5")
651
- done();
652
- }).catch(function(err){
653
- winston.error("test reject", err);
654
- assert.isNotOk(err,'Promise error');
655
- done();
656
- });
748
+ messageService.create(messageSender, "test sender", savedRequest.request_id, "hello2",
749
+ savedProject._id, messageSender)]).then(function (all) {
750
+ requestService.updateWaitingTimeByRequestId(savedRequest.request_id, savedProject._id, true).then(function (upRequest) {
751
+ var maxWaitingTime = Date.now() - upRequest.createdAt;
752
+ console.log("resolve closedRequest", upRequest.toObject(), maxWaitingTime);
753
+
754
+ expect(upRequest.status).to.equal(200);
755
+ // console.log("1")
756
+ // expect(upRequest.status).to.equal(300);
757
+ expect(upRequest.waiting_time).to.not.equal(null);
758
+ // console.log("2")
759
+ expect(upRequest.waiting_time).to.gte(300);
760
+ // console.log("3")
761
+ expect(upRequest.waiting_time).to.lte(maxWaitingTime);
762
+ // console.log("4")
763
+ expect(upRequest.first_response_at).to.not.equal(null);
764
+ // console.log("5")
765
+ done();
766
+ }).catch(function (err) {
767
+ winston.error("test reject", err);
768
+ assert.isNotOk(err, 'Promise error');
769
+ done();
657
770
  });
658
- }, 300);
771
+ });
772
+ }, 300);
659
773
  });
660
774
  });
775
+ });
661
776
  });
662
- });
663
777
 
664
778
 
665
779
 
666
780
 
667
781
 
668
782
 
669
- // mocha test/requestService.js --grep 'closeRequest'
783
+ // mocha test/requestService.js --grep 'closeRequest'
670
784
 
671
785
 
672
- it('closeRequest', function (done) {
786
+ it('closeRequest', function (done) {
673
787
 
674
- var email = "test-request-create-" + Date.now() + "@email.com";
675
- var pwd = "pwd";
676
-
677
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
678
- var userid = savedUser.id;
679
-
680
- projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function(savedProjectAndPU) {
681
- var savedProject = savedProjectAndPU.project;
682
- var now = Date.now();
683
- requestService.createWithIdAndRequester("request_id-closeRequest-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
684
- Promise.all([
685
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
788
+ var email = "test-request-create-" + Date.now() + "@email.com";
789
+ var pwd = "pwd";
790
+
791
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
792
+ var userid = savedUser.id;
793
+
794
+ projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
795
+ var savedProject = savedProjectAndPU.project;
796
+ var now = Date.now();
797
+ requestService.createWithIdAndRequester("request_id-closeRequest-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
798
+ Promise.all([
799
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
686
800
  savedProject._id, "5badfe5d553d1844ad654072"),
687
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
688
- savedProject._id, "5badfe5d553d1844ad654072")]).then(function(all) {
801
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
802
+ savedProject._id, "5badfe5d553d1844ad654072")]).then(function (all) {
689
803
  // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
690
- requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id, false, true, "user1").then(function(closedRequest) {
691
- winston.debug("resolve closedRequest", closedRequest.toObject());
692
- expect(closedRequest.status).to.equal(1000);
693
- expect(closedRequest.closed_at).to.not.equal(null);
694
- expect(closedRequest.transcript).to.contains("hello1");
695
- expect(closedRequest.transcript).to.contains("hello2");
696
- expect(closedRequest.snapshot.agents).to.equal(undefined);
697
- expect(closedRequest.closed_by).to.equal("user1");
698
-
699
- done();
700
- }).catch(function(err){
701
- winston.error("test reject", err);
702
- assert.isNotOk(err,'Promise error');
703
- done();
704
- });
804
+ requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id, false, true, "user1").then(function (closedRequest) {
805
+ winston.debug("resolve closedRequest", closedRequest.toObject());
806
+ expect(closedRequest.status).to.equal(1000);
807
+ expect(closedRequest.closed_at).to.not.equal(null);
808
+ expect(closedRequest.transcript).to.contains("hello1");
809
+ expect(closedRequest.transcript).to.contains("hello2");
810
+ expect(closedRequest.snapshot.agents).to.equal(undefined);
811
+ expect(closedRequest.closed_by).to.equal("user1");
812
+
813
+ done();
814
+ }).catch(function (err) {
815
+ winston.error("test reject", err);
816
+ assert.isNotOk(err, 'Promise error');
817
+ done();
705
818
  });
706
819
  });
707
- });
820
+ });
708
821
  });
709
822
  });
710
-
711
-
823
+ });
824
+
825
+
712
826
 
713
827
 
714
- // mocha test/requestService.js --grep 'closeRequestForce'
828
+ // mocha test/requestService.js --grep 'closeRequestForce'
715
829
 
716
830
 
717
831
  it('closeRequestForce', function (done) {
@@ -719,41 +833,41 @@ describe('RequestService', function () {
719
833
  var email = "test-request-create-" + Date.now() + "@email.com";
720
834
  var pwd = "pwd";
721
835
 
722
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
836
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
723
837
  var userid = savedUser.id;
724
838
 
725
- projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function(savedProjectAndPU) {
839
+ projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
726
840
  var savedProject = savedProjectAndPU.project;
727
841
  var now = Date.now();
728
- requestService.createWithIdAndRequester("request_id-closeRequest-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
842
+ requestService.createWithIdAndRequester("request_id-closeRequest-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
729
843
  Promise.all([
730
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
731
- savedProject._id, "5badfe5d553d1844ad654072"),
844
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
845
+ savedProject._id, "5badfe5d553d1844ad654072"),
732
846
  messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
733
- savedProject._id, "5badfe5d553d1844ad654072")]).then(function(all) {
734
- // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by, force)
735
- requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id, false, true, "user1").then(function(closedRequest) {
736
- winston.debug("resolve closedRequest", closedRequest.toObject());
737
- expect(closedRequest.status).to.equal(1000);
738
- expect(closedRequest.closed_at).to.not.equal(null);
739
- expect(closedRequest.transcript).to.contains("hello1");
740
- expect(closedRequest.transcript).to.contains("hello2");
741
- expect(closedRequest.snapshot.agents).to.equal(undefined);
742
- expect(closedRequest.closed_by).to.equal("user1");
847
+ savedProject._id, "5badfe5d553d1844ad654072")]).then(function (all) {
848
+ // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by, force)
849
+ requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id, false, true, "user1").then(function (closedRequest) {
850
+ winston.debug("resolve closedRequest", closedRequest.toObject());
851
+ expect(closedRequest.status).to.equal(1000);
852
+ expect(closedRequest.closed_at).to.not.equal(null);
853
+ expect(closedRequest.transcript).to.contains("hello1");
854
+ expect(closedRequest.transcript).to.contains("hello2");
855
+ expect(closedRequest.snapshot.agents).to.equal(undefined);
856
+ expect(closedRequest.closed_by).to.equal("user1");
743
857
 
744
- requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id, false, true, "user1", true).then(function(closedRequest) {
745
- expect(closedRequest.status).to.equal(1000);
746
- done();
747
- });
748
-
749
- }).catch(function(err){
750
- winston.error("test reject", err);
751
- assert.isNotOk(err,'Promise error');
858
+ requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id, false, true, "user1", true).then(function (closedRequest) {
859
+ expect(closedRequest.status).to.equal(1000);
752
860
  done();
753
861
  });
862
+
863
+ }).catch(function (err) {
864
+ winston.error("test reject", err);
865
+ assert.isNotOk(err, 'Promise error');
866
+ done();
867
+ });
754
868
  });
755
- });
756
- });
869
+ });
870
+ });
757
871
  });
758
872
  });
759
873
 
@@ -766,40 +880,40 @@ describe('RequestService', function () {
766
880
  var email = "test-request-create-" + Date.now() + "@email.com";
767
881
  var pwd = "pwd";
768
882
 
769
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
883
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
770
884
  var userid = savedUser.id;
771
885
 
772
- projectService.createAndReturnProjectAndProjectUser("test1", userid, {email: {autoSendTranscriptToRequester:true}}).then(function(savedProjectAndPU) {
773
- var savedProject = savedProjectAndPU.project;
774
-
775
- leadService.createIfNotExists("leadfullname", "andrea.leo@frontiere21.it", savedProject._id).then(function(createdLead) {
776
- var now = Date.now();
777
- requestService.createWithIdAndRequester("request_id-closeRequestAndSendTranscript-"+now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
778
- Promise.all([
779
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
780
- savedProject._id, "5badfe5d553d1844ad654072"),
781
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
782
- savedProject._id, "5badfe5d553d1844ad654072")]).then(function(all) {
783
- requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id).then(function(closedRequest) {
784
- winston.debug("resolve closedRequest", closedRequest.toObject());
785
- expect(closedRequest.status).to.equal(1000);
786
- expect(closedRequest.closed_at).to.not.equal(null);
787
- expect(closedRequest.transcript).to.contains("hello1");
788
- expect(closedRequest.transcript).to.contains("hello2");
789
- expect(closedRequest.snapshot.agents).to.equal(undefined);
886
+ projectService.createAndReturnProjectAndProjectUser("test1", userid, { email: { autoSendTranscriptToRequester: true } }).then(function (savedProjectAndPU) {
887
+ var savedProject = savedProjectAndPU.project;
790
888
 
791
- done();
792
- }).catch(function(err){
793
- winston.error("test reject", err);
794
- assert.isNotOk(err,'Promise error');
795
- done();
889
+ leadService.createIfNotExists("leadfullname", "andrea.leo@frontiere21.it", savedProject._id).then(function (createdLead) {
890
+ var now = Date.now();
891
+ requestService.createWithIdAndRequester("request_id-closeRequestAndSendTranscript-" + now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function (savedRequest) {
892
+ Promise.all([
893
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
894
+ savedProject._id, "5badfe5d553d1844ad654072"),
895
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
896
+ savedProject._id, "5badfe5d553d1844ad654072")]).then(function (all) {
897
+ requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id).then(function (closedRequest) {
898
+ winston.debug("resolve closedRequest", closedRequest.toObject());
899
+ expect(closedRequest.status).to.equal(1000);
900
+ expect(closedRequest.closed_at).to.not.equal(null);
901
+ expect(closedRequest.transcript).to.contains("hello1");
902
+ expect(closedRequest.transcript).to.contains("hello2");
903
+ expect(closedRequest.snapshot.agents).to.equal(undefined);
904
+
905
+ done();
906
+ }).catch(function (err) {
907
+ winston.error("test reject", err);
908
+ assert.isNotOk(err, 'Promise error');
909
+ done();
910
+ });
796
911
  });
797
- });
798
912
  });
799
913
  });
800
914
  });
915
+ });
801
916
  });
802
- });
803
917
 
804
918
 
805
919
 
@@ -808,45 +922,45 @@ describe('RequestService', function () {
808
922
  var email = "test-request-create-" + Date.now() + "@email.com";
809
923
  var pwd = "pwd";
810
924
 
811
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
925
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
812
926
  var userid = savedUser.id;
813
927
 
814
- projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function(savedProjectAndPU) {
815
- var savedProject = savedProjectAndPU.project;
816
- var now = Date.now();
928
+ projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
929
+ var savedProject = savedProjectAndPU.project;
930
+ var now = Date.now();
817
931
 
818
- requestService.createWithIdAndRequester("request_id-reopenRequest-"+now, savedProjectAndPU.project_user._id, null,savedProject._id, "first_text").then(function(savedRequest) {
819
-
820
- requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id).then(function(closedRequest) {
821
- requestService.reopenRequestByRequestId(savedRequest.request_id, savedProject._id).then(function(reopenedRequest) {
822
-
823
- winston.info("resolve reopenedRequest", reopenedRequest.toObject());
932
+ requestService.createWithIdAndRequester("request_id-reopenRequest-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
824
933
 
825
- //check closedRequest
826
- expect(closedRequest.status).to.equal(1000);
827
- expect(closedRequest.closed_at).to.not.equal(null);
828
- expect(closedRequest.participants).to.have.lengthOf(1);
829
-
830
- //check reopenedRequest
831
- expect(reopenedRequest.status).to.equal(200);
832
- expect(reopenedRequest.closed_at).to.not.equal(null);
833
- expect(reopenedRequest.participants).to.have.lengthOf(1);
834
- expect(reopenedRequest.snapshot.agents).to.equal(undefined);
835
-
836
-
837
- done();
838
- }).catch(function(err){
839
- winston.error("test reject", err);
840
- assert.isNotOk(err,'Promise error');
841
- done();
842
- });
934
+ requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id).then(function (closedRequest) {
935
+ requestService.reopenRequestByRequestId(savedRequest.request_id, savedProject._id).then(function (reopenedRequest) {
936
+
937
+ winston.info("resolve reopenedRequest", reopenedRequest.toObject());
938
+
939
+ //check closedRequest
940
+ expect(closedRequest.status).to.equal(1000);
941
+ expect(closedRequest.closed_at).to.not.equal(null);
942
+ expect(closedRequest.participants).to.have.lengthOf(1);
943
+
944
+ //check reopenedRequest
945
+ expect(reopenedRequest.status).to.equal(200);
946
+ expect(reopenedRequest.closed_at).to.not.equal(null);
947
+ expect(reopenedRequest.participants).to.have.lengthOf(1);
948
+ expect(reopenedRequest.snapshot.agents).to.equal(undefined);
949
+
950
+
951
+ done();
952
+ }).catch(function (err) {
953
+ winston.error("test reject", err);
954
+ assert.isNotOk(err, 'Promise error');
955
+ done();
843
956
  });
844
957
  });
845
- });
958
+ });
959
+ });
960
+ });
846
961
  });
847
- });
848
962
 
849
- // mocha test/requestService.js --grep 'addparticipant'
963
+ // mocha test/requestService.js --grep 'addparticipant'
850
964
 
851
965
  it('addparticipant', function (done) {
852
966
 
@@ -855,510 +969,455 @@ describe('RequestService', function () {
855
969
 
856
970
  var pwd = "pwd";
857
971
 
858
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
972
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
859
973
  var userid = savedUser.id;
860
974
 
861
- projectService.createAndReturnProjectAndProjectUser("addparticipant-project", userid).then(function(savedProjectAndPU) {
862
- var savedProject = savedProjectAndPU.project;
975
+ projectService.createAndReturnProjectAndProjectUser("addparticipant-project", userid).then(function (savedProjectAndPU) {
976
+ var savedProject = savedProjectAndPU.project;
863
977
 
864
- userService.signup( email2 ,pwd, "Test Firstname2", "Test lastname2").then(function(savedUser2) {
978
+ userService.signup(email2, pwd, "Test Firstname2", "Test lastname2").then(function (savedUser2) {
865
979
 
866
- // console.log("savedUser2",savedUser2);
980
+ // console.log("savedUser2",savedUser2);
867
981
 
868
- var newProject_user = new Project_user({
869
- // _id: new mongoose.Types.ObjectId(),
870
- id_project: savedProject._id.toString(),
871
- id_user: savedUser2._id.toString(),
872
- role: "agent",
873
- user_available: false,
874
- createdBy: userid,
875
- updatedBy: userid
876
- });
982
+ var newProject_user = new Project_user({
983
+ // _id: new mongoose.Types.ObjectId(),
984
+ id_project: savedProject._id.toString(),
985
+ id_user: savedUser2._id.toString(),
986
+ role: "agent",
987
+ user_available: false,
988
+ createdBy: userid,
989
+ updatedBy: userid
990
+ });
877
991
 
878
- return newProject_user.save(function (err, savedProject_user) {
992
+ return newProject_user.save(function (err, savedProject_user) {
879
993
 
880
- if (err) {
881
- console.log("err",err)
882
- }
994
+ if (err) {
995
+ console.log("err", err)
996
+ }
883
997
 
884
- var now = Date.now();
885
- requestService.createWithIdAndRequester("request_id-addparticipant-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
886
- // inserisci id valido
887
- // var member = 'agent1';
888
- var member = savedUser2._id.toString();
889
- // console.log("member",member)
890
- // addParticipantByRequestId(request_id, id_project, member) {
891
- requestService.addParticipantByRequestId(savedRequest.request_id, savedProject._id, member).then(function(savedRequestParticipant) {
892
- winston.info("resolve addParticipantByRequestId", savedRequestParticipant.toObject());
893
- expect(savedRequestParticipant.request_id).to.equal("request_id-addparticipant-"+now);
998
+ var now = Date.now();
999
+ requestService.createWithIdAndRequester("request_id-addparticipant-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1000
+ // inserisci id valido
1001
+ // var member = 'agent1';
1002
+ var member = savedUser2._id.toString();
1003
+ // console.log("member",member)
1004
+ // addParticipantByRequestId(request_id, id_project, member) {
1005
+ requestService.addParticipantByRequestId(savedRequest.request_id, savedProject._id, member).then(function (savedRequestParticipant) {
1006
+ winston.info("resolve addParticipantByRequestId", savedRequestParticipant.toObject());
1007
+ expect(savedRequestParticipant.request_id).to.equal("request_id-addparticipant-" + now);
894
1008
 
895
- winston.info("savedProjectAndPU.project_user._id.toString():"+savedProjectAndPU.project_user._id.toString());
896
- expect(savedRequestParticipant.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1009
+ winston.info("savedProjectAndPU.project_user._id.toString():" + savedProjectAndPU.project_user._id.toString());
1010
+ expect(savedRequestParticipant.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
897
1011
 
898
- expect(savedRequestParticipant.first_text).to.equal("first_text");
899
- // expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(2);
900
- expect(savedRequestParticipant.status).to.equal(200);
1012
+ expect(savedRequestParticipant.first_text).to.equal("first_text");
1013
+ // expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(2);
1014
+ expect(savedRequestParticipant.status).to.equal(200);
901
1015
 
902
- expect(savedRequestParticipant.participants).to.have.lengthOf(2);
903
- expect(savedRequestParticipant.participants).to.contains(userid);
904
- expect(savedRequestParticipant.participants).to.contains(member);
1016
+ expect(savedRequestParticipant.participants).to.have.lengthOf(2);
1017
+ expect(savedRequestParticipant.participants).to.contains(userid);
1018
+ expect(savedRequestParticipant.participants).to.contains(member);
905
1019
 
906
- expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(2);
907
- expect(savedRequestParticipant.participantsAgents).to.contains(userid);
908
- expect(savedRequestParticipant.participantsAgents).to.contains(member);
1020
+ expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(2);
1021
+ expect(savedRequestParticipant.participantsAgents).to.contains(userid);
1022
+ expect(savedRequestParticipant.participantsAgents).to.contains(member);
909
1023
 
910
- expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(2);
911
- expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
912
- expect(savedRequestParticipant.hasBot).to.equal(false);
913
- expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1024
+ expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(2);
1025
+ expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
1026
+ expect(savedRequestParticipant.hasBot).to.equal(false);
1027
+ expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
914
1028
 
915
- expect(savedRequestParticipant.snapshot.agents).to.equal(undefined);
1029
+ expect(savedRequestParticipant.snapshot.agents).to.equal(undefined);
916
1030
 
917
- done();
918
- }).catch(function(err) {
919
- console.log("test reject", err);
920
- assert.isNotOk(err,'Promise error');
921
- done();
1031
+ done();
1032
+ }).catch(function (err) {
1033
+ console.log("test reject", err);
1034
+ assert.isNotOk(err, 'Promise error');
1035
+ done();
1036
+ });
1037
+ });
1038
+ });
1039
+ });
922
1040
  });
923
1041
  });
924
1042
  });
925
- });
926
- });
927
- });
928
- });
929
1043
 
930
1044
 
931
1045
 
932
1046
 
933
1047
 
934
1048
 
935
- it('setParticipantsByRequestId', function (done) {
1049
+ it('setParticipantsByRequestId', function (done) {
936
1050
 
937
- var email = "test-request-setParticipantsByRequestId-" + Date.now() + "@email.com";
938
- var email2 = "test-request-setParticipantsByRequestId2-" + Date.now() + "@email.com";
1051
+ var email = "test-request-setParticipantsByRequestId-" + Date.now() + "@email.com";
1052
+ var email2 = "test-request-setParticipantsByRequestId2-" + Date.now() + "@email.com";
939
1053
 
940
- var pwd = "pwd";
1054
+ var pwd = "pwd";
941
1055
 
942
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
943
- var userid = savedUser.id;
1056
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1057
+ var userid = savedUser.id;
944
1058
 
945
- projectService.createAndReturnProjectAndProjectUser("setParticipantsByRequestId-project", userid).then(function(savedProjectAndPU) {
946
- var savedProject = savedProjectAndPU.project;
1059
+ projectService.createAndReturnProjectAndProjectUser("setParticipantsByRequestId-project", userid).then(function (savedProjectAndPU) {
1060
+ var savedProject = savedProjectAndPU.project;
947
1061
 
948
- userService.signup( email2 ,pwd, "Test Firstname2", "Test lastname2").then(function(savedUser2) {
1062
+ userService.signup(email2, pwd, "Test Firstname2", "Test lastname2").then(function (savedUser2) {
949
1063
 
950
- // console.log("savedUser2",savedUser2);
1064
+ // console.log("savedUser2",savedUser2);
951
1065
 
952
- var newProject_user = new Project_user({
953
- // _id: new mongoose.Types.ObjectId(),
954
- id_project: savedProject._id.toString(),
955
- id_user: savedUser2._id.toString(),
956
- role: "agent",
957
- user_available: false,
958
- createdBy: userid,
959
- updatedBy: userid
960
- });
1066
+ var newProject_user = new Project_user({
1067
+ // _id: new mongoose.Types.ObjectId(),
1068
+ id_project: savedProject._id.toString(),
1069
+ id_user: savedUser2._id.toString(),
1070
+ role: "agent",
1071
+ user_available: false,
1072
+ createdBy: userid,
1073
+ updatedBy: userid
1074
+ });
1075
+
1076
+ return newProject_user.save(function (err, savedProject_user) {
1077
+
1078
+ if (err) {
1079
+ console.log("err", err)
1080
+ }
1081
+ var now = Date.now();
1082
+
1083
+ requestService.createWithIdAndRequester("request_id1-setParticipantsByRequestId-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1084
+ expect(savedRequest.participants).to.contains(userid);
1085
+ expect(savedRequest.participantsAgents).to.contains(userid);
1086
+
1087
+ // inserisci id valido
1088
+ // var member = 'agent1';
1089
+ var member = savedUser2._id.toString();
1090
+ // console.log("member",member)
1091
+ // setParticipantsByRequestId(request_id, id_project, newparticipants) {
1092
+ requestService.setParticipantsByRequestId(savedRequest.request_id, savedProject._id, [member]).then(function (savedRequestParticipant) {
1093
+ winston.info("resolve setParticipantsByRequestId", savedRequestParticipant.toObject());
1094
+ expect(savedRequestParticipant.request_id).to.equal("request_id1-setParticipantsByRequestId-" + now);
1095
+
1096
+ winston.info("savedProjectAndPU.project_user._id.toString():" + savedProjectAndPU.project_user._id.toString());
1097
+ expect(savedRequestParticipant.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
961
1098
 
962
- return newProject_user.save(function (err, savedProject_user) {
963
-
964
- if (err) {
965
- console.log("err",err)
966
- }
967
- var now = Date.now();
968
-
969
- requestService.createWithIdAndRequester("request_id1-setParticipantsByRequestId-"+now,savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
970
- expect(savedRequest.participants).to.contains(userid);
971
- expect(savedRequest.participantsAgents).to.contains(userid);
972
-
973
- // inserisci id valido
974
- // var member = 'agent1';
975
- var member = savedUser2._id.toString();
976
- // console.log("member",member)
977
- // setParticipantsByRequestId(request_id, id_project, newparticipants) {
978
- requestService.setParticipantsByRequestId(savedRequest.request_id, savedProject._id, [member]).then(function(savedRequestParticipant) {
979
- winston.info("resolve setParticipantsByRequestId", savedRequestParticipant.toObject());
980
- expect(savedRequestParticipant.request_id).to.equal("request_id1-setParticipantsByRequestId-"+now);
981
-
982
- winston.info("savedProjectAndPU.project_user._id.toString():"+savedProjectAndPU.project_user._id.toString());
983
- expect(savedRequestParticipant.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
984
-
985
- expect(savedRequestParticipant.first_text).to.equal("first_text");
986
- // expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(2);
987
- expect(savedRequestParticipant.status).to.equal(200);
988
-
989
- expect(savedRequestParticipant.participants).to.have.lengthOf(1);
990
- expect(savedRequestParticipant.participants).to.contains(member);
991
-
992
- expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(1);
993
- expect(savedRequestParticipant.participantsAgents).to.contains(member);
994
-
995
- expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(1);
996
- expect(savedRequestParticipant.participatingAgents[0]._id.toString()).to.equal(member);
997
- expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
998
- expect(savedRequestParticipant.hasBot).to.equal(false);
999
- expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1000
-
1001
- done();
1002
- }).catch(function(err) {
1003
- console.log("test reject", err);
1004
- assert.isNotOk(err,'Promise error');
1005
- done();
1099
+ expect(savedRequestParticipant.first_text).to.equal("first_text");
1100
+ // expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(2);
1101
+ expect(savedRequestParticipant.status).to.equal(200);
1102
+
1103
+ expect(savedRequestParticipant.participants).to.have.lengthOf(1);
1104
+ expect(savedRequestParticipant.participants).to.contains(member);
1105
+
1106
+ expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(1);
1107
+ expect(savedRequestParticipant.participantsAgents).to.contains(member);
1108
+
1109
+ expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(1);
1110
+ expect(savedRequestParticipant.participatingAgents[0]._id.toString()).to.equal(member);
1111
+ expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
1112
+ expect(savedRequestParticipant.hasBot).to.equal(false);
1113
+ expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1114
+
1115
+ done();
1116
+ }).catch(function (err) {
1117
+ console.log("test reject", err);
1118
+ assert.isNotOk(err, 'Promise error');
1119
+ done();
1120
+ });
1121
+ });
1122
+ });
1123
+ });
1124
+ });
1006
1125
  });
1007
1126
  });
1008
- });
1009
- });
1010
- });
1011
- });
1012
- });
1013
1127
 
1014
1128
 
1015
1129
  // mocha test/requestService.js --grep 'removeparticipant'
1016
1130
 
1017
- it('removeparticipant', function (done) {
1018
-
1019
- var email = "test-request-create-" + Date.now() + "@email.com";
1020
- var pwd = "pwd";
1021
-
1022
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1023
- var userid = savedUser.id;
1024
-
1025
- projectService.createAndReturnProjectAndProjectUser("removeparticipant-project", userid).then(function(savedProjectAndPU) {
1026
- var savedProject = savedProjectAndPU.project;
1027
- var now = Date.now();
1028
- requestService.createWithIdAndRequester("request_id-removeparticipant-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
1029
- requestService.removeParticipantByRequestId(savedRequest.request_id, savedProject._id, userid).then(function(savedRequestParticipant) {
1030
- winston.info("resolve", savedRequestParticipant.toObject());
1031
-
1032
- //savedRequest is assigned -> 200
1033
- expect(savedRequest.status).to.equal(200);
1034
-
1035
- //savedRequestParticipant is UNASSIGNED -> 100
1036
- expect(savedRequestParticipant.request_id).to.equal("request_id-removeparticipant-"+now);
1037
- // expect(savedRequestParticipant.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1038
- expect(savedRequestParticipant.first_text).to.equal("first_text");
1039
- // expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(1);
1040
- expect(savedRequestParticipant.status).to.equal(100);
1041
- expect(savedRequestParticipant.participants).to.have.lengthOf(0);
1042
- expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(0);
1043
- expect(savedRequestParticipant.participantsBots).to.have.lengthOf(0);
1044
-
1045
- expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(0);
1046
- expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
1047
-
1048
- expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1049
- expect(savedRequestParticipant.attributes.abandoned_by_project_users[savedProjectAndPU.project_user._id]).to.not.equal(undefined);
1050
-
1051
- done();
1052
- }).catch(function(err) {
1053
- console.log("test reject");
1054
- assert.isNotOk(err,'Promise error');
1055
- done();
1131
+ it('removeparticipant', function (done) {
1132
+
1133
+ var email = "test-request-create-" + Date.now() + "@email.com";
1134
+ var pwd = "pwd";
1135
+
1136
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1137
+ var userid = savedUser.id;
1138
+
1139
+ projectService.createAndReturnProjectAndProjectUser("removeparticipant-project", userid).then(function (savedProjectAndPU) {
1140
+ var savedProject = savedProjectAndPU.project;
1141
+ var now = Date.now();
1142
+ requestService.createWithIdAndRequester("request_id-removeparticipant-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1143
+ requestService.removeParticipantByRequestId(savedRequest.request_id, savedProject._id, userid).then(function (savedRequestParticipant) {
1144
+ winston.info("resolve", savedRequestParticipant.toObject());
1145
+
1146
+ //savedRequest is assigned -> 200
1147
+ expect(savedRequest.status).to.equal(200);
1148
+
1149
+ //savedRequestParticipant is UNASSIGNED -> 100
1150
+ expect(savedRequestParticipant.request_id).to.equal("request_id-removeparticipant-" + now);
1151
+ // expect(savedRequestParticipant.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1152
+ expect(savedRequestParticipant.first_text).to.equal("first_text");
1153
+ // expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(1);
1154
+ expect(savedRequestParticipant.status).to.equal(100);
1155
+ expect(savedRequestParticipant.participants).to.have.lengthOf(0);
1156
+ expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(0);
1157
+ expect(savedRequestParticipant.participantsBots).to.have.lengthOf(0);
1158
+
1159
+ expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(0);
1160
+ expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
1161
+
1162
+ expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1163
+ expect(savedRequestParticipant.attributes.abandoned_by_project_users[savedProjectAndPU.project_user._id]).to.not.equal(undefined);
1164
+
1165
+ done();
1166
+ }).catch(function (err) {
1167
+ console.log("test reject");
1168
+ assert.isNotOk(err, 'Promise error');
1169
+ done();
1170
+ });
1171
+ });
1056
1172
  });
1057
1173
  });
1058
1174
  });
1059
- });
1060
- });
1061
1175
 
1062
1176
 
1063
1177
 
1064
1178
  // mocha test/requestService.js --grep 'routeDepartmentSameAgentSameDepartmentSkipUpdate'
1065
1179
  it('routeDepartmentSameAgentSameDepartmentSkipUpdate', function (done) {
1066
1180
  // this.timeout(10000);
1067
-
1181
+
1068
1182
  var email = "test-route-create-" + Date.now() + "@email.com";
1069
1183
  var pwd = "pwd";
1070
-
1071
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1184
+
1185
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1072
1186
  var userid = savedUser.id;
1073
-
1074
- projectService.createAndReturnProjectAndProjectUser("routeDepartmentSameAgentSameDepartmentSkipUpdate", userid).then(function(savedProjectAndPU) {
1075
- var savedProject = savedProjectAndPU.project;
1076
- var now = Date.now();
1077
- requestService.createWithIdAndRequester("routeDepartmentSameAgentSameDepartmentSkipUpdate-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
1187
+
1188
+ projectService.createAndReturnProjectAndProjectUser("routeDepartmentSameAgentSameDepartmentSkipUpdate", userid).then(function (savedProjectAndPU) {
1189
+ var savedProject = savedProjectAndPU.project;
1190
+ var now = Date.now();
1191
+ requestService.createWithIdAndRequester("routeDepartmentSameAgentSameDepartmentSkipUpdate-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1078
1192
  winston.debug("resolve savedRequest");
1079
- expect(savedRequest.request_id).to.equal("routeDepartmentSameAgentSameDepartmentSkipUpdate-"+now);
1193
+ expect(savedRequest.request_id).to.equal("routeDepartmentSameAgentSameDepartmentSkipUpdate-" + now);
1080
1194
  expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1081
1195
  expect(savedRequest.first_text).to.equal("first_text");
1082
1196
  expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
1083
1197
  expect(savedRequest.status).to.equal(200);
1084
- expect(savedRequest.participants).to.have.lengthOf(1);
1198
+ expect(savedRequest.participants).to.have.lengthOf(1);
1085
1199
  expect(savedRequest.participantsAgents).to.have.lengthOf(1);
1086
1200
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
1087
- expect(savedRequest.hasBot).to.equal(false);
1201
+ expect(savedRequest.hasBot).to.equal(false);
1088
1202
  expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1089
-
1090
- console.log("savedRequest.department",savedRequest.department);
1091
- // expect(savedRequest.department.name).to.equal("Default");
1092
-
1093
- // departmentService.create("AssignedDepartment-for-routeDepartmentSameAgentSameDepartmentSkipUpdate", savedProject._id, 'assigned', userid).then(function(createdDepartment) {
1094
- let dep = savedRequest.department;
1095
-
1096
- // route(request_id, departmentid, id_project, nobot, no_populate) {
1097
- requestService.route("routeDepartmentSameAgentSameDepartmentSkipUpdate-"+now, dep, savedProject._id, false).then(function(routedRequest) {
1098
-
1099
- expect(routedRequest.request_id).to.equal("routeDepartmentSameAgentSameDepartmentSkipUpdate-"+now);
1100
- expect(routedRequest.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1101
- expect(routedRequest.first_text).to.equal("first_text");
1102
- expect(routedRequest.snapshot.agents).to.have.lengthOf(1);
1103
- expect(routedRequest.status).to.equal(200);
1104
- expect(routedRequest.participants).to.have.lengthOf(1);
1105
- expect(routedRequest.participantsAgents).to.have.lengthOf(1);
1106
- expect(routedRequest.participantsBots).to.have.lengthOf(0);
1107
- expect(routedRequest.hasBot).to.equal(false);
1108
- expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1109
-
1110
- console.log("routedRequest.department.name",routedRequest.department.name);
1111
- expect(routedRequest.department._id.toString()).to.equal(dep.toString());
1112
- expect(routedRequest.snapshot.department._id.toString()).to.equal(dep.toString());
1113
-
1114
- done();
1115
-
1116
- });
1117
-
1118
- }).catch(function(err) {
1119
- console.log("test reject",err);
1120
- assert.isNotOk(err,'Promise error');
1121
- done();
1122
- });
1123
- });
1124
- });
1125
- });
1126
-
1127
-
1128
-
1129
- // mocha test/requestService.js --grep 'routeDepartmentSameAgentDifferentDepartment'
1130
- it('routeDepartmentSameAgentDifferentDepartment', function (done) {
1131
- // this.timeout(10000);
1132
-
1133
- var email = "test-route-create-" + Date.now() + "@email.com";
1134
- var pwd = "pwd";
1135
-
1136
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1137
- var userid = savedUser.id;
1138
-
1139
- projectService.createAndReturnProjectAndProjectUser("routeDepartmentSameAgentDifferentDepartment", userid).then(function(savedProjectAndPU) {
1140
- var savedProject = savedProjectAndPU.project;
1141
- var now = Date.now();
1142
1203
 
1143
- requestService.createWithIdAndRequester("routeDepartmentSameAgentDifferentDepartment-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
1144
- winston.debug("resolve savedRequest");
1145
- expect(savedRequest.request_id).to.equal("routeDepartmentSameAgentDifferentDepartment-"+now);
1146
- expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1147
- expect(savedRequest.first_text).to.equal("first_text");
1148
- expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
1149
- expect(savedRequest.status).to.equal(200);
1150
- expect(savedRequest.participants).to.have.lengthOf(1);
1151
- expect(savedRequest.participantsAgents).to.have.lengthOf(1);
1152
- expect(savedRequest.participantsBots).to.have.lengthOf(0);
1153
- expect(savedRequest.hasBot).to.equal(false);
1154
- expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1155
-
1156
- console.log("savedRequest.department",savedRequest.department);
1157
- // expect(savedRequest.department.name).to.equal("Default");
1204
+ console.log("savedRequest.department", savedRequest.department);
1205
+ // expect(savedRequest.department.name).to.equal("Default");
1158
1206
 
1159
- departmentService.create("AssignedDepartment-for-routeDepartmentSameAgentDifferentDepartment", savedProject._id, 'assigned', userid).then(function(createdDepartment) {
1207
+ // departmentService.create("AssignedDepartment-for-routeDepartmentSameAgentSameDepartmentSkipUpdate", savedProject._id, 'assigned', userid).then(function(createdDepartment) {
1208
+ let dep = savedRequest.department;
1160
1209
 
1161
1210
  // route(request_id, departmentid, id_project, nobot, no_populate) {
1162
- requestService.route("routeDepartmentSameAgentDifferentDepartment-"+now, createdDepartment._id, savedProject._id, false).then(function(routedRequest) {
1211
+ requestService.route("routeDepartmentSameAgentSameDepartmentSkipUpdate-" + now, dep, savedProject._id, false).then(function (routedRequest) {
1163
1212
 
1164
- expect(routedRequest.request_id).to.equal("routeDepartmentSameAgentDifferentDepartment-"+now);
1213
+ expect(routedRequest.request_id).to.equal("routeDepartmentSameAgentSameDepartmentSkipUpdate-" + now);
1165
1214
  expect(routedRequest.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1166
1215
  expect(routedRequest.first_text).to.equal("first_text");
1167
1216
  expect(routedRequest.snapshot.agents).to.have.lengthOf(1);
1168
1217
  expect(routedRequest.status).to.equal(200);
1169
- expect(routedRequest.participants).to.have.lengthOf(1);
1218
+ expect(routedRequest.participants).to.have.lengthOf(1);
1170
1219
  expect(routedRequest.participantsAgents).to.have.lengthOf(1);
1171
1220
  expect(routedRequest.participantsBots).to.have.lengthOf(0);
1172
- expect(routedRequest.hasBot).to.equal(false);
1221
+ expect(routedRequest.hasBot).to.equal(false);
1173
1222
  expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1174
-
1175
- console.log("routedRequest.department.name",routedRequest.department.name);
1176
- expect(routedRequest.department._id.toString()).to.equal(createdDepartment._id.toString());
1177
- expect(routedRequest.snapshot.department._id.toString()).to.equal(createdDepartment._id.toString());
1178
-
1223
+
1224
+ console.log("routedRequest.department.name", routedRequest.department.name);
1225
+ expect(routedRequest.department._id.toString()).to.equal(dep.toString());
1226
+ expect(routedRequest.snapshot.department._id.toString()).to.equal(dep.toString());
1227
+
1179
1228
  done();
1180
1229
 
1181
1230
  });
1182
1231
 
1183
- }).catch(function(err) {
1184
- console.log("test reject",err);
1185
- assert.isNotOk(err,'Promise error');
1186
- done();
1232
+ }).catch(function (err) {
1233
+ console.log("test reject", err);
1234
+ assert.isNotOk(err, 'Promise error');
1235
+ done();
1187
1236
  });
1237
+ });
1238
+ });
1188
1239
  });
1189
- });
1190
- });
1191
- });
1192
1240
 
1193
1241
 
1194
1242
 
1195
-
1196
- // mocha test/requestService.js --grep 'routeDepartmentDifferentAgentDifferentDepartment'
1197
- it('routeDepartmentDifferentAgentDifferentDepartment', function (done) {
1243
+ // mocha test/requestService.js --grep 'routeDepartmentSameAgentDifferentDepartment'
1244
+ it('routeDepartmentSameAgentDifferentDepartment', function (done) {
1198
1245
  // this.timeout(10000);
1199
-
1246
+
1200
1247
  var email = "test-route-create-" + Date.now() + "@email.com";
1201
1248
  var pwd = "pwd";
1202
-
1203
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1204
- var userid = savedUser.id;
1205
-
1206
- projectService.createAndReturnProjectAndProjectUser("routeDepartmentDifferentAgentDifferentDepartment", userid).then(function(savedProjectAndPU) {
1207
- var savedProject = savedProjectAndPU.project;
1208
-
1209
-
1210
-
1211
-
1212
- var email2 = "test-route-create-" + Date.now() + "@email.com";
1213
- var pwd2 = "pwd";
1214
-
1215
- userService.signup( email2 ,pwd2, "Test Firstname", "Test lastname").then(function(savedUser2) {
1216
- var userid2 = savedUser2.id;
1217
1249
 
1250
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1251
+ var userid = savedUser.id;
1218
1252
 
1219
- var newProject_user = new Project_user({
1220
- // _id: new mongoose.Types.ObjectId(),
1221
- id_project: savedProject._id.toString(),
1222
- id_user: savedUser2._id.toString(),
1223
- role: "agent",
1224
- user_available: true,
1225
- createdBy: userid,
1226
- updatedBy: userid
1227
- });
1228
-
1229
- newProject_user.save(function (err, savedProject_user) {
1230
-
1231
- if (err) {
1232
- console.log("err",err)
1233
- }
1234
- var now = Date.now();
1253
+ projectService.createAndReturnProjectAndProjectUser("routeDepartmentSameAgentDifferentDepartment", userid).then(function (savedProjectAndPU) {
1254
+ var savedProject = savedProjectAndPU.project;
1255
+ var now = Date.now();
1235
1256
 
1236
- requestService.createWithIdAndRequester("routeDepartmentDifferentAgentDifferentDepartment-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
1257
+ requestService.createWithIdAndRequester("routeDepartmentSameAgentDifferentDepartment-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1237
1258
  winston.debug("resolve savedRequest");
1238
- expect(savedRequest.request_id).to.equal("routeDepartmentDifferentAgentDifferentDepartment-"+now);
1259
+ expect(savedRequest.request_id).to.equal("routeDepartmentSameAgentDifferentDepartment-" + now);
1239
1260
  expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1240
1261
  expect(savedRequest.first_text).to.equal("first_text");
1241
- expect(savedRequest.snapshot.agents).to.have.lengthOf(2);
1262
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(1);
1242
1263
  expect(savedRequest.status).to.equal(200);
1243
- expect(savedRequest.participants).to.have.lengthOf(1);
1244
- // expect(savedRequest.participants[0]).to.equal(userid);
1264
+ expect(savedRequest.participants).to.have.lengthOf(1);
1245
1265
  expect(savedRequest.participantsAgents).to.have.lengthOf(1);
1246
1266
  expect(savedRequest.participantsBots).to.have.lengthOf(0);
1247
- expect(savedRequest.hasBot).to.equal(false);
1267
+ expect(savedRequest.hasBot).to.equal(false);
1248
1268
  expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1249
-
1250
- console.log("savedRequest.department",savedRequest.department);
1251
- // expect(savedRequest.department.name).to.equal("Default");
1252
-
1253
1269
 
1254
- var newGroup = new Group({
1255
- name: "group1",
1256
- members: [userid2],
1257
- trashed: false,
1258
- id_project: savedProject._id,
1259
- createdBy: userid,
1260
- updatedBy: userid
1261
- });
1262
- newGroup.save(function (err, savedGroup) {
1263
- console.log("savedGroup",savedGroup)
1264
-
1265
-
1266
-
1267
- departmentService.create("AssignedDepartment-for-routeDepartmentDifferentAgentDifferentDepartment", savedProject._id, 'assigned', userid).then(function(createdDepartment) {
1270
+ console.log("savedRequest.department", savedRequest.department);
1271
+ // expect(savedRequest.department.name).to.equal("Default");
1268
1272
 
1269
-
1270
- createdDepartment.id_group = newGroup._id;
1271
- createdDepartment.save(function (err, savedGroupDepartment) {
1272
- console.log("savedGroupDepartment",savedGroupDepartment)
1273
+ departmentService.create("AssignedDepartment-for-routeDepartmentSameAgentDifferentDepartment", savedProject._id, 'assigned', userid).then(function (createdDepartment) {
1273
1274
 
1274
-
1275
1275
  // route(request_id, departmentid, id_project, nobot, no_populate) {
1276
- requestService.route("routeDepartmentDifferentAgentDifferentDepartment-"+now, createdDepartment._id, savedProject._id, false).then(function(routedRequest) {
1277
-
1278
- expect(routedRequest.request_id).to.equal("routeDepartmentDifferentAgentDifferentDepartment-"+now);
1276
+ requestService.route("routeDepartmentSameAgentDifferentDepartment-" + now, createdDepartment._id, savedProject._id, false).then(function (routedRequest) {
1277
+
1278
+ expect(routedRequest.request_id).to.equal("routeDepartmentSameAgentDifferentDepartment-" + now);
1279
1279
  expect(routedRequest.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1280
1280
  expect(routedRequest.first_text).to.equal("first_text");
1281
1281
  expect(routedRequest.snapshot.agents).to.have.lengthOf(1);
1282
1282
  expect(routedRequest.status).to.equal(200);
1283
- expect(routedRequest.participants).to.have.lengthOf(1);
1284
- expect(routedRequest.participants[0]).to.equal(userid2);
1283
+ expect(routedRequest.participants).to.have.lengthOf(1);
1285
1284
  expect(routedRequest.participantsAgents).to.have.lengthOf(1);
1286
1285
  expect(routedRequest.participantsBots).to.have.lengthOf(0);
1287
- expect(routedRequest.hasBot).to.equal(false);
1286
+ expect(routedRequest.hasBot).to.equal(false);
1288
1287
  expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1289
-
1290
- console.log("routedRequest.department.name",routedRequest.department.name);
1288
+
1289
+ console.log("routedRequest.department.name", routedRequest.department.name);
1291
1290
  expect(routedRequest.department._id.toString()).to.equal(createdDepartment._id.toString());
1292
1291
  expect(routedRequest.snapshot.department._id.toString()).to.equal(createdDepartment._id.toString());
1293
-
1292
+
1294
1293
  done();
1295
-
1294
+
1296
1295
  });
1297
-
1296
+
1297
+ }).catch(function (err) {
1298
+ console.log("test reject", err);
1299
+ assert.isNotOk(err, 'Promise error');
1300
+ done();
1298
1301
  });
1302
+ });
1303
+ });
1299
1304
  });
1300
1305
  });
1301
- });
1302
- });
1303
- });
1304
- });
1305
- });
1306
- });
1307
1306
 
1308
1307
 
1309
1308
 
1310
1309
 
1310
+ // mocha test/requestService.js --grep 'routeDepartmentDifferentAgentDifferentDepartment'
1311
+ it('routeDepartmentDifferentAgentDifferentDepartment', function (done) {
1312
+ // this.timeout(10000);
1311
1313
 
1314
+ var email = "test-route-create-" + Date.now() + "@email.com";
1315
+ var pwd = "pwd";
1312
1316
 
1317
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1318
+ var userid = savedUser.id;
1313
1319
 
1320
+ projectService.createAndReturnProjectAndProjectUser("routeDepartmentDifferentAgentDifferentDepartment", userid).then(function (savedProjectAndPU) {
1321
+ var savedProject = savedProjectAndPU.project;
1314
1322
 
1315
1323
 
1316
- it('reroute', function (done) {
1317
1324
 
1318
- var email = "test-request-reroute-" + Date.now() + "@email.com";
1319
- var pwd = "pwd";
1320
1325
 
1321
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1322
- var userid = savedUser.id;
1326
+ var email2 = "test-route-create-" + Date.now() + "@email.com";
1327
+ var pwd2 = "pwd";
1323
1328
 
1324
- projectService.createAndReturnProjectAndProjectUser("reroute-project", userid).then(function(savedProjectAndPU) {
1325
- var savedProject = savedProjectAndPU.project;
1326
- var now = Date.now();
1327
- requestService.createWithIdAndRequester("request_id1-reroute-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
1329
+ userService.signup(email2, pwd2, "Test Firstname", "Test lastname").then(function (savedUser2) {
1330
+ var userid2 = savedUser2.id;
1328
1331
 
1329
- // reroute(request_id, id_project, nobot) {
1330
- requestService.reroute(savedRequest.request_id, savedProject._id, true).then(function(savedRequestParticipant) {
1331
- winston.info("resolve", savedRequestParticipant.toObject());
1332
-
1333
- //savedRequest is assigned -> 200
1334
- expect(savedRequest.status).to.equal(200);
1335
1332
 
1336
- //savedRequestParticipant is UNASSIGNED -> 100
1337
- expect(savedRequestParticipant.request_id).to.equal("request_id1-reroute-"+now);
1338
- // expect(savedRequestParticipant.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1339
- expect(savedRequestParticipant.first_text).to.equal("first_text");
1340
- expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(1);
1341
- expect(savedRequestParticipant.status).to.equal(200);
1342
- expect(savedRequestParticipant.participants).to.have.lengthOf(1);
1343
- expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(1);
1344
- expect(savedRequestParticipant.participantsAgents).to.contains(userid);
1345
- expect(savedRequestParticipant.participantsBots).to.have.lengthOf(0);
1333
+ var newProject_user = new Project_user({
1334
+ // _id: new mongoose.Types.ObjectId(),
1335
+ id_project: savedProject._id.toString(),
1336
+ id_user: savedUser2._id.toString(),
1337
+ role: "agent",
1338
+ user_available: true,
1339
+ createdBy: userid,
1340
+ updatedBy: userid
1341
+ });
1346
1342
 
1347
- expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(1);
1348
- expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
1343
+ newProject_user.save(function (err, savedProject_user) {
1349
1344
 
1350
- expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1351
-
1352
- done();
1353
- }).catch(function(err) {
1354
- console.log("test reject", err);
1355
- assert.isNotOk(err,'Promise error');
1356
- done();
1345
+ if (err) {
1346
+ console.log("err", err)
1347
+ }
1348
+ var now = Date.now();
1349
+
1350
+ requestService.createWithIdAndRequester("routeDepartmentDifferentAgentDifferentDepartment-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1351
+ winston.debug("resolve savedRequest");
1352
+ expect(savedRequest.request_id).to.equal("routeDepartmentDifferentAgentDifferentDepartment-" + now);
1353
+ expect(savedRequest.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1354
+ expect(savedRequest.first_text).to.equal("first_text");
1355
+ expect(savedRequest.snapshot.agents).to.have.lengthOf(2);
1356
+ expect(savedRequest.status).to.equal(200);
1357
+ expect(savedRequest.participants).to.have.lengthOf(1);
1358
+ // expect(savedRequest.participants[0]).to.equal(userid);
1359
+ expect(savedRequest.participantsAgents).to.have.lengthOf(1);
1360
+ expect(savedRequest.participantsBots).to.have.lengthOf(0);
1361
+ expect(savedRequest.hasBot).to.equal(false);
1362
+ expect(savedRequest.id_project).to.equal(savedProject._id.toString());
1363
+
1364
+ console.log("savedRequest.department", savedRequest.department);
1365
+ // expect(savedRequest.department.name).to.equal("Default");
1366
+
1367
+
1368
+ var newGroup = new Group({
1369
+ name: "group1",
1370
+ members: [userid2],
1371
+ trashed: false,
1372
+ id_project: savedProject._id,
1373
+ createdBy: userid,
1374
+ updatedBy: userid
1375
+ });
1376
+ newGroup.save(function (err, savedGroup) {
1377
+ console.log("savedGroup", savedGroup)
1378
+
1379
+
1380
+
1381
+ departmentService.create("AssignedDepartment-for-routeDepartmentDifferentAgentDifferentDepartment", savedProject._id, 'assigned', userid).then(function (createdDepartment) {
1382
+
1383
+
1384
+ createdDepartment.id_group = newGroup._id;
1385
+ createdDepartment.save(function (err, savedGroupDepartment) {
1386
+ console.log("savedGroupDepartment", savedGroupDepartment)
1387
+
1388
+
1389
+ // route(request_id, departmentid, id_project, nobot, no_populate) {
1390
+ requestService.route("routeDepartmentDifferentAgentDifferentDepartment-" + now, createdDepartment._id, savedProject._id, false).then(function (routedRequest) {
1391
+
1392
+ expect(routedRequest.request_id).to.equal("routeDepartmentDifferentAgentDifferentDepartment-" + now);
1393
+ expect(routedRequest.requester._id.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1394
+ expect(routedRequest.first_text).to.equal("first_text");
1395
+ expect(routedRequest.snapshot.agents).to.have.lengthOf(1);
1396
+ expect(routedRequest.status).to.equal(200);
1397
+ expect(routedRequest.participants).to.have.lengthOf(1);
1398
+ expect(routedRequest.participants[0]).to.equal(userid2);
1399
+ expect(routedRequest.participantsAgents).to.have.lengthOf(1);
1400
+ expect(routedRequest.participantsBots).to.have.lengthOf(0);
1401
+ expect(routedRequest.hasBot).to.equal(false);
1402
+ expect(routedRequest.id_project).to.equal(savedProject._id.toString());
1403
+
1404
+ console.log("routedRequest.department.name", routedRequest.department.name);
1405
+ expect(routedRequest.department._id.toString()).to.equal(createdDepartment._id.toString());
1406
+ expect(routedRequest.snapshot.department._id.toString()).to.equal(createdDepartment._id.toString());
1407
+
1408
+ done();
1409
+
1410
+ });
1411
+
1412
+ });
1413
+ });
1414
+ });
1415
+ });
1416
+ });
1417
+ });
1357
1418
  });
1358
1419
  });
1359
1420
  });
1360
- });
1361
- });
1362
1421
 
1363
1422
 
1364
1423
 
@@ -1366,127 +1425,182 @@ it('reroute', function (done) {
1366
1425
 
1367
1426
 
1368
1427
 
1369
- it('closeRequestAndRemoveParticipant', function (done) {
1370
1428
 
1371
- var email = "test-request-create-" + Date.now() + "@email.com";
1372
- var pwd = "pwd";
1373
1429
 
1374
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1375
- var userid = savedUser.id;
1430
+ it('reroute', function (done) {
1376
1431
 
1377
- projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function(savedProjectAndPU) {
1378
- var savedProject = savedProjectAndPU.project;
1379
- var now = Date.now();
1380
- requestService.createWithIdAndRequester("request_id-closeRequestAndRemoveParticipant-"+now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function(savedRequest) {
1381
- Promise.all([
1382
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
1383
- savedProject._id, "5badfe5d553d1844ad654072"),
1384
- messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
1385
- savedProject._id, "5badfe5d553d1844ad654072")]).then(function(all) {
1386
- requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id).then(function(closedRequest) {
1387
- expect(closedRequest.closed_at).to.not.equal(null);
1388
- expect(closedRequest.transcript).to.contains("hello1");
1389
- expect(closedRequest.transcript).to.contains("hello2");
1390
-
1391
- requestService.removeParticipantByRequestId(savedRequest.request_id, savedProject._id, userid).then(function(savedRequestParticipant) {
1392
- winston.debug("resolve closeRequestAndRemoveParticipant", closedRequest.toObject());
1393
- expect(savedRequestParticipant.status).to.equal(1000);
1394
-
1395
- done();
1396
- });
1397
- }).catch(function(err){
1398
- winston.error("test reject", err);
1399
- assert.isNotOk(err,'Promise error');
1400
- done();
1401
- });
1432
+ var email = "test-request-reroute-" + Date.now() + "@email.com";
1433
+ var pwd = "pwd";
1434
+
1435
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1436
+ var userid = savedUser.id;
1437
+
1438
+ projectService.createAndReturnProjectAndProjectUser("reroute-project", userid).then(function (savedProjectAndPU) {
1439
+ var savedProject = savedProjectAndPU.project;
1440
+ var now = Date.now();
1441
+ requestService.createWithIdAndRequester("request_id1-reroute-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1442
+
1443
+ // reroute(request_id, id_project, nobot) {
1444
+ requestService.reroute(savedRequest.request_id, savedProject._id, true).then(function (savedRequestParticipant) {
1445
+ winston.info("resolve", savedRequestParticipant.toObject());
1446
+
1447
+ //savedRequest is assigned -> 200
1448
+ expect(savedRequest.status).to.equal(200);
1449
+
1450
+ //savedRequestParticipant is UNASSIGNED -> 100
1451
+ expect(savedRequestParticipant.request_id).to.equal("request_id1-reroute-" + now);
1452
+ // expect(savedRequestParticipant.requester.toString()).to.equal(savedProjectAndPU.project_user._id.toString());
1453
+ expect(savedRequestParticipant.first_text).to.equal("first_text");
1454
+ expect(savedRequestParticipant.snapshot.agents).to.have.lengthOf(1);
1455
+ expect(savedRequestParticipant.status).to.equal(200);
1456
+ expect(savedRequestParticipant.participants).to.have.lengthOf(1);
1457
+ expect(savedRequestParticipant.participantsAgents).to.have.lengthOf(1);
1458
+ expect(savedRequestParticipant.participantsAgents).to.contains(userid);
1459
+ expect(savedRequestParticipant.participantsBots).to.have.lengthOf(0);
1460
+
1461
+ expect(savedRequestParticipant.participatingAgents).to.have.lengthOf(1);
1462
+ expect(savedRequestParticipant.participatingBots).to.have.lengthOf(0);
1463
+
1464
+ expect(savedRequestParticipant.id_project).to.equal(savedProject._id.toString());
1465
+
1466
+ done();
1467
+ }).catch(function (err) {
1468
+ console.log("test reject", err);
1469
+ assert.isNotOk(err, 'Promise error');
1470
+ done();
1402
1471
  });
1472
+ });
1403
1473
  });
1404
1474
  });
1405
- });
1406
- });
1475
+ });
1407
1476
 
1408
1477
 
1409
1478
 
1410
1479
 
1411
- it('addTag', function (done) {
1412
- // this.timeout(10000);
1413
- var email = "test-request-create-" + Date.now() + "@email.com";
1414
- var pwd = "pwd";
1415
1480
 
1416
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1417
- var userid = savedUser.id;
1418
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
1419
- var savedProject = savedProjectAndPU.project;
1420
1481
 
1421
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
1422
- var now = Date.now();
1423
- requestService.createWithIdAndRequester("request_id1-addTag-"+now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
1424
- winston.debug("resolve", savedRequest.toObject());
1425
- expect(savedRequest.request_id).to.equal("request_id1-addTag-"+now);
1426
- expect(savedRequest.tags.length).to.equal(0);
1427
-
1428
- var tag = {tag:"tag1"};
1429
- requestService.addTagByRequestId("request_id1-addTag-"+now, savedProject._id, tag).then(function(savedReqTag) {
1430
- expect(savedReqTag.request_id).to.equal("request_id1-addTag-"+now);
1431
- expect(savedReqTag.tags.length).to.equal(1);
1432
- expect(savedReqTag.tags[0].tag).to.equal("tag1");
1433
- done();
1434
- });
1435
1482
 
1436
-
1437
- }).catch(function(err) {
1438
- console.log("test reject",err);
1439
- assert.isNotOk(err,'Promise error');
1440
- done();
1483
+ it('closeRequestAndRemoveParticipant', function (done) {
1484
+
1485
+ var email = "test-request-create-" + Date.now() + "@email.com";
1486
+ var pwd = "pwd";
1487
+
1488
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1489
+ var userid = savedUser.id;
1490
+
1491
+ projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
1492
+ var savedProject = savedProjectAndPU.project;
1493
+ var now = Date.now();
1494
+ requestService.createWithIdAndRequester("request_id-closeRequestAndRemoveParticipant-" + now, savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
1495
+ Promise.all([
1496
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello1",
1497
+ savedProject._id, "5badfe5d553d1844ad654072"),
1498
+ messageService.create("5badfe5d553d1844ad654072", "test sender", savedRequest.request_id, "hello2",
1499
+ savedProject._id, "5badfe5d553d1844ad654072")]).then(function (all) {
1500
+ requestService.closeRequestByRequestId(savedRequest.request_id, savedProject._id).then(function (closedRequest) {
1501
+ expect(closedRequest.closed_at).to.not.equal(null);
1502
+ expect(closedRequest.transcript).to.contains("hello1");
1503
+ expect(closedRequest.transcript).to.contains("hello2");
1504
+
1505
+ requestService.removeParticipantByRequestId(savedRequest.request_id, savedProject._id, userid).then(function (savedRequestParticipant) {
1506
+ winston.debug("resolve closeRequestAndRemoveParticipant", closedRequest.toObject());
1507
+ expect(savedRequestParticipant.status).to.equal(1000);
1508
+
1509
+ done();
1510
+ });
1511
+ }).catch(function (err) {
1512
+ winston.error("test reject", err);
1513
+ assert.isNotOk(err, 'Promise error');
1514
+ done();
1515
+ });
1516
+ });
1517
+ });
1441
1518
  });
1519
+ });
1442
1520
  });
1443
- });
1444
- });
1445
- });
1446
1521
 
1447
1522
 
1448
1523
 
1449
- it('removeTag', function (done) {
1450
- // this.timeout(10000);
1451
- var email = "test-request-create-" + Date.now() + "@email.com";
1452
- var pwd = "pwd";
1453
-
1454
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1455
- var userid = savedUser.id;
1456
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
1457
- var savedProject = savedProjectAndPU.project;
1458
-
1459
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
1460
- var now = Date.now();
1461
- requestService.createWithIdAndRequester("request_id1-addTag-"+now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function(savedRequest) {
1462
- winston.debug("resolve", savedRequest.toObject());
1463
- expect(savedRequest.request_id).to.equal("request_id1-addTag-"+now);
1464
- expect(savedRequest.tags.length).to.equal(0);
1465
-
1466
- var tag = {tag:"tag1"};
1467
- requestService.addTagByRequestId("request_id1-addTag-"+now, savedProject._id, tag).then(function(savedReqTag) {
1468
- expect(savedReqTag.request_id).to.equal("request_id1-addTag-"+now);
1469
- expect(savedReqTag.tags.length).to.equal(1);
1470
- expect(savedReqTag.tags[0].tag).to.equal("tag1");
1471
-
1472
- requestService.removeTagByRequestId("request_id1-addTag-"+now, savedProject._id, "tag1").then(function(savedReqTagRem) {
1473
- expect(savedReqTagRem.request_id).to.equal("request_id1-addTag-"+now);
1474
- expect(savedReqTagRem.tags.length).to.equal(0);
1524
+
1525
+ it('addTag', function (done) {
1526
+ // this.timeout(10000);
1527
+ var email = "test-request-create-" + Date.now() + "@email.com";
1528
+ var pwd = "pwd";
1529
+
1530
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1531
+ var userid = savedUser.id;
1532
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
1533
+ var savedProject = savedProjectAndPU.project;
1534
+
1535
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
1536
+ var now = Date.now();
1537
+ requestService.createWithIdAndRequester("request_id1-addTag-" + now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function (savedRequest) {
1538
+ winston.debug("resolve", savedRequest.toObject());
1539
+ expect(savedRequest.request_id).to.equal("request_id1-addTag-" + now);
1540
+ expect(savedRequest.tags.length).to.equal(0);
1541
+
1542
+ var tag = { tag: "tag1" };
1543
+ requestService.addTagByRequestId("request_id1-addTag-" + now, savedProject._id, tag).then(function (savedReqTag) {
1544
+ expect(savedReqTag.request_id).to.equal("request_id1-addTag-" + now);
1545
+ expect(savedReqTag.tags.length).to.equal(1);
1546
+ expect(savedReqTag.tags[0].tag).to.equal("tag1");
1547
+ done();
1548
+ });
1549
+
1550
+
1551
+ }).catch(function (err) {
1552
+ console.log("test reject", err);
1553
+ assert.isNotOk(err, 'Promise error');
1475
1554
  done();
1476
1555
  });
1477
-
1478
1556
  });
1479
-
1480
-
1481
- }).catch(function(err) {
1482
- console.log("test reject",err);
1483
- assert.isNotOk(err,'Promise error');
1484
- done();
1485
1557
  });
1558
+ });
1486
1559
  });
1487
- });
1560
+
1561
+
1562
+
1563
+ it('removeTag', function (done) {
1564
+ // this.timeout(10000);
1565
+ var email = "test-request-create-" + Date.now() + "@email.com";
1566
+ var pwd = "pwd";
1567
+
1568
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1569
+ var userid = savedUser.id;
1570
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
1571
+ var savedProject = savedProjectAndPU.project;
1572
+
1573
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
1574
+ var now = Date.now();
1575
+ requestService.createWithIdAndRequester("request_id1-addTag-" + now, savedProjectAndPU.project_user._id, createdLead._id, savedProject._id, "first_text").then(function (savedRequest) {
1576
+ winston.debug("resolve", savedRequest.toObject());
1577
+ expect(savedRequest.request_id).to.equal("request_id1-addTag-" + now);
1578
+ expect(savedRequest.tags.length).to.equal(0);
1579
+
1580
+ var tag = { tag: "tag1" };
1581
+ requestService.addTagByRequestId("request_id1-addTag-" + now, savedProject._id, tag).then(function (savedReqTag) {
1582
+ expect(savedReqTag.request_id).to.equal("request_id1-addTag-" + now);
1583
+ expect(savedReqTag.tags.length).to.equal(1);
1584
+ expect(savedReqTag.tags[0].tag).to.equal("tag1");
1585
+
1586
+ requestService.removeTagByRequestId("request_id1-addTag-" + now, savedProject._id, "tag1").then(function (savedReqTagRem) {
1587
+ expect(savedReqTagRem.request_id).to.equal("request_id1-addTag-" + now);
1588
+ expect(savedReqTagRem.tags.length).to.equal(0);
1589
+ done();
1590
+ });
1591
+
1592
+ });
1593
+
1594
+
1595
+ }).catch(function (err) {
1596
+ console.log("test reject", err);
1597
+ assert.isNotOk(err, 'Promise error');
1598
+ done();
1599
+ });
1600
+ });
1601
+ });
1602
+ });
1488
1603
  });
1489
- });
1490
1604
 
1491
1605
 
1492
1606
 
@@ -1495,55 +1609,56 @@ it('removeTag', function (done) {
1495
1609
 
1496
1610
 
1497
1611
 
1498
- // mocha test/requestService.js --grep 'createMessageMicroLanguageAttributes'
1612
+ // mocha test/requestService.js --grep 'createMessageMicroLanguageAttributes'
1613
+
1614
+ it('createMessageMicroLanguageAttributes', function (done) {
1615
+ // this.timeout(10000);
1616
+
1617
+
1618
+ var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor');
1619
+ // var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
1620
+ console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor);
1621
+ microLanguageTransformerInterceptor.listen();
1622
+
1623
+
1624
+
1625
+ var email = "test-request-create-" + Date.now() + "@email.com";
1626
+ var pwd = "pwd";
1499
1627
 
1500
- it('createMessageMicroLanguageAttributes', function (done) {
1501
- // this.timeout(10000);
1502
-
1503
-
1504
- var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor');
1505
- // var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
1506
- console.log("microLanguageTransformerInterceptor",microLanguageTransformerInterceptor);
1507
- microLanguageTransformerInterceptor.listen();
1508
-
1509
-
1510
-
1511
- var email = "test-request-create-" + Date.now() + "@email.com";
1512
- var pwd = "pwd";
1628
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1629
+ var userid = savedUser.id;
1513
1630
 
1514
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1515
- var userid = savedUser.id;
1516
-
1517
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
1518
- var savedProject = savedProjectAndPU.project;
1519
-
1520
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
1521
- var now = Date.now();
1522
- var request = {
1523
- request_id:"request_idcreateMessageMicroLanguageAttributes-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
1524
- id_project:savedProject._id, first_text: "first_text",
1525
- participants: [userid],
1526
- lead:createdLead, requester: savedProjectAndPU.project_user };
1527
-
1528
- requestService.create(request).then(function(savedRequest) {
1529
- winston.info("resolve", savedRequest.toObject());
1631
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
1632
+ var savedProject = savedProjectAndPU.project;
1633
+
1634
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
1635
+ var now = Date.now();
1636
+ var request = {
1637
+ request_id: "request_idcreateMessageMicroLanguageAttributes-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
1638
+ id_project: savedProject._id, first_text: "first_text",
1639
+ participants: [userid],
1640
+ lead: createdLead, requester: savedProjectAndPU.project_user
1641
+ };
1642
+
1643
+ requestService.create(request).then(function (savedRequest) {
1644
+ winston.info("resolve", savedRequest.toObject());
1530
1645
 
1531
1646
  // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
1532
1647
  messageService.create(userid, "test sender", "testrecipient-createMessageMicroLanguageFromBot", "ciao\n* Button1",
1533
- savedProject._id, userid, undefined, {microlanguage:true}).then(function(savedMessage){
1648
+ savedProject._id, userid, undefined, { microlanguage: true }).then(function (savedMessage) {
1534
1649
  winston.debug("resolve savedMessage", savedMessage.toObject());
1535
-
1536
- expect(savedMessage.text).to.equal("ciao");
1537
- expect(savedMessage.type).to.equal("text");
1538
- expect(savedMessage.attributes._raw_message).to.equal("ciao\n* Button1","attachment");
1539
- expect(savedMessage.attributes.attachment.type).to.equal("template");
1540
- expect(savedMessage.attributes.attachment.buttons[0].value).to.equal("Button1");
1541
- expect(savedMessage.sender).to.equal(userid);
1542
- expect(savedMessage.senderFullname).to.equal("test sender");
1543
- expect(savedMessage.recipient).to.equal("testrecipient-createMessageMicroLanguageFromBot");
1544
- done();
1545
-
1546
- })
1650
+
1651
+ expect(savedMessage.text).to.equal("ciao");
1652
+ expect(savedMessage.type).to.equal("text");
1653
+ expect(savedMessage.attributes._raw_message).to.equal("ciao\n* Button1", "attachment");
1654
+ expect(savedMessage.attributes.attachment.type).to.equal("template");
1655
+ expect(savedMessage.attributes.attachment.buttons[0].value).to.equal("Button1");
1656
+ expect(savedMessage.sender).to.equal(userid);
1657
+ expect(savedMessage.senderFullname).to.equal("test sender");
1658
+ expect(savedMessage.recipient).to.equal("testrecipient-createMessageMicroLanguageFromBot");
1659
+ done();
1660
+
1661
+ })
1547
1662
  });
1548
1663
  });
1549
1664
  });
@@ -1561,59 +1676,60 @@ it('removeTag', function (done) {
1561
1676
 
1562
1677
 
1563
1678
 
1564
- // mocha test/requestService.js --grep 'createMessageMicroLanguageFromBot'
1679
+ // mocha test/requestService.js --grep 'createMessageMicroLanguageFromBot'
1565
1680
 
1566
- it('createMessageMicroLanguageFromBot', function (done) {
1567
- // this.timeout(10000);
1568
-
1569
-
1570
- // var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor');
1571
- var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
1572
- console.log("microLanguageTransformerInterceptor",microLanguageTransformerInterceptor);
1573
- microLanguageTransformerInterceptor.listen();
1574
-
1575
-
1576
-
1577
- var email = "test-request-create-" + Date.now() + "@email.com";
1578
- var pwd = "pwd";
1681
+ it('createMessageMicroLanguageFromBot', function (done) {
1682
+ // this.timeout(10000);
1579
1683
 
1580
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1581
- var userid = savedUser.id;
1582
-
1583
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
1584
- var savedProject = savedProjectAndPU.project;
1585
-
1586
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
1587
-
1588
- var now = Date.now();
1589
1684
 
1685
+ // var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor');
1686
+ var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
1687
+ console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor);
1688
+ microLanguageTransformerInterceptor.listen();
1590
1689
 
1591
- var request = {
1592
- request_id:"request_idcreateMessageMicroLanguageFromBot-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
1593
- id_project:savedProject._id, first_text: "first_text",
1594
- participants: ["bot_"+userid],
1595
- lead:createdLead, requester: savedProjectAndPU.project_user };
1596
-
1597
-
1598
- requestService.create(request).then(function(savedRequest) {
1599
- winston.info("resolve", savedRequest.toObject());
1690
+
1691
+
1692
+ var email = "test-request-create-" + Date.now() + "@email.com";
1693
+ var pwd = "pwd";
1694
+
1695
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1696
+ var userid = savedUser.id;
1697
+
1698
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
1699
+ var savedProject = savedProjectAndPU.project;
1700
+
1701
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
1702
+
1703
+ var now = Date.now();
1704
+
1705
+
1706
+ var request = {
1707
+ request_id: "request_idcreateMessageMicroLanguageFromBot-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
1708
+ id_project: savedProject._id, first_text: "first_text",
1709
+ participants: ["bot_" + userid],
1710
+ lead: createdLead, requester: savedProjectAndPU.project_user
1711
+ };
1712
+
1713
+
1714
+ requestService.create(request).then(function (savedRequest) {
1715
+ winston.info("resolve", savedRequest.toObject());
1600
1716
 
1601
1717
  // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
1602
1718
  messageService.create(userid, "test sender", "testrecipient-createMessageMicroLanguageFromBot", "ciao\n* Button1",
1603
- savedProject._id, userid, undefined, {microlanguage:true}).then(function(savedMessage){
1719
+ savedProject._id, userid, undefined, { microlanguage: true }).then(function (savedMessage) {
1604
1720
  winston.debug("resolve savedMessage", savedMessage.toObject());
1605
-
1606
- expect(savedMessage.text).to.equal("ciao");
1607
- expect(savedMessage.type).to.equal("text");
1608
- expect(savedMessage.attributes._raw_message).to.equal("ciao\n* Button1","attachment");
1609
- expect(savedMessage.attributes.attachment.type).to.equal("template");
1610
- expect(savedMessage.attributes.attachment.buttons[0].value).to.equal("Button1");
1611
- expect(savedMessage.sender).to.equal(userid);
1612
- expect(savedMessage.senderFullname).to.equal("test sender");
1613
- expect(savedMessage.recipient).to.equal("testrecipient-createMessageMicroLanguageFromBot");
1614
- done();
1615
-
1616
- })
1721
+
1722
+ expect(savedMessage.text).to.equal("ciao");
1723
+ expect(savedMessage.type).to.equal("text");
1724
+ expect(savedMessage.attributes._raw_message).to.equal("ciao\n* Button1", "attachment");
1725
+ expect(savedMessage.attributes.attachment.type).to.equal("template");
1726
+ expect(savedMessage.attributes.attachment.buttons[0].value).to.equal("Button1");
1727
+ expect(savedMessage.sender).to.equal(userid);
1728
+ expect(savedMessage.senderFullname).to.equal("test sender");
1729
+ expect(savedMessage.recipient).to.equal("testrecipient-createMessageMicroLanguageFromBot");
1730
+ done();
1731
+
1732
+ })
1617
1733
  });
1618
1734
  });
1619
1735
  });
@@ -1623,47 +1739,48 @@ it('removeTag', function (done) {
1623
1739
 
1624
1740
 
1625
1741
 
1626
- // mocha test/requestService.js --grep 'selectSnapshot'
1742
+ // mocha test/requestService.js --grep 'selectSnapshot'
1627
1743
 
1628
- it('selectSnapshot', function (done) {
1629
- // this.timeout(10000);
1630
- // return new Promise(function (resolve) {
1631
- var email = "test-request-create-" + Date.now() + "@email.com";
1632
- var pwd = "pwd";
1744
+ it('selectSnapshot', function (done) {
1745
+ // this.timeout(10000);
1746
+ // return new Promise(function (resolve) {
1747
+ var email = "test-request-create-" + Date.now() + "@email.com";
1748
+ var pwd = "pwd";
1633
1749
 
1634
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1635
- var userid = savedUser.id;
1636
-
1637
- projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function(savedProjectAndPU) {
1638
- var savedProject = savedProjectAndPU.project;
1750
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1751
+ var userid = savedUser.id;
1639
1752
 
1640
- leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function(createdLead) {
1641
-
1642
- var now = Date.now();
1753
+ projectService.createAndReturnProjectAndProjectUser("createWithId", userid).then(function (savedProjectAndPU) {
1754
+ var savedProject = savedProjectAndPU.project;
1643
1755
 
1644
- var request = {
1645
- request_id:"request_idselectSnapshot-"+now, project_user_id:savedProjectAndPU.project_user._id, lead_id:createdLead._id,
1646
- id_project:savedProject._id, first_text: "first_text",
1647
- participants: ["bot_"+userid],
1648
- lead:createdLead, requester: savedProjectAndPU.project_user };
1756
+ leadService.createIfNotExists("leadfullname", "email@email.com", savedProject._id).then(function (createdLead) {
1649
1757
 
1650
- requestService.create(request).then(async function(savedRequest) {
1651
- winston.info("resolve", savedRequest.toObject());
1758
+ var now = Date.now();
1652
1759
 
1653
- var snapshotAgents = await Request.findById(savedRequest.id).select({"snapshot":1}).exec();
1760
+ var request = {
1761
+ request_id: "request_idselectSnapshot-" + now, project_user_id: savedProjectAndPU.project_user._id, lead_id: createdLead._id,
1762
+ id_project: savedProject._id, first_text: "first_text",
1763
+ participants: ["bot_" + userid],
1764
+ lead: createdLead, requester: savedProjectAndPU.project_user
1765
+ };
1654
1766
 
1655
- console.log("snapshotAgents",snapshotAgents);
1767
+ requestService.create(request).then(async function (savedRequest) {
1768
+ winston.info("resolve", savedRequest.toObject());
1656
1769
 
1657
- expect(snapshotAgents.snapshot.agents.length).to.equal(1);
1658
- // return;
1659
- done();
1770
+ var snapshotAgents = await Request.findById(savedRequest.id).select({ "snapshot": 1 }).exec();
1660
1771
 
1661
- });
1772
+ console.log("snapshotAgents", snapshotAgents);
1773
+
1774
+ expect(snapshotAgents.snapshot.agents.length).to.equal(1);
1775
+ // return;
1776
+ done();
1777
+
1778
+ });
1779
+ });
1662
1780
  });
1663
1781
  });
1782
+ // });
1664
1783
  });
1665
- // });
1666
- });
1667
1784
 
1668
1785
  });
1669
1786