@tiledesk/tiledesk-server 2.1.40 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/.circleci/config.yml +54 -0
  2. package/.env.sample +1 -1
  3. package/.github/workflows/docker-community-push-latest.yml +22 -0
  4. package/.github/workflows/{docker-image-push.yml → docker-image-en-tag-push.yml} +1 -1
  5. package/.github/workflows/docker-image-tag-community-tag-push.yml +21 -0
  6. package/.github/workflows/{docker-push-latest.yml → docker-push-en-push-latest.yml} +1 -1
  7. package/CHANGELOG.md +195 -1
  8. package/Dockerfile +1 -1
  9. package/Dockerfile-en +1 -1
  10. package/README.md +5 -7
  11. package/app.js +12 -1
  12. package/channels/channelManager.js +1 -1
  13. package/channels/chat21/chat21Contact.js +34 -8
  14. package/channels/chat21/chat21Handler.js +48 -5
  15. package/channels/chat21/chat21WebHook.js +34 -9
  16. package/channels/chat21/nativeauth.js +2 -2
  17. package/channels/chat21/package-lock.json +3013 -0
  18. package/config/email.js +2 -0
  19. package/config/global.js +3 -0
  20. package/config/labels/widget.json +170 -16
  21. package/event/messageEvent.js +18 -1
  22. package/middleware/passport.js +10 -4
  23. package/migrations/1619185894304-request-remove-duplicated-request-by-request_id--autosync.js +67 -0
  24. package/models/actionsConstants.js +7 -0
  25. package/models/department.js +3 -0
  26. package/models/faq.js +8 -2
  27. package/models/faq_kb.js +6 -0
  28. package/models/message.js +10 -4
  29. package/models/messageConstants.js +9 -3
  30. package/models/request.js +33 -3
  31. package/package.json +31 -28
  32. package/pubmodules/emailNotification/requestNotification.js +483 -56
  33. package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
  34. package/pubmodules/messageTransformer/index.js +5 -1
  35. package/pubmodules/messageTransformer/messageTransformerInterceptor.js +4 -2
  36. package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
  37. package/pubmodules/messageTransformer/microLanguageTransformerInterceptor.js +67 -0
  38. package/pubmodules/pubModulesManager.js +66 -13
  39. package/pubmodules/rules/conciergeBot.js +81 -49
  40. package/routes/auth.js +46 -11
  41. package/routes/campaigns.js +117 -25
  42. package/routes/department.js +2 -2
  43. package/routes/faq.js +19 -0
  44. package/routes/faq_kb.js +13 -4
  45. package/routes/faqpub.js +1 -1
  46. package/routes/files.js +17 -2
  47. package/routes/images.js +1 -1
  48. package/routes/jwt.js +0 -1
  49. package/routes/logs.js +26 -0
  50. package/routes/message.js +7 -2
  51. package/routes/messagesRoot.js +73 -16
  52. package/routes/project_user.js +36 -1
  53. package/routes/request.js +88 -12
  54. package/routes/requestUtilRoot.js +30 -0
  55. package/routes/urls.js +12 -0
  56. package/routes/users.js +5 -1
  57. package/services/BotSubscriptionNotifier.js +1 -0
  58. package/services/departmentService.js +29 -5
  59. package/services/emailService.js +1170 -239
  60. package/services/faqBotHandler.js +176 -61
  61. package/services/faqBotSupport.js +182 -117
  62. package/services/faqService.js +18 -14
  63. package/services/messageService.js +57 -9
  64. package/services/modulesManager.js +86 -23
  65. package/services/requestService.js +58 -17
  66. package/template/email/assignedEmailMessage.html +205 -0
  67. package/template/email/assignedRequest.html +44 -14
  68. package/template/email/beenInvitedExistingUser.html +2 -2
  69. package/template/email/beenInvitedNewUser.html +1 -1
  70. package/template/email/newMessage.html +31 -12
  71. package/template/email/passwordChanged.html +2 -3
  72. package/template/email/pooledEmailMessage.html +208 -0
  73. package/template/email/pooledRequest.html +41 -14
  74. package/template/email/resetPassword.html +2 -3
  75. package/template/email/sendTranscript.html +1 -1
  76. package/template/email/test.html +1 -1
  77. package/template/email/ticket.html +191 -0
  78. package/template/email/ticket.txt +11 -0
  79. package/template/email/verify.html +1 -1
  80. package/test/authentication.js +76 -4
  81. package/test/authenticationJwt.js +76 -2
  82. package/test/campaignsRoute.js +226 -0
  83. package/test/faqService.js +3 -3
  84. package/test/faqkbRoute.js +3 -2
  85. package/test/messageRootRoute.js +193 -0
  86. package/test/messageRoute.js +75 -0
  87. package/test/messageService.js +39 -2
  88. package/test/requestRoute.js +27 -9
  89. package/test/requestService.js +472 -11
  90. package/test-int/bot.js +673 -8
  91. package/websocket/webSocketServer.js +7 -4
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
2
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
3
3
 
4
4
  <body>
5
5
  Hi {{user.name}}, this is a test email from Tiledesk
@@ -0,0 +1,191 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
3
+
4
+ <head>
5
+ <meta name="viewport" content="width=device-width" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
7
+ <title>New Ticket from TileDesk</title>
8
+
9
+ <style type="text/css">
10
+ img {
11
+ max-width: 100%;
12
+ margin-left:16px;
13
+ margin-bottom:16px;
14
+ text-align:center !important;
15
+ }
16
+ body {
17
+ -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em;
18
+ }
19
+ body {
20
+ background-color: #f6f6f6;
21
+ }
22
+
23
+ @media only screen and (max-width: 640px) {
24
+ body {
25
+ padding: 0 !important;
26
+ }
27
+ h1 {
28
+ font-weight: 800 !important; margin: 20px 0 5px !important;
29
+ text-align:center !important;
30
+ }
31
+ h2 {
32
+ font-weight: 800 !important; margin: 20px 0 5px !important;
33
+ }
34
+ h3 {
35
+ font-weight: 800 !important; margin: 20px 0 5px !important;
36
+ }
37
+ h4 {
38
+ font-weight: 800 !important; margin: 20px 0 5px !important;
39
+ }
40
+ h1 {
41
+ font-size: 22px !important;
42
+ }
43
+ h2 {
44
+ font-size: 18px !important;
45
+ }
46
+ h3 {
47
+ font-size: 16px !important;
48
+ }
49
+ .container {
50
+ padding: 0 !important; width: 100% !important;
51
+ }
52
+ .content {
53
+ padding: 0 !important;
54
+ }
55
+ .content-wrap {
56
+ padding: 10px !important;
57
+ }
58
+ .invoice {
59
+ width: 100% !important;
60
+ }
61
+ }
62
+ </style>
63
+ </head>
64
+
65
+ <body itemscope itemtype="http://schema.org/EmailMessage" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6">
66
+
67
+ {{#if baseScope.replyEnabled}}
68
+ <div>\# Please type your reply above this line \#</div>
69
+ {{/if}}
70
+
71
+ <table class="main" width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;" bgcolor="#fff">
72
+
73
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
74
+ <td class="alert alert-warning" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; font-weight: 500; text-align: center; border-radius: 3px 3px 0 0; margin: 0;" align="center" valign="top">
75
+
76
+ <div style="text-align:center">
77
+ <a href="http://www.tiledesk.com" style="color:#2daae1;font-weight:bold;text-decoration:none;word-break:break-word" target="_blank">
78
+ <img src="https://tiledesk.com/tiledesk-logo-x1.png" style="width:20%;outline:none;text-decoration:none;border:none;min-height:36px" class="CToWUd">
79
+ </a>
80
+ </div>
81
+ </td>
82
+ </tr>
83
+
84
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
85
+
86
+ <td class="alert alert-warning" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; font-weight: 500; text-align: center; border-radius: 3px 3px 0 0; margin: 0;" align="center" valign="top">
87
+ <div>
88
+ <h2>Ticket number: #{{message.request.ticket_id}}</h2>
89
+ </div>
90
+
91
+ </td>
92
+ </tr>
93
+
94
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
95
+ <td class="content-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 20px;" valign="top">
96
+ <table width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
97
+
98
+
99
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
100
+ <td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
101
+ Sender: <strong style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">{{message.senderFullname}}</strong>
102
+ </td>
103
+ </tr>
104
+
105
+
106
+
107
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
108
+ <td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
109
+ {{#ifEquals message.type "text"}}
110
+ <div style="white-space: pre-wrap;">{{{msgText}}}</div>
111
+ {{/ifEquals}}
112
+ {{#ifEquals message.type "image"}}
113
+ <img src="{{message.metadata.src}}"/>
114
+ {{#if msgText}}
115
+ <div style="white-space: pre-wrap;">{{{msgText}}}</div>
116
+ {{/if}}
117
+ {{/ifEquals}}
118
+ {{#ifEquals message.type "file"}}
119
+ <a href="{{message.metadata.src}}">{{message.metadata.name}}</a>
120
+ {{/ifEquals}}
121
+ {{#ifEquals message.type "frame"}}
122
+ <a href="{{message.metadata.src}}">{{message.metadata.name}}</a>
123
+ {{#if msgText}}
124
+ <div style="white-space: pre-wrap;">{{{msgText}}}</div>
125
+ {{/if}}
126
+ {{/ifEquals}}
127
+
128
+ {{#if message.attributes}}
129
+ {{#if message.attributes.attachment}}
130
+ {{#if message.attributes.attachment.buttons}}
131
+ {{#each message.attributes.attachment.buttons}}
132
+ {{#ifEquals this.type "url"}}
133
+ <li><a href="{{this.link}}" class="dynamic_button">{{this.value}}</a></li>
134
+ {{else}}
135
+ <li><a href="mailto:{{../message.request.request_id}}@{{../baseScope.inboundDomain}}?subject=Re:%20{{../message.request.subject}}&body={{this.value}}" class="dynamic_button">{{this.value}}</a></li>
136
+ {{/ifEquals}}
137
+ {{/each}}
138
+
139
+
140
+ {{/if}}
141
+ {{/if}}
142
+ {{/if}}
143
+
144
+ <!-- {{#if message.attributes.intent_info}}
145
+ {{#if message.attributes.intent_info.others}}
146
+ Others:
147
+ {{#each message.attributes.intent_info.others}}
148
+ <li><span>{{this.answer}}</span></li>
149
+ {{/each}}
150
+ {{/if}}
151
+ {{/if}} -->
152
+
153
+
154
+
155
+
156
+
157
+ </td>
158
+ </tr>
159
+
160
+
161
+
162
+
163
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
164
+ <td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
165
+
166
+ Click <a href="{{seamlessPage}}{{tokenQueryString}}">here</a> to continue by chat the conversation.
167
+ </td>
168
+ </tr>
169
+
170
+
171
+
172
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
173
+ <td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
174
+ </td>
175
+ </tr>
176
+ </table>
177
+ </td>
178
+ </tr>
179
+ </table>
180
+ <div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
181
+ <table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
182
+ <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
183
+ <td class="aligncenter content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; vertical-align: top; color: #999; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top">
184
+ <span><a href="http://www.tiledesk.com" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;" > Tiledesk.com </a></span>
185
+ <!-- <br><span><a href="%unsubscribe_url%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;">Unsubscribe</a></span> -->
186
+ </td>
187
+ </tr>
188
+ </table>
189
+
190
+ </body>
191
+ </html>
@@ -0,0 +1,11 @@
1
+ \# Please type your reply above this line \#
2
+
3
+ Ticket number: #{{message.request.ticket_id}}
4
+
5
+ {{message.senderFullname}}
6
+
7
+ {{message.text}}
8
+
9
+ Continue the conversation by chat here: {{seamlessPage}}{{tokenQueryString}}
10
+
11
+ Powered by Tiledesk : https://tiledesk.com
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
2
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
3
3
 
4
4
  <head>
5
5
  <meta name="viewport" content="width=device-width" />
@@ -87,6 +87,78 @@ describe('Authentication', () => {
87
87
 
88
88
 
89
89
 
90
+
91
+
92
+ it('signinValidation', (done) => {
93
+
94
+
95
+ // this.timeout();
96
+
97
+ var email = "test-signinko-" + Date.now() + "@email.com";
98
+ var pwd = "pwd";
99
+
100
+
101
+ chai.request(server)
102
+ .post('/auth/signin' )
103
+ .send()
104
+ .end((err, res) => {
105
+ //console.log("res", res);
106
+ console.log("res.body", res.body);
107
+ res.should.have.status(422);
108
+
109
+
110
+ done();
111
+ });
112
+
113
+
114
+ });
115
+
116
+
117
+ // mocha test/authentication.js --grep 'signinLowercase'
118
+
119
+ it('signinLowercase', (done) => {
120
+
121
+
122
+ // this.timeout();
123
+
124
+ var email = "Test-SigninKO-" + Date.now() + "@email.com";
125
+ var pwd = "pwd";
126
+
127
+ userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
128
+
129
+ chai.request(server)
130
+ .post('/auth/signin' )
131
+ .send({"email":email, "password":pwd})
132
+ .end((err, res) => {
133
+ console.log("res.body", res.body);
134
+ res.should.have.status(200);
135
+ res.body.should.be.a('object');
136
+ expect(res.body.success).to.equal(true);
137
+ expect(res.body.token).to.not.equal(null);
138
+ expect(res.body.user.email).to.equal(email.toLowerCase());
139
+ expect(res.body.user.password).to.equal(undefined);
140
+
141
+
142
+
143
+ chai.request(server)
144
+ .get('/users/' )
145
+ .auth(email, pwd)
146
+ .end((err, res) => {
147
+ console.log("res.body", res.body);
148
+ res.should.have.status(200);
149
+ res.body.should.be.a('object');
150
+
151
+ done();
152
+ });
153
+
154
+ });
155
+
156
+ });
157
+
158
+ });
159
+ });
160
+
161
+
90
162
  });
91
163
 
92
164
 
@@ -129,6 +201,8 @@ describe('/signup', () => {
129
201
 
130
202
  });
131
203
 
204
+ // mocha test/authentication.js --grep 'signupUpperCaseEmail'
205
+
132
206
 
133
207
  it('signupUpperCaseEmail', (done) => {
134
208
 
@@ -153,9 +227,7 @@ describe('/signup', () => {
153
227
 
154
228
  done();
155
229
  });
156
-
157
-
158
-
230
+
159
231
  });
160
232
 
161
233
 
@@ -184,7 +256,7 @@ describe('/signup', () => {
184
256
  });
185
257
 
186
258
 
187
- });
259
+ // });
188
260
 
189
261
 
190
262
 
@@ -379,6 +379,79 @@ it('signinJWt-userYESAudYesSubject', (done) => {
379
379
 
380
380
 
381
381
 
382
+
383
+
384
+
385
+
386
+ // // mocha test/authenticationJwt.js --grep 'signinJWt-Project-external-user-YESAudYesSubjectAndRole'
387
+
388
+ // it('signinJWt-Project-external-user-YESAudYesSubjectAndRole', (done) => {
389
+
390
+
391
+ // // this.timeout();
392
+
393
+ // var email = "test-signup-" + Date.now() + "@email.com";
394
+ // var pwd = "pwd";
395
+
396
+ // userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
397
+ // // create(name, createdBy, settings)
398
+ // projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
399
+
400
+ // chai.request(server)
401
+ // .post('/'+ savedProject._id + '/keys/generate')
402
+ // .auth(email, pwd)
403
+ // .send()
404
+ // .end((err, res) => {
405
+ // //console.log("res", res);
406
+ // console.log("res.body", res.body);
407
+ // res.should.have.status(200);
408
+ // res.body.should.be.a('object');
409
+ // expect(res.body.jwtSecret).to.not.equal(null);
410
+
411
+
412
+ // var externalUserObj = {_id:"123",name:"andrea", surname:"leo",role : 'agent'};
413
+
414
+ // console.log("externalUserObj", externalUserObj);
415
+
416
+
417
+ // var signOptions = {
418
+ // subject: 'userexternal',
419
+ // audience: 'https://tiledesk.com/projects/'+savedProject._id ,
420
+ // };
421
+
422
+
423
+ // var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
424
+
425
+
426
+
427
+ // console.log("jwtToken", jwtToken);
428
+
429
+ // chai.request(server)
430
+ // .get('/testauth/noentitycheck')
431
+ // .set('Authorization', 'JWT '+jwtToken)
432
+ // .send()
433
+ // .end((err, res) => {
434
+ // console.log("res.body", res.body);
435
+ // res.should.have.status(200);
436
+
437
+ // done();
438
+ // });
439
+
440
+
441
+
442
+
443
+ // });
444
+
445
+
446
+
447
+
448
+
449
+ // });
450
+
451
+
452
+ // });
453
+ // });
454
+
382
455
  it('signinJWt-bot-YESAudYesSubject', (done) => {
383
456
 
384
457
 
@@ -389,8 +462,9 @@ it('signinJWt-userYESAudYesSubject', (done) => {
389
462
 
390
463
  userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
391
464
  // create(name, createdBy, settings)
392
- projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
393
- faqService.create("testbot", null, savedProject._id, savedUser._id, true).then(function(savedBot) {
465
+ projectService.create("test-signinJWt-user", savedUser._id).then(function(savedProject) {
466
+ // create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language) {
467
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
394
468
  var savedBotObj = savedBot.toObject();
395
469
  console.log("savedBotObj", savedBotObj);
396
470
 
@@ -0,0 +1,226 @@
1
+ //During the test the env variable is set to test
2
+ process.env.NODE_ENV = 'test';
3
+
4
+ var User = require('../models/user');
5
+ var projectService = require('../services/projectService');
6
+ var Group = require('../models/group');
7
+ var userService = require('../services/userService');
8
+
9
+ //Require the dev-dependencies
10
+ let chai = require('chai');
11
+ let chaiHttp = require('chai-http');
12
+ let server = require('../app');
13
+ let should = chai.should();
14
+ var winston = require('../config/winston');
15
+ var jwt = require('jsonwebtoken');
16
+ // chai.config.includeStack = true;
17
+
18
+ var expect = chai.expect;
19
+ var assert = chai.assert;
20
+
21
+ chai.use(chaiHttp);
22
+
23
+ describe('CampaignsRoute', () => {
24
+
25
+
26
+ // mocha test/campaignsRoute.js --grep 'directSimpleNoOut'
27
+
28
+ it('directSimpleNoOut', function (done) {
29
+
30
+ var email = "test-message-create-" + Date.now() + "@email.com";
31
+ var pwd = "pwd";
32
+
33
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
34
+ projectService.createAndReturnProjectAndProjectUser("directSimple", savedUser._id).then(function (savedProjectAndPU) {
35
+
36
+ var savedProject = savedProjectAndPU.project;
37
+ var recipient = "5f8972c82db41c003473cb03";
38
+
39
+ chai.request(server)
40
+ .post('/' + savedProject._id + '/campaigns/direct')
41
+ .auth(email, pwd)
42
+ .set('content-type', 'application/json')
43
+ .send({ "text": "ciao", "recipient": recipient })
44
+ .end(function (err, res) {
45
+ //console.log("res", res);
46
+ console.log("res.body", res.body);
47
+ res.should.have.status(200);
48
+ res.body.should.be.a('object');
49
+
50
+
51
+
52
+ expect(res.body.success).to.equal(true);
53
+
54
+
55
+ done();
56
+ });
57
+ });
58
+ });
59
+ });
60
+
61
+
62
+
63
+
64
+
65
+
66
+ // mocha test/campaignsRoute.js --grep 'directSimple'
67
+
68
+ it('directSimple', function (done) {
69
+
70
+ var email = "test-message-create-" + Date.now() + "@email.com";
71
+ var pwd = "pwd";
72
+
73
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
74
+ projectService.createAndReturnProjectAndProjectUser("directSimple", savedUser._id).then(function (savedProjectAndPU) {
75
+
76
+ var savedProject = savedProjectAndPU.project;
77
+ var recipient = "5f8972c82db41c003473cb03";
78
+
79
+ chai.request(server)
80
+ .post('/' + savedProject._id + '/campaigns/direct')
81
+ .auth(email, pwd)
82
+ .set('content-type', 'application/json')
83
+ .send({ "text": "ciao", "recipient": recipient, returnobject: true })
84
+ .end(function (err, res) {
85
+ //console.log("res", res);
86
+ console.log("res.body", res.body);
87
+ res.should.have.status(200);
88
+ res.body.should.be.a('object');
89
+
90
+ expect(res.body.channel_type).to.equal("direct");
91
+ expect(res.body.senderFullname).to.equal("Test Firstname Test lastname");
92
+ expect(res.body.sender).to.equal(savedUser._id.toString());
93
+ expect(res.body.recipient).to.equal(recipient);
94
+
95
+
96
+ // expect(res.body.success).to.equal(true);
97
+
98
+
99
+ done();
100
+ });
101
+ });
102
+ });
103
+ });
104
+
105
+
106
+
107
+
108
+ // mocha test/campaignsRoute.js --grep 'directGroupIdNoOut'
109
+
110
+ it('directGroupIdNoOut', function (done) {
111
+
112
+ var email = "test-message-create-" + Date.now() + "@email.com";
113
+ var pwd = "pwd";
114
+
115
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
116
+ projectService.createAndReturnProjectAndProjectUser("directSimple", savedUser._id).then(function (savedProjectAndPU) {
117
+
118
+ var savedProject = savedProjectAndPU.project;
119
+
120
+ var userid = savedUser._id;
121
+
122
+ var email2 = "test-message-create-" + Date.now() + "@email.com";
123
+ userService.signup(email2, pwd, "Test Firstname", "Test lastname").then(function (savedUser2) {
124
+
125
+ var newGroup = new Group({
126
+ name: "group1",
127
+ // members: ["userid1", "userid2"],
128
+ members: [userid, savedUser2._id.toString()],
129
+ trashed: false,
130
+ id_project: savedProject._id,
131
+ createdBy: userid,
132
+ updatedBy: userid
133
+ });
134
+ newGroup.save(function (err, savedGroup) {
135
+ console.log("savedGroup", savedGroup)
136
+
137
+
138
+ chai.request(server)
139
+ .post('/' + savedProject._id + '/campaigns/direct')
140
+ .auth(email, pwd)
141
+ .set('content-type', 'application/json')
142
+ .send({ "text": "ciao", "group_id": savedGroup._id.toString() })
143
+ .end(function (err, res) {
144
+ //console.log("res", res);
145
+ console.log("res.body", res.body);
146
+ res.should.have.status(200);
147
+ res.body.should.be.a('object');
148
+
149
+
150
+ expect(res.body.success).to.equal(true);
151
+
152
+
153
+ done();
154
+ });
155
+ });
156
+ });
157
+ });
158
+ });
159
+ });
160
+
161
+
162
+
163
+
164
+ // mocha test/campaignsRoute.js --grep 'directGroupId2'
165
+
166
+ it('directGroupId2', function (done) {
167
+
168
+ var email = "test-message-create-" + Date.now() + "@email.com";
169
+ var pwd = "pwd";
170
+
171
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
172
+ projectService.createAndReturnProjectAndProjectUser("directSimple", savedUser._id).then(function (savedProjectAndPU) {
173
+
174
+ var savedProject = savedProjectAndPU.project;
175
+
176
+ var userid = savedUser._id;
177
+
178
+ var email2 = "test-message-create-" + Date.now() + "@email.com";
179
+ userService.signup(email2, pwd, "Test Firstname", "Test lastname").then(function (savedUser2) {
180
+
181
+ var newGroup = new Group({
182
+ name: "group1",
183
+ // members: ["userid1", "userid2"],
184
+ members: [userid, savedUser2._id.toString()],
185
+ trashed: false,
186
+ id_project: savedProject._id,
187
+ createdBy: userid,
188
+ updatedBy: userid
189
+ });
190
+ newGroup.save(function (err, savedGroup) {
191
+ console.log("savedGroup", savedGroup)
192
+
193
+
194
+ chai.request(server)
195
+ .post('/' + savedProject._id + '/campaigns/direct')
196
+ .auth(email, pwd)
197
+ .set('content-type', 'application/json')
198
+ .send({ "text": "ciao", "group_id": savedGroup._id.toString(), returnobject: true })
199
+ .end(function (err, res) {
200
+ //console.log("res", res);
201
+ console.log("res.body", res.body);
202
+ res.should.have.status(200);
203
+ res.body.should.be.a('array');
204
+
205
+ expect(res.body.length).to.equal(2);
206
+ expect(res.body[0].recipient).to.equal(userid.toString());
207
+ expect(res.body[1].recipient).to.equal(savedUser2._id.toString());
208
+ // expect(res.body.success).to.equal(true);
209
+
210
+
211
+ done();
212
+ });
213
+ });
214
+ });
215
+ });
216
+ });
217
+ });
218
+
219
+
220
+
221
+
222
+
223
+
224
+ });
225
+
226
+
@@ -28,7 +28,7 @@ describe('FaqService()', function () {
28
28
 
29
29
  userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
30
30
  projectService.create("test-FaqService", savedUser._id).then(function(savedProject) {
31
- faqService.create("testbot", null, savedProject._id, savedUser._id, true).then(function(savedBot) {
31
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
32
32
 
33
33
  var newFaq = new Faq({
34
34
  id_faq_kb: savedBot._id,
@@ -94,7 +94,7 @@ it('create-with-intent_display_name-and-search', (done) => {
94
94
 
95
95
  userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
96
96
  projectService.create("test-FaqService", savedUser._id).then(function(savedProject) {
97
- faqService.create("testbot", null, savedProject._id, savedUser._id, true).then(function(savedBot) {
97
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
98
98
 
99
99
  var newFaq = new Faq({
100
100
  id_faq_kb: savedBot._id,
@@ -162,7 +162,7 @@ it('create-with-duplicated-intent_display_name-and-search', (done) => {
162
162
 
163
163
  userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
164
164
  projectService.create("test-FaqService", savedUser._id).then(function(savedProject) {
165
- faqService.create("testbot", null, savedProject._id, savedUser._id, true).then(function(savedBot) {
165
+ faqService.create("testbot", null, savedProject._id, savedUser._id).then(function(savedBot) {
166
166
 
167
167
  var newFaq0 = new Faq({
168
168
  id_faq_kb: savedBot._id,