@tiledesk/tiledesk-server 2.10.15 → 2.10.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/app.js +2 -1
  3. package/models/request.js +8 -0
  4. package/package.json +4 -3
  5. package/pubmodules/activities/test/activityRoute.js +6 -2
  6. package/pubmodules/events/test/eventRoute.js +7 -3
  7. package/pubmodules/pubModulesManager.js +24 -0
  8. package/pubmodules/voice-twilio/index.js +6 -0
  9. package/pubmodules/voice-twilio/listener.js +59 -0
  10. package/routes/campaigns.js +1 -1
  11. package/routes/files.js +6 -4
  12. package/routes/images.js +0 -2
  13. package/routes/kb.js +7 -1
  14. package/routes/users.js +2 -2
  15. package/services/fileGridFsService.js +12 -10
  16. package/services/requestService.js +2 -1
  17. package/test/app-test.js +36 -1
  18. package/test/authentication.js +662 -796
  19. package/test/authenticationJwt.js +213 -315
  20. package/test/authorization.js +53 -72
  21. package/test/campaignsRoute.js +42 -47
  22. package/test/cannedRoute.js +30 -16
  23. package/test/departmentService.js +222 -274
  24. package/test/example.json +31 -1
  25. package/test/faqRoute.js +713 -622
  26. package/test/faqService.js +124 -159
  27. package/test/faqkbRoute.js +128 -100
  28. package/test/fileRoute.js +50 -46
  29. package/test/imageRoute.js +263 -254
  30. package/test/jwtRoute.js +128 -153
  31. package/test/kbRoute.js +40 -17
  32. package/test/kbsettingsRoute.js +78 -54
  33. package/test/keysRoute.js +6 -7
  34. package/test/labelRoute.js +591 -696
  35. package/test/labelService.js +40 -47
  36. package/test/leadService.js +100 -115
  37. package/test/logsRoute.js +13 -7
  38. package/test/messageRootRoute.js +112 -102
  39. package/test/messageRoute.js +1171 -1419
  40. package/test/messageService.js +41 -43
  41. package/test/openaiRoute.js +5 -1
  42. package/test/projectRoute.js +23 -4
  43. package/test/projectService.js +3 -1
  44. package/test/quoteManager.js +36 -13
  45. package/test/requestRoute.js +103 -72
  46. package/test/requestService.js +51 -51
  47. package/test/userRoute.js +37 -8
  48. package/test/userService.js +34 -31
  49. package/utils/promiseUtil.js +1 -1
package/test/faqRoute.js CHANGED
@@ -1,5 +1,6 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
+ process.env.LOG_LEVEL = 'critical';
3
4
 
4
5
  var User = require('../models/user');
5
6
  var projectService = require('../services/projectService');
@@ -28,718 +29,808 @@ chai.use(chaiHttp);
28
29
 
29
30
  describe('FaqKBRoute', () => {
30
31
 
31
- describe('/create', () => {
32
+ it('create', (done) => {
32
33
 
33
- it('create', (done) => {
34
+ // this.timeout();
34
35
 
35
- // this.timeout();
36
+ var email = "test-signup-" + Date.now() + "@email.com";
37
+ var pwd = "pwd";
36
38
 
37
- var email = "test-signup-" + Date.now() + "@email.com";
38
- var pwd = "pwd";
39
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
40
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
39
41
 
40
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
41
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
42
+ chai.request(server)
43
+ .post('/' + savedProject._id + '/faq_kb')
44
+ .auth(email, pwd)
45
+ .send({ "name": "testbot", type: "internal" })
46
+ .end((err, res) => {
42
47
 
48
+ if (err) { console.error("err: ", err); }
49
+ if (log) { console.log("create bot res.body", res.body); }
43
50
 
44
- console.log("#### savedProject: ", savedProject)
45
- chai.request(server)
46
- .post('/' + savedProject._id + '/faq_kb')
47
- .auth(email, pwd)
48
- .send({ "name": "testbot", type: "internal" })
49
- .end((err, res) => {
50
- if (log) { console.log("create bot res.body", res.body); }
51
- res.should.have.status(200);
52
- res.body.should.be.a('object');
53
- expect(res.body.name).to.equal("testbot");
54
- expect(res.body.public).to.exist;
55
- expect(res.body.public).to.equal(false);
56
- var id_faq_kb = res.body._id;
51
+ res.should.have.status(200);
52
+ res.body.should.be.a('object');
53
+ expect(res.body.name).to.equal("testbot");
54
+ expect(res.body.public).to.exist;
55
+ expect(res.body.public).to.equal(false);
56
+ var id_faq_kb = res.body._id;
57
57
 
58
- chai.request(server)
59
- .post('/' + savedProject._id + '/faq')
60
- .auth(email, pwd)
61
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: { one: "one", two: "two"}, attr2: {three: "three"}}, intent_id: 'custom-intent-id' }) // if intent_id is null the value will be the default one
62
- .end((err, res) => {
63
- if (log) { console.log("create intent res.body", res.body); }
64
- res.should.have.status(200);
65
- res.body.should.be.a('object');
66
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
67
- expect(res.body.question).to.equal("question1");
68
- expect(res.body.answer).to.equal("answer1");
69
- expect(res.body.intent_display_name).to.not.equal(undefined);
70
- expect(res.body.webhook_enabled).to.equal(false);
58
+ chai.request(server)
59
+ .post('/' + savedProject._id + '/faq')
60
+ .auth(email, pwd)
61
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: { one: "one", two: "two"}, attr2: {three: "three"}}, intent_id: 'custom-intent-id' }) // if intent_id is null the value will be the default one
62
+ .end((err, res) => {
71
63
 
72
- done();
73
- });
64
+ if (err) { console.error("err: ", err); }
65
+ if (log) { console.log("create intent res.body", res.body); }
74
66
 
75
- });
67
+ res.should.have.status(200);
68
+ res.body.should.be.a('object');
69
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
70
+ expect(res.body.question).to.equal("question1");
71
+ expect(res.body.answer).to.equal("answer1");
72
+ expect(res.body.intent_display_name).to.not.equal(undefined);
73
+ expect(res.body.webhook_enabled).to.equal(false);
76
74
 
75
+ done();
76
+ });
77
77
 
78
- });
79
- });
78
+ });
80
79
 
81
- });
82
80
 
83
- it('create with form (createFaqKb function)', (done) => {
84
-
85
-
86
- // this.timeout();
87
-
88
- var email = "test-signup-" + Date.now() + "@email.com";
89
- var pwd = "pwd";
90
- let example_form = {
91
- fields: [
92
- {
93
- name: "userFullname",
94
- type: "text",
95
- label: "What is your name?"
96
- },
97
- {
98
- name: "userEmail",
99
- type: "text",
100
- regex: "/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+(.[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/",
101
- label: "Your email?",
102
- errorLabel: "This email address is invalid\n\nCan you insert a correct email address?"
103
- }
104
- ]
105
- }
106
-
107
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
108
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
109
-
110
- chai.request(server)
111
- .post('/' + savedProject._id + '/faq_kb')
112
- .auth(email, pwd)
113
- .send({ "name": "testbot", type: "external", language: 'fr' })
114
- .end((err, res) => {
115
- if (log) { console.log("res.body", res.body); }
116
- res.should.have.status(200);
117
- res.body.should.be.a('object');
118
- expect(res.body.name).to.equal("testbot");
119
- expect(res.body.language).to.equal("fr");
120
- var id_faq_kb = res.body._id;
121
-
122
- chai.request(server)
123
- .post('/' + savedProject._id + '/faq')
124
- .auth(email, pwd)
125
- .send({ id_faq_kb: id_faq_kb, form: example_form })
126
- .end((err, res) => {
127
- if (log) { console.log("res.body", res.body); }
128
- res.should.have.status(200);
129
- res.body.should.be.a('object');
130
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
131
- expect(res.body.form).to.exist;
132
- res.body.form.should.be.a('object');
133
- expect(res.body.intent_display_name).to.not.equal(undefined);
134
- expect(res.body.webhook_enabled).to.equal(false);
135
-
136
- done();
137
- });
138
- });
139
-
140
-
141
- });
142
81
  });
82
+ });
143
83
 
144
- }).timeout(20000);
145
-
146
- it('createWithLanguage', (done) => {
147
-
148
-
149
- // this.timeout();
150
-
151
- var email = "test-signup-" + Date.now() + "@email.com";
152
- var pwd = "pwd";
153
-
154
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
155
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
156
- chai.request(server)
157
- .post('/' + savedProject._id + '/faq_kb')
158
- .auth(email, pwd)
159
- .send({ "name": "testbot", type: "internal", template: "example", language: "it" })
160
- .end((err, res) => {
161
- if (log) { console.log("res.body", res.body); }
162
- res.should.have.status(200);
163
- res.body.should.be.a('object');
164
- expect(res.body.name).to.equal("testbot");
165
- expect(res.body.language).to.equal("it");
166
- var id_faq_kb = res.body._id;
167
-
168
- chai.request(server)
169
- .post('/' + savedProject._id + '/faq')
170
- .auth(email, pwd)
171
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
172
- .end((err, res) => {
173
- if (log) { console.log("res.body", res.body); }
174
- res.should.have.status(200);
175
- res.body.should.be.a('object');
176
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
177
- expect(res.body.question).to.equal("question1");
178
- expect(res.body.answer).to.equal("answer1");
179
- expect(res.body.intent_display_name).to.not.equal(undefined);
180
- expect(res.body.webhook_enabled).to.equal(false);
181
- expect(res.body.language).to.equal("it");
182
- done();
183
- });
184
-
185
- });
186
-
187
-
188
- });
189
- });
84
+ });
190
85
 
86
+ it('create with form (createFaqKb function)', (done) => {
87
+
88
+
89
+ // this.timeout();
90
+
91
+ var email = "test-signup-" + Date.now() + "@email.com";
92
+ var pwd = "pwd";
93
+ let example_form = {
94
+ fields: [
95
+ {
96
+ name: "userFullname",
97
+ type: "text",
98
+ label: "What is your name?"
99
+ },
100
+ {
101
+ name: "userEmail",
102
+ type: "text",
103
+ regex: "/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+(.[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/",
104
+ label: "Your email?",
105
+ errorLabel: "This email address is invalid\n\nCan you insert a correct email address?"
106
+ }
107
+ ]
108
+ }
109
+
110
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
111
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
112
+
113
+ chai.request(server)
114
+ .post('/' + savedProject._id + '/faq_kb')
115
+ .auth(email, pwd)
116
+ .send({ "name": "testbot", type: "external", language: 'fr' })
117
+ .end((err, res) => {
118
+
119
+ if (err) { console.error("err: ", err); }
120
+ if (log) { console.log("res.body", res.body); }
121
+
122
+ res.should.have.status(200);
123
+ res.body.should.be.a('object');
124
+ expect(res.body.name).to.equal("testbot");
125
+ expect(res.body.language).to.equal("fr");
126
+ var id_faq_kb = res.body._id;
127
+
128
+ chai.request(server)
129
+ .post('/' + savedProject._id + '/faq')
130
+ .auth(email, pwd)
131
+ .send({ id_faq_kb: id_faq_kb, form: example_form })
132
+ .end((err, res) => {
133
+
134
+ if (err) { console.error("err: ", err); }
135
+ if (log) { console.log("res.body", res.body); }
136
+
137
+ res.should.have.status(200);
138
+ res.body.should.be.a('object');
139
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
140
+ expect(res.body.form).to.exist;
141
+ res.body.form.should.be.a('object');
142
+ expect(res.body.intent_display_name).to.not.equal(undefined);
143
+ expect(res.body.webhook_enabled).to.equal(false);
144
+
145
+ done();
146
+ });
147
+ });
148
+
149
+
150
+ });
191
151
  });
192
152
 
193
- it('createWithIntentDisplayNameAndWebhookEnalbed', (done) => {
153
+ }).timeout(20000);
194
154
 
155
+ it('createWithLanguage', (done) => {
195
156
 
196
- // this.timeout();
197
157
 
198
- var email = "test-signup-" + Date.now() + "@email.com";
199
- var pwd = "pwd";
158
+ // this.timeout();
200
159
 
201
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
202
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
160
+ var email = "test-signup-" + Date.now() + "@email.com";
161
+ var pwd = "pwd";
203
162
 
204
- chai.request(server)
205
- .post('/' + savedProject._id + '/faq_kb')
206
- .auth(email, pwd)
207
- .send({ "name": "testbot", type: "internal", template: "example", })
208
- .end((err, res) => {
209
- if (log) { console.log("res.body", res.body); }
210
- res.should.have.status(200);
211
- res.body.should.be.a('object');
212
- expect(res.body.name).to.equal("testbot");
213
- var id_faq_kb = res.body._id;
163
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
164
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
165
+ chai.request(server)
166
+ .post('/' + savedProject._id + '/faq_kb')
167
+ .auth(email, pwd)
168
+ .send({ "name": "testbot", type: "internal", template: "example", language: "it" })
169
+ .end((err, res) => {
214
170
 
215
- chai.request(server)
216
- .post('/' + savedProject._id + '/faq')
217
- .auth(email, pwd)
218
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", webhook_enabled: true, intent_display_name: "intent_display_name1" })
219
- .end((err, res) => {
220
- if (log) { console.log("res.body", res.body); }
221
- res.should.have.status(200);
222
- res.body.should.be.a('object');
223
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
224
- expect(res.body.question).to.equal("question1");
225
- expect(res.body.answer).to.equal("answer1");
226
- expect(res.body.intent_display_name).to.equal("intent_display_name1");
227
- expect(res.body.webhook_enabled).to.equal(true);
171
+ if (err) { console.error("err: ", err); }
172
+ if (log) { console.log("res.body", res.body); }
228
173
 
229
- done();
230
- });
174
+ res.should.have.status(200);
175
+ res.body.should.be.a('object');
176
+ expect(res.body.name).to.equal("testbot");
177
+ expect(res.body.language).to.equal("it");
178
+ var id_faq_kb = res.body._id;
231
179
 
232
- });
180
+ chai.request(server)
181
+ .post('/' + savedProject._id + '/faq')
182
+ .auth(email, pwd)
183
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
184
+ .end((err, res) => {
233
185
 
186
+ if (err) { console.error("err: ", err); }
187
+ if (log) { console.log("res.body", res.body); }
234
188
 
235
- });
236
- });
189
+ res.should.have.status(200);
190
+ res.body.should.be.a('object');
191
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
192
+ expect(res.body.question).to.equal("question1");
193
+ expect(res.body.answer).to.equal("answer1");
194
+ expect(res.body.intent_display_name).to.not.equal(undefined);
195
+ expect(res.body.webhook_enabled).to.equal(false);
196
+ expect(res.body.language).to.equal("it");
197
+ done();
198
+ });
199
+
200
+ });
237
201
 
202
+
203
+ });
238
204
  });
239
205
 
240
- it('update', (done) => {
241
-
242
-
243
- // this.timeout();
244
-
245
- var email = "test-signup-" + Date.now() + "@email.com";
246
- var pwd = "pwd";
247
-
248
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
249
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
250
- chai.request(server)
251
- .post('/' + savedProject._id + '/faq_kb')
252
- .auth(email, pwd)
253
- .send({ "name": "testbot", type: "internal" })
254
- .end((err, res) => {
255
- if (log) { console.log("res.body", res.body); }
256
- res.should.have.status(200);
257
- res.body.should.be.a('object');
258
- expect(res.body.name).to.equal("testbot");
259
- var id_faq_kb = res.body._id;
260
-
261
- chai.request(server)
262
- .post('/' + savedProject._id + '/faq')
263
- .auth(email, pwd)
264
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: {one: "one", two: "two"}} })
265
- .end((err, res) => {
266
- if (log) { console.log("res.body", res.body); }
267
- res.should.have.status(200);
268
- res.body.should.be.a('object');
269
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
270
- expect(res.body.question).to.equal("question1");
271
- expect(res.body.answer).to.equal("answer1");
272
- expect(res.body.intent_display_name).to.not.equal(undefined);
273
- expect(res.body.webhook_enabled).to.equal(false);
274
-
275
- chai.request(server)
276
- .put('/' + savedProject._id + '/faq/' + res.body._id)
277
- .auth(email, pwd)
278
- .send({ id_faq_kb: id_faq_kb, question: "question2", answer: "answer2", webhook_enabled: true, attributes: { two: "twooo" } })
279
- .end((err, res) => {
280
- if (log) { console.log("res.body", res.body); }
281
- res.should.have.status(200);
282
- res.body.should.be.a('object');
283
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
284
- expect(res.body.question).to.equal("question2");
285
- expect(res.body.answer).to.equal("answer2");
286
- expect(res.body.intent_display_name).to.not.equal(undefined);
287
- expect(res.body.webhook_enabled).to.equal(true);
288
-
289
- done();
290
- });
291
-
292
- });
293
-
294
- });
295
-
296
-
297
- });
206
+ });
207
+
208
+ it('createWithIntentDisplayNameAndWebhookEnalbed', (done) => {
209
+
210
+
211
+ // this.timeout();
212
+
213
+ var email = "test-signup-" + Date.now() + "@email.com";
214
+ var pwd = "pwd";
215
+
216
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
217
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
218
+
219
+ chai.request(server)
220
+ .post('/' + savedProject._id + '/faq_kb')
221
+ .auth(email, pwd)
222
+ .send({ "name": "testbot", type: "internal", template: "example", })
223
+ .end((err, res) => {
224
+
225
+ if (err) { console.error("err: ", err); }
226
+ if (log) { console.log("res.body", res.body); }
227
+
228
+ res.should.have.status(200);
229
+ res.body.should.be.a('object');
230
+ expect(res.body.name).to.equal("testbot");
231
+ var id_faq_kb = res.body._id;
232
+
233
+ chai.request(server)
234
+ .post('/' + savedProject._id + '/faq')
235
+ .auth(email, pwd)
236
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", webhook_enabled: true, intent_display_name: "intent_display_name1" })
237
+ .end((err, res) => {
238
+
239
+ if (err) { console.error("err: ", err); }
240
+ if (log) { console.log("res.body", res.body); }
241
+
242
+ res.should.have.status(200);
243
+ res.body.should.be.a('object');
244
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
245
+ expect(res.body.question).to.equal("question1");
246
+ expect(res.body.answer).to.equal("answer1");
247
+ expect(res.body.intent_display_name).to.equal("intent_display_name1");
248
+ expect(res.body.webhook_enabled).to.equal(true);
249
+
250
+ done();
251
+ });
252
+
253
+ });
254
+
255
+
298
256
  });
257
+ });
258
+
259
+ });
260
+
261
+ it('update', (done) => {
262
+
263
+
264
+ // this.timeout();
265
+
266
+ var email = "test-signup-" + Date.now() + "@email.com";
267
+ var pwd = "pwd";
268
+
269
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
270
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
271
+ chai.request(server)
272
+ .post('/' + savedProject._id + '/faq_kb')
273
+ .auth(email, pwd)
274
+ .send({ "name": "testbot", type: "internal" })
275
+ .end((err, res) => {
276
+
277
+ if (err) { console.error("err: ", err); }
278
+ if (log) { console.log("res.body", res.body); }
279
+
280
+ res.should.have.status(200);
281
+ res.body.should.be.a('object');
282
+ expect(res.body.name).to.equal("testbot");
283
+ var id_faq_kb = res.body._id;
284
+
285
+ chai.request(server)
286
+ .post('/' + savedProject._id + '/faq')
287
+ .auth(email, pwd)
288
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: {one: "one", two: "two"}} })
289
+ .end((err, res) => {
290
+
291
+ if (err) { console.error("err: ", err); }
292
+ if (log) { console.log("res.body", res.body); }
299
293
 
294
+ res.should.have.status(200);
295
+ res.body.should.be.a('object');
296
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
297
+ expect(res.body.question).to.equal("question1");
298
+ expect(res.body.answer).to.equal("answer1");
299
+ expect(res.body.intent_display_name).to.not.equal(undefined);
300
+ expect(res.body.webhook_enabled).to.equal(false);
301
+
302
+ chai.request(server)
303
+ .put('/' + savedProject._id + '/faq/' + res.body._id)
304
+ .auth(email, pwd)
305
+ .send({ id_faq_kb: id_faq_kb, question: "question2", answer: "answer2", webhook_enabled: true, attributes: { two: "twooo" } })
306
+ .end((err, res) => {
307
+
308
+ if (err) { console.error("err: ", err); }
309
+ if (log) { console.log("res.body", res.body); }
310
+
311
+ res.should.have.status(200);
312
+ res.body.should.be.a('object');
313
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
314
+ expect(res.body.question).to.equal("question2");
315
+ expect(res.body.answer).to.equal("answer2");
316
+ expect(res.body.intent_display_name).to.not.equal(undefined);
317
+ expect(res.body.webhook_enabled).to.equal(true);
318
+
319
+ done();
320
+ });
321
+
322
+ });
323
+
324
+ });
325
+
326
+
327
+ });
300
328
  });
301
329
 
302
- it('update attributes', (done) => {
303
-
304
- var email = "test-signup-" + Date.now() + "@email.com";
305
- var pwd = "pwd";
306
-
307
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
308
- projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
309
- chai.request(server)
310
- .post('/' + savedProject._id + '/faq_kb')
311
- .auth(email, pwd)
312
- .send({ "name": "testbot", type: "internal" })
313
- .end((err, res) => {
314
- if (log) { console.log("res.body", res.body); }
315
- res.should.have.status(200);
316
- res.body.should.be.a('object');
317
- expect(res.body.name).to.equal("testbot");
318
- var id_faq_kb = res.body._id;
319
-
320
- chai.request(server)
321
- .post('/' + savedProject._id + '/faq')
322
- .auth(email, pwd)
323
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
324
- .end((err, res) => {
325
- if (log) { console.log("res.body", res.body); }
326
- res.should.have.status(200);
327
- res.body.should.be.a('object');
328
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
329
- expect(res.body.question).to.equal("question1");
330
- expect(res.body.answer).to.equal("answer1");
331
- expect(res.body.intent_display_name).to.not.equal(undefined);
332
- expect(res.body.webhook_enabled).to.equal(false);
333
-
334
- chai.request(server)
335
- .patch('/' + savedProject._id + '/faq/' + res.body._id + '/attributes')
336
- .auth(email, pwd)
337
- .send({
338
- "first_parameter": {
339
- "x": "first",
340
- "y": "second"
341
- },
342
- "color": {
343
- "first": "first",
344
- }
345
- })
346
- .end((err, res) => {
347
- if (log) {
348
- console.log("res.body attributes", res.body);
349
- console.log("res.body attributes", res.body.attributes);
350
- }
351
- res.should.have.status(200);
352
- res.body.should.be.a('object');
353
- expect(res.body.attributes).to.not.equal(undefined);
354
-
355
- done();
356
- });
357
-
358
- });
359
-
360
- });
361
-
362
-
363
- });
330
+ });
331
+
332
+ it('update attributes', (done) => {
333
+
334
+ var email = "test-signup-" + Date.now() + "@email.com";
335
+ var pwd = "pwd";
336
+
337
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
338
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
339
+ chai.request(server)
340
+ .post('/' + savedProject._id + '/faq_kb')
341
+ .auth(email, pwd)
342
+ .send({ "name": "testbot", type: "internal" })
343
+ .end((err, res) => {
344
+
345
+ if (err) { console.error("err: ", err); }
346
+ if (log) { console.log("res.body", res.body); }
347
+
348
+ res.should.have.status(200);
349
+ res.body.should.be.a('object');
350
+ expect(res.body.name).to.equal("testbot");
351
+ var id_faq_kb = res.body._id;
352
+
353
+ chai.request(server)
354
+ .post('/' + savedProject._id + '/faq')
355
+ .auth(email, pwd)
356
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
357
+ .end((err, res) => {
358
+
359
+ if (err) { console.error("err: ", err); }
360
+ if (log) { console.log("res.body", res.body); }
361
+
362
+ res.should.have.status(200);
363
+ res.body.should.be.a('object');
364
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
365
+ expect(res.body.question).to.equal("question1");
366
+ expect(res.body.answer).to.equal("answer1");
367
+ expect(res.body.intent_display_name).to.not.equal(undefined);
368
+ expect(res.body.webhook_enabled).to.equal(false);
369
+
370
+ chai.request(server)
371
+ .patch('/' + savedProject._id + '/faq/' + res.body._id + '/attributes')
372
+ .auth(email, pwd)
373
+ .send({
374
+ "first_parameter": {
375
+ "x": "first",
376
+ "y": "second"
377
+ },
378
+ "color": {
379
+ "first": "first",
380
+ }
381
+ })
382
+ .end((err, res) => {
383
+
384
+ if (err) { console.error("err: ", err); }
385
+ if (log) {
386
+ console.log("res.body attributes", res.body);
387
+ console.log("res.body attributes", res.body.attributes);
388
+ }
389
+ res.should.have.status(200);
390
+ res.body.should.be.a('object');
391
+ expect(res.body.attributes).to.not.equal(undefined);
392
+
393
+ done();
394
+ });
395
+
396
+ });
397
+
398
+ });
399
+
400
+
364
401
  });
365
- })
402
+ });
403
+ })
366
404
 
367
- it('updateBulkOperations', (done) => {
405
+ it('updateBulkOperations', (done) => {
368
406
 
369
- var email = "test-signup-" + Date.now() + "@email.com";
370
- var pwd = "pwd";
407
+ var email = "test-signup-" + Date.now() + "@email.com";
408
+ var pwd = "pwd";
371
409
 
372
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
373
- projectService.create("test-updatebulkops", savedUser._id).then((savedProject) => {
410
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
411
+ projectService.create("test-updatebulkops", savedUser._id).then((savedProject) => {
374
412
 
375
- //console.log("EXAMPLE DATA: ", JSON.stringify(example_data));
413
+ //console.log("EXAMPLE DATA: ", JSON.stringify(example_data));
376
414
 
377
- chai.request(server)
378
- .post('/' + savedProject._id + '/faq/ops_update')
379
- .auth(email, pwd)
380
- .send(example_data.json_multiple_operation) // set up the payload
381
- .end((err, res) => {
382
- if (log) { console.log("res.body", res.body); }
383
- res.should.have.status(200);
384
- res.body.should.be.a('object');
415
+ chai.request(server)
416
+ .post('/' + savedProject._id + '/faq/ops_update')
417
+ .auth(email, pwd)
418
+ .send(example_data.json_multiple_operation) // set up the payload
419
+ .end((err, res) => {
385
420
 
386
- done();
387
- })
421
+ if (err) { console.error("err: ", err); }
422
+ if (log) { console.log("res.body", res.body); }
423
+
424
+ res.should.have.status(200);
425
+ res.body.should.be.a('object');
426
+
427
+ done();
428
+ })
388
429
 
389
- })
390
430
  })
391
431
  })
432
+ })
392
433
 
434
+ it('uploadcsv', (done) => {
393
435
 
394
- it('uploadcsv', (done) => {
395
436
 
437
+ // this.timeout();
396
438
 
397
- // this.timeout();
439
+ var email = "test-signup-" + Date.now() + "@email.com";
440
+ var pwd = "pwd";
398
441
 
399
- var email = "test-signup-" + Date.now() + "@email.com";
400
- var pwd = "pwd";
442
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
443
+ projectService.create("test-uploadcsv", savedUser._id).then(function (savedProject) {
401
444
 
402
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
403
- projectService.create("test-uploadcsv", savedUser._id).then(function (savedProject) {
445
+ chai.request(server)
446
+ .post('/' + savedProject._id + '/faq_kb')
447
+ .auth(email, pwd)
448
+ .send({ "name": "testbot", type: "internal" })
449
+ .end((err, res) => {
404
450
 
405
- chai.request(server)
406
- .post('/' + savedProject._id + '/faq_kb')
407
- .auth(email, pwd)
408
- .send({ "name": "testbot", type: "internal" })
409
- .end((err, res) => {
410
- if (log) { console.log("res.body", res.body); }
411
- res.should.have.status(200);
412
- res.body.should.be.a('object');
413
- expect(res.body.name).to.equal("testbot");
414
- var id_faq_kb = res.body._id;
451
+ if (err) { console.error("err: ", err); }
452
+ if (log) { console.log("res.body", res.body); }
415
453
 
416
- chai.request(server)
417
- .post('/' + savedProject._id + '/faq/uploadcsv')
418
- .auth(email, pwd)
419
- .set('Content-Type', 'text/csv')
420
- .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
421
- .field('id_faq_kb', id_faq_kb)
422
- .field('delimiter', ';')
423
- // .send({id_faq_kb: id_faq_kb})
424
- .end((err, res) => {
425
- if (err) { console.log("err", err); }
426
- if (log) { console.log("res.body", res.body); }
427
- res.should.have.status(200);
428
- res.body.should.be.a('object');
454
+ res.should.have.status(200);
455
+ res.body.should.be.a('object');
456
+ expect(res.body.name).to.equal("testbot");
457
+ var id_faq_kb = res.body._id;
429
458
 
430
- done();
431
- });
459
+ chai.request(server)
460
+ .post('/' + savedProject._id + '/faq/uploadcsv')
461
+ .auth(email, pwd)
462
+ .set('Content-Type', 'text/csv')
463
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
464
+ .field('id_faq_kb', id_faq_kb)
465
+ .field('delimiter', ';')
466
+ // .send({id_faq_kb: id_faq_kb})
467
+ .end((err, res) => {
432
468
 
433
- });
469
+ if (err) { console.error("err: ", err); }
470
+ if (log) { console.log("res.body", res.body); }
434
471
 
435
- });
436
- });
472
+ res.should.have.status(200);
473
+ res.body.should.be.a('object');
437
474
 
438
- });
475
+ done();
476
+ });
439
477
 
440
- it('uploadcsvWithLanguage', (done) => {
441
-
442
-
443
- // this.timeout();
444
-
445
- var email = "test-signup-" + Date.now() + "@email.com";
446
- var pwd = "pwd";
447
-
448
- userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
449
- projectService.create("test-uploadcsv", savedUser._id).then(function (savedProject) {
450
-
451
- chai.request(server)
452
- .post('/' + savedProject._id + '/faq_kb')
453
- .auth(email, pwd)
454
- .send({ "name": "testbot", type: "internal", language: "it" })
455
- .end((err, res) => {
456
- if (log) { console.log("res.body", res.body); }
457
- res.should.have.status(200);
458
- res.body.should.be.a('object');
459
- expect(res.body.name).to.equal("testbot");
460
- expect(res.body.language).to.equal("it");
461
- var id_faq_kb = res.body._id;
462
-
463
- chai.request(server)
464
- .post('/' + savedProject._id + '/faq/uploadcsv')
465
- .auth(email, pwd)
466
- .set('Content-Type', 'text/csv')
467
- .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
468
- .field('id_faq_kb', id_faq_kb)
469
- .field('delimiter', ';')
470
- // .send({id_faq_kb: id_faq_kb})
471
- .end((err, res) => {
472
- if (err) {
473
- console.log("err", err);
474
- }
475
- if (log) { console.log("res.body", res.body); }
476
- res.should.have.status(200);
477
- res.body.should.be.a('object');
478
-
479
- done();
480
- });
481
-
482
- });
483
-
484
- });
485
- });
478
+ });
486
479
 
480
+ });
487
481
  });
488
482
 
483
+ });
489
484
 
490
- it('searchFaqs', (done) => {
485
+ it('uploadcsvWithLanguage', (done) => {
491
486
 
492
- var email = "test-signup-" + Date.now() + "@email.com";
493
- var pwd = "pwd";
494
487
 
495
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
496
- projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
488
+ // this.timeout();
497
489
 
498
- chai.request(server)
499
- .post('/' + savedProject._id + '/faq_kb')
500
- .auth(email, pwd)
501
- .send({ "name": "testbot", type: "internal", template: "example" })
502
- .end((err, res) => {
503
- if (log) { console.log("res.body", res.body); }
504
- res.should.have.status(200);
505
- res.body.should.be.a('object');
506
- expect(res.body.name).to.equal("testbot");
507
- var id_faq_kb = res.body._id;
490
+ var email = "test-signup-" + Date.now() + "@email.com";
491
+ var pwd = "pwd";
508
492
 
493
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
494
+ projectService.create("test-uploadcsv", savedUser._id).then(function (savedProject) {
509
495
 
510
- chai.request(server)
511
- //.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
512
- .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb + "&page=0&limit=25&text=looking")
513
- .auth(email, pwd)
514
- .end((err, res) => {
515
- if (log) { console.log("found these faqs: \n", res.body); }
516
- res.should.have.status(200);
517
- res.body.should.be.an('array');
496
+ chai.request(server)
497
+ .post('/' + savedProject._id + '/faq_kb')
498
+ .auth(email, pwd)
499
+ .send({ "name": "testbot", type: "internal", language: "it" })
500
+ .end((err, res) => {
518
501
 
502
+ if (err) { console.error("err: ", err); }
503
+ if (log) { console.log("res.body", res.body); }
519
504
 
520
- done();
505
+ res.should.have.status(200);
506
+ res.body.should.be.a('object');
507
+ expect(res.body.name).to.equal("testbot");
508
+ expect(res.body.language).to.equal("it");
509
+ var id_faq_kb = res.body._id;
521
510
 
522
- })
523
- })
524
- })
525
- })
511
+ chai.request(server)
512
+ .post('/' + savedProject._id + '/faq/uploadcsv')
513
+ .auth(email, pwd)
514
+ .set('Content-Type', 'text/csv')
515
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
516
+ .field('id_faq_kb', id_faq_kb)
517
+ .field('delimiter', ';')
518
+ // .send({id_faq_kb: id_faq_kb})
519
+ .end((err, res) => {
520
+
521
+ if (err) { console.error("err: ", err); }
522
+ if (log) { console.log("res.body", res.body); }
523
+
524
+ res.should.have.status(200);
525
+ res.body.should.be.a('object');
526
+
527
+ done();
528
+ });
529
+
530
+ });
531
+
532
+ });
526
533
  });
527
534
 
528
- it('intentsEngine on', (done) => {
535
+ });
536
+
537
+ it('searchFaqs', (done) => {
538
+
539
+ var email = "test-signup-" + Date.now() + "@email.com";
540
+ var pwd = "pwd";
541
+
542
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
543
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
544
+
545
+ chai.request(server)
546
+ .post('/' + savedProject._id + '/faq_kb')
547
+ .auth(email, pwd)
548
+ .send({ "name": "testbot", type: "internal", template: "example" })
549
+ .end((err, res) => {
529
550
 
530
- var email = "test-signup-" + Date.now() + "@email.com";
531
- var pwd = "pwd";
551
+ if (err) { console.error("err: ", err); }
552
+ if (log) { console.log("res.body", res.body); }
532
553
 
533
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
534
- projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
554
+ res.should.have.status(200);
555
+ res.body.should.be.a('object');
556
+ expect(res.body.name).to.equal("testbot");
557
+ var id_faq_kb = res.body._id;
535
558
 
536
- chai.request(server)
537
- .post('/' + savedProject._id + '/faq_kb')
538
- .auth(email, pwd)
539
- .send({ "name": "testbot", type: "internal", template: "blank", intentsEngine: 'tiledesk-ai' })
540
- .end((err, res) => {
541
- if (log) { console.log("res.body", res.body); }
542
- res.should.have.status(200);
543
- res.body.should.be.a('object');
544
- expect(res.body.name).to.equal("testbot");
545
- var id_faq_kb = res.body._id;
546
559
 
560
+ chai.request(server)
561
+ //.get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
562
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb + "&page=0&limit=25&text=looking")
563
+ .auth(email, pwd)
564
+ .end((err, res) => {
547
565
 
548
- chai.request(server)
549
- .post('/' + savedProject._id + '/faq')
550
- .auth(email, pwd)
551
- .send({ id_faq_kb: id_faq_kb, question: "question1\nciao\nbuongiorno", answer: "answer1" })
552
- .end((err, res) => {
553
- if (log) { console.log("intentEngin on resbody (create faq): \n", res.body); }
554
- res.should.have.status(200);
566
+ if (err) { console.error("err: ", err); }
567
+ if (log) { console.log("found these faqs: \n", res.body); }
555
568
 
556
- done();
569
+ res.should.have.status(200);
570
+ res.body.should.be.an('array');
557
571
 
558
- })
559
- })
560
- })
572
+
573
+ done();
574
+
575
+ })
576
+ })
561
577
  })
562
- });
578
+ })
579
+ });
580
+
581
+ it('intentsEngine on', (done) => {
582
+
583
+ var email = "test-signup-" + Date.now() + "@email.com";
584
+ var pwd = "pwd";
585
+
586
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
587
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
588
+
589
+ chai.request(server)
590
+ .post('/' + savedProject._id + '/faq_kb')
591
+ .auth(email, pwd)
592
+ .send({ "name": "testbot", type: "internal", template: "blank", intentsEngine: 'tiledesk-ai' })
593
+ .end((err, res) => {
594
+
595
+ if (err) { console.error("err: ", err); }
596
+ if (log) { console.log("res.body", res.body); }
597
+
598
+ res.should.have.status(200);
599
+ res.body.should.be.a('object');
600
+ expect(res.body.name).to.equal("testbot");
601
+ var id_faq_kb = res.body._id;
602
+
603
+
604
+ chai.request(server)
605
+ .post('/' + savedProject._id + '/faq')
606
+ .auth(email, pwd)
607
+ .send({ id_faq_kb: id_faq_kb, question: "question1\nciao\nbuongiorno", answer: "answer1" })
608
+ .end((err, res) => {
609
+
610
+ if (err) { console.error("err: ", err); }
611
+ if (log) { console.log("intentEngin on resbody (create faq): \n", res.body); }
563
612
 
564
- it('delete with _id', (done) => {
565
-
566
- var email = "test-signup-" + Date.now() + "@email.com";
567
- var pwd = "pwd";
568
-
569
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
570
- projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
571
-
572
- chai.request(server)
573
- .post('/' + savedProject._id + '/faq_kb')
574
- .auth(email, pwd)
575
- .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
576
- .end((err, res) => {
577
- if (log) { console.log("create chatbot res.body", res.body); }
578
- res.should.have.status(200);
579
- res.body.should.be.a('object');
580
- expect(res.body.name).to.equal("testbot");
581
- var id_faq_kb = res.body._id;
582
-
583
- chai.request(server)
584
- .post('/' + savedProject._id + '/faq')
585
- .auth(email, pwd)
586
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
587
- .end((err, res) => {
588
- if (log) { console.log("create intent res.body", res.body); }
589
- res.should.have.status(200);
590
- let faqid = res.body._id;
591
-
592
- chai.request(server)
593
- .delete('/' + savedProject._id + '/faq/' + faqid)
594
- .auth(email, pwd)
595
- .end((err, res) => {
596
- if (log) { console.log("delete intent res.body", res.body); }
597
- res.should.have.status(200);
598
-
599
- done();
600
- })
601
-
602
- })
603
- })
604
- })
613
+ res.should.have.status(200);
614
+
615
+ done();
616
+
617
+ })
618
+ })
605
619
  })
606
- });
620
+ })
621
+ });
622
+
623
+ it('delete with _id', (done) => {
624
+
625
+ var email = "test-signup-" + Date.now() + "@email.com";
626
+ var pwd = "pwd";
627
+
628
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
629
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
630
+
631
+ chai.request(server)
632
+ .post('/' + savedProject._id + '/faq_kb')
633
+ .auth(email, pwd)
634
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
635
+ .end((err, res) => {
607
636
 
608
- it('deleteWithIntentId', (done) => {
609
-
610
- var email = "test-signup-" + Date.now() + "@email.com";
611
- var pwd = "pwd";
612
-
613
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
614
- projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
615
-
616
- chai.request(server)
617
- .post('/' + savedProject._id + '/faq_kb')
618
- .auth(email, pwd)
619
- .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
620
- .end((err, res) => {
621
- if (log) { console.log("create chatbot res.body", res.body); }
622
- res.should.have.status(200);
623
- res.body.should.be.a('object');
624
- expect(res.body.name).to.equal("testbot");
625
- var id_faq_kb = res.body._id;
626
-
627
- chai.request(server)
628
- .post('/' + savedProject._id + '/faq')
629
- .auth(email, pwd)
630
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
631
- .end((err, res) => {
632
- if (log) { console.log("create intent res.body", res.body); }
633
- res.should.have.status(200);
634
- let faqid = res.body.intent_id;
635
-
636
- chai.request(server)
637
- .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
638
- .auth(email, pwd)
639
- .end((err, res) => {
640
- if (log) { console.log("delete intent res.body", res.body); }
641
- res.should.have.status(200);
642
-
643
- done();
644
- })
645
-
646
- })
647
- })
648
- })
637
+ if (err) { console.error("err: ", err); }
638
+ if (log) { console.log("create chatbot res.body", res.body); }
639
+
640
+ res.should.have.status(200);
641
+ res.body.should.be.a('object');
642
+ expect(res.body.name).to.equal("testbot");
643
+ var id_faq_kb = res.body._id;
644
+
645
+ chai.request(server)
646
+ .post('/' + savedProject._id + '/faq')
647
+ .auth(email, pwd)
648
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
649
+ .end((err, res) => {
650
+
651
+ if (err) { console.error("err: ", err); }
652
+ if (log) { console.log("create intent res.body", res.body); }
653
+
654
+ res.should.have.status(200);
655
+ let faqid = res.body._id;
656
+
657
+ chai.request(server)
658
+ .delete('/' + savedProject._id + '/faq/' + faqid)
659
+ .auth(email, pwd)
660
+ .end((err, res) => {
661
+
662
+ if (err) { console.error("err: ", err); }
663
+ if (log) { console.log("delete intent res.body", res.body); }
664
+
665
+ res.should.have.status(200);
666
+
667
+ done();
668
+ })
669
+
670
+ })
671
+ })
649
672
  })
650
- });
673
+ })
674
+ });
675
+
676
+ it('deleteWithIntentId', (done) => {
677
+
678
+ var email = "test-signup-" + Date.now() + "@email.com";
679
+ var pwd = "pwd";
680
+
681
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
682
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
683
+
684
+ chai.request(server)
685
+ .post('/' + savedProject._id + '/faq_kb')
686
+ .auth(email, pwd)
687
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
688
+ .end((err, res) => {
689
+
690
+ if (err) { console.error("err: ", err); }
691
+ if (log) { console.log("create chatbot res.body", res.body); }
692
+
693
+ res.should.have.status(200);
694
+ res.body.should.be.a('object');
695
+ expect(res.body.name).to.equal("testbot");
696
+ var id_faq_kb = res.body._id;
697
+
698
+ chai.request(server)
699
+ .post('/' + savedProject._id + '/faq')
700
+ .auth(email, pwd)
701
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
702
+ .end((err, res) => {
651
703
 
652
- it('deleteWithIntentIdError', (done) => {
653
-
654
- var email = "test-signup-" + Date.now() + "@email.com";
655
- var pwd = "pwd";
656
-
657
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
658
- projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
659
-
660
- chai.request(server)
661
- .post('/' + savedProject._id + '/faq_kb')
662
- .auth(email, pwd)
663
- .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
664
- .end((err, res) => {
665
- if (log) { console.log("create chatbot res.body", res.body); }
666
- res.should.have.status(200);
667
- res.body.should.be.a('object');
668
- expect(res.body.name).to.equal("testbot");
669
- var id_faq_kb = res.body._id;
670
-
671
- chai.request(server)
672
- .post('/' + savedProject._id + '/faq')
673
- .auth(email, pwd)
674
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
675
- .end((err, res) => {
676
- if (log) { console.log("create intent res.body", res.body); }
677
- res.should.have.status(200);
678
- let faqid = res.body.intent_id;
679
-
680
- chai.request(server)
681
- .delete('/' + savedProject._id + '/faq/intentId' + faqid)
682
- // .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
683
- .auth(email, pwd)
684
- .end((err, res) => {
685
- if (log) { console.log("delete intent res.body", res.body); }
686
- res.should.have.status(500);
687
-
688
- done();
689
- })
690
-
691
- })
692
- })
693
- })
704
+ if (err) { console.error("err: ", err); }
705
+ if (log) { console.log("create intent res.body", res.body); }
706
+
707
+ res.should.have.status(200);
708
+ let faqid = res.body.intent_id;
709
+
710
+ chai.request(server)
711
+ .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
712
+ .auth(email, pwd)
713
+ .end((err, res) => {
714
+
715
+ if (err) { console.error("err: ", err); }
716
+ if (log) { console.log("delete intent res.body", res.body); }
717
+
718
+ res.should.have.status(200);
719
+
720
+ done();
721
+ })
722
+
723
+ })
724
+ })
694
725
  })
695
- });
726
+ })
727
+ });
728
+
729
+ it('deleteWithIntentIdError', (done) => {
730
+
731
+ var email = "test-signup-" + Date.now() + "@email.com";
732
+ var pwd = "pwd";
733
+
734
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
735
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
736
+
737
+ chai.request(server)
738
+ .post('/' + savedProject._id + '/faq_kb')
739
+ .auth(email, pwd)
740
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
741
+ .end((err, res) => {
742
+
743
+ if (err) { console.error("err: ", err); }
744
+ if (log) { console.log("create chatbot res.body", res.body); }
745
+
746
+ res.should.have.status(200);
747
+ res.body.should.be.a('object');
748
+ expect(res.body.name).to.equal("testbot");
749
+ var id_faq_kb = res.body._id;
750
+
751
+ chai.request(server)
752
+ .post('/' + savedProject._id + '/faq')
753
+ .auth(email, pwd)
754
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
755
+ .end((err, res) => {
756
+
757
+ if (err) { console.error("err: ", err); }
758
+ if (log) { console.log("create intent res.body", res.body); }
759
+
760
+ res.should.have.status(200);
761
+ let faqid = res.body.intent_id;
762
+
763
+ chai.request(server)
764
+ .delete('/' + savedProject._id + '/faq/intentId' + faqid)
765
+ // .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
766
+ .auth(email, pwd)
767
+ .end((err, res) => {
696
768
 
697
- it('deleteWithIntentIdErroWrongChatbotId', (done) => {
698
-
699
- var email = "test-signup-" + Date.now() + "@email.com";
700
- var pwd = "pwd";
701
-
702
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
703
- projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
704
-
705
- chai.request(server)
706
- .post('/' + savedProject._id + '/faq_kb')
707
- .auth(email, pwd)
708
- .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
709
- .end((err, res) => {
710
- if (log) { console.log("create chatbot res.body", res.body); }
711
- res.should.have.status(200);
712
- res.body.should.be.a('object');
713
- expect(res.body.name).to.equal("testbot");
714
- var id_faq_kb = res.body._id;
715
-
716
- chai.request(server)
717
- .post('/' + savedProject._id + '/faq')
718
- .auth(email, pwd)
719
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
720
- .end((err, res) => {
721
- if (log) { console.log("create intent res.body", res.body); }
722
- res.should.have.status(200);
723
- let faqid = res.body.intent_id;
724
-
725
- chai.request(server)
726
- .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=11233")
727
- // .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
728
- .auth(email, pwd)
729
- .end((err, res) => {
730
- if (log) { console.log("delete intent res.body", res.body); }
731
- res.should.have.status(404);
732
-
733
- done();
734
- })
735
-
736
- })
737
- })
738
- })
769
+ if (err) { console.error("err: ", err); }
770
+ if (log) { console.log("delete intent res.body", res.body); }
771
+
772
+ res.should.have.status(500);
773
+
774
+ done();
775
+ })
776
+
777
+ })
778
+ })
739
779
  })
740
- });
780
+ })
781
+ });
782
+
783
+ it('deleteWithIntentIdErroWrongChatbotId', (done) => {
784
+
785
+ var email = "test-signup-" + Date.now() + "@email.com";
786
+ var pwd = "pwd";
787
+
788
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
789
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
790
+
791
+ chai.request(server)
792
+ .post('/' + savedProject._id + '/faq_kb')
793
+ .auth(email, pwd)
794
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
795
+ .end((err, res) => {
741
796
 
797
+ if (err) { console.error("err: ", err); }
798
+ if (log) { console.log("create chatbot res.body", res.body); }
742
799
 
800
+ res.should.have.status(200);
801
+ res.body.should.be.a('object');
802
+ expect(res.body.name).to.equal("testbot");
803
+ var id_faq_kb = res.body._id;
804
+
805
+ chai.request(server)
806
+ .post('/' + savedProject._id + '/faq')
807
+ .auth(email, pwd)
808
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
809
+ .end((err, res) => {
810
+
811
+ if (err) { console.error("err: ", err); }
812
+ if (log) { console.log("create intent res.body", res.body); }
813
+
814
+ res.should.have.status(200);
815
+ let faqid = res.body.intent_id;
816
+
817
+ chai.request(server)
818
+ .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=11233")
819
+ // .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
820
+ .auth(email, pwd)
821
+ .end((err, res) => {
822
+
823
+ if (err) { console.error("err: ", err); }
824
+ if (log) { console.log("delete intent res.body", res.body); }
825
+
826
+ res.should.have.status(404);
827
+
828
+ done();
829
+ })
830
+ })
831
+ })
832
+ })
833
+ })
743
834
  });
744
835
 
745
836
  });