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