@tiledesk/tiledesk-server 2.4.52 → 2.4.53
Sign up to get free protection for your applications and to get access to all the features.
- package/app.js +2 -2
- package/models/faq.js +6 -0
- package/package.json +2 -2
- package/routes/faq.js +66 -23
- package/routes/faq_kb.js +7 -3
- package/routes/openai.js +112 -0
- package/routes/users.js +24 -0
- package/services/emailService.js +33 -0
- package/services/openaiService.js +41 -0
- package/template/email/redirectToDesktopEmail.html +304 -0
- package/template/email/redirectToDesktopEmail_new.html +604 -0
- package/test/faqRoute.js +116 -51
- package/test/openaiRoute.js +134 -0
- package/test/userRoute.js +63 -0
- package/routes/openai_kbs.js +0 -58
- package/test/openaiKbsRoute.js +0 -75
package/test/faqRoute.js
CHANGED
@@ -19,7 +19,7 @@ const path = require('path');
|
|
19
19
|
var expect = chai.expect;
|
20
20
|
var assert = chai.assert;
|
21
21
|
|
22
|
-
let log =
|
22
|
+
let log = false;
|
23
23
|
|
24
24
|
chai.use(chaiHttp);
|
25
25
|
|
@@ -27,7 +27,7 @@ describe('FaqKBRoute', () => {
|
|
27
27
|
|
28
28
|
describe('/create', () => {
|
29
29
|
|
30
|
-
it('create', (done) => {
|
30
|
+
it('create qwerty', (done) => {
|
31
31
|
|
32
32
|
// this.timeout();
|
33
33
|
|
@@ -41,8 +41,7 @@ describe('FaqKBRoute', () => {
|
|
41
41
|
.auth(email, pwd)
|
42
42
|
.send({ "name": "testbot", type: "internal" })
|
43
43
|
.end((err, res) => {
|
44
|
-
|
45
|
-
console.log("res.body", res.body);
|
44
|
+
if (log) { console.log("create bot res.body", res.body); }
|
46
45
|
res.should.have.status(200);
|
47
46
|
res.body.should.be.a('object');
|
48
47
|
expect(res.body.name).to.equal("testbot");
|
@@ -55,8 +54,7 @@ describe('FaqKBRoute', () => {
|
|
55
54
|
.auth(email, pwd)
|
56
55
|
.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
|
57
56
|
.end((err, res) => {
|
58
|
-
|
59
|
-
console.log("res.body", res.body);
|
57
|
+
if (log) { console.log("create intent res.body", res.body); }
|
60
58
|
res.should.have.status(200);
|
61
59
|
res.body.should.be.a('object');
|
62
60
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -108,8 +106,7 @@ describe('FaqKBRoute', () => {
|
|
108
106
|
.auth(email, pwd)
|
109
107
|
.send({ "name": "testbot", type: "external", language: 'fr' })
|
110
108
|
.end((err, res) => {
|
111
|
-
|
112
|
-
console.log("res.body", res.body);
|
109
|
+
if (log) { console.log("res.body", res.body); }
|
113
110
|
res.should.have.status(200);
|
114
111
|
res.body.should.be.a('object');
|
115
112
|
expect(res.body.name).to.equal("testbot");
|
@@ -121,8 +118,7 @@ describe('FaqKBRoute', () => {
|
|
121
118
|
.auth(email, pwd)
|
122
119
|
.send({ id_faq_kb: id_faq_kb, form: example_form })
|
123
120
|
.end((err, res) => {
|
124
|
-
|
125
|
-
console.log("res.body", res.body);
|
121
|
+
if (log) { console.log("res.body", res.body); }
|
126
122
|
res.should.have.status(200);
|
127
123
|
res.body.should.be.a('object');
|
128
124
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -156,8 +152,7 @@ describe('FaqKBRoute', () => {
|
|
156
152
|
.auth(email, pwd)
|
157
153
|
.send({ "name": "testbot", type: "internal", template: "example", language: "it" })
|
158
154
|
.end((err, res) => {
|
159
|
-
|
160
|
-
console.log("res.body", res.body);
|
155
|
+
if (log) { console.log("res.body", res.body); }
|
161
156
|
res.should.have.status(200);
|
162
157
|
res.body.should.be.a('object');
|
163
158
|
expect(res.body.name).to.equal("testbot");
|
@@ -169,8 +164,7 @@ describe('FaqKBRoute', () => {
|
|
169
164
|
.auth(email, pwd)
|
170
165
|
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
|
171
166
|
.end((err, res) => {
|
172
|
-
|
173
|
-
console.log("res.body", res.body);
|
167
|
+
if (log) { console.log("res.body", res.body); }
|
174
168
|
res.should.have.status(200);
|
175
169
|
res.body.should.be.a('object');
|
176
170
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -206,8 +200,7 @@ describe('FaqKBRoute', () => {
|
|
206
200
|
.auth(email, pwd)
|
207
201
|
.send({ "name": "testbot", type: "internal", template: "example", })
|
208
202
|
.end((err, res) => {
|
209
|
-
|
210
|
-
console.log("res.body", res.body);
|
203
|
+
if (log) { console.log("res.body", res.body); }
|
211
204
|
res.should.have.status(200);
|
212
205
|
res.body.should.be.a('object');
|
213
206
|
expect(res.body.name).to.equal("testbot");
|
@@ -218,8 +211,7 @@ describe('FaqKBRoute', () => {
|
|
218
211
|
.auth(email, pwd)
|
219
212
|
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", webhook_enabled: true, intent_display_name: "intent_display_name1" })
|
220
213
|
.end((err, res) => {
|
221
|
-
|
222
|
-
console.log("res.body", res.body);
|
214
|
+
if (log) { console.log("res.body", res.body); }
|
223
215
|
res.should.have.status(200);
|
224
216
|
res.body.should.be.a('object');
|
225
217
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -254,8 +246,7 @@ describe('FaqKBRoute', () => {
|
|
254
246
|
.auth(email, pwd)
|
255
247
|
.send({ "name": "testbot", type: "internal" })
|
256
248
|
.end((err, res) => {
|
257
|
-
|
258
|
-
console.log("res.body", res.body);
|
249
|
+
if (log) { console.log("res.body", res.body); }
|
259
250
|
res.should.have.status(200);
|
260
251
|
res.body.should.be.a('object');
|
261
252
|
expect(res.body.name).to.equal("testbot");
|
@@ -266,8 +257,7 @@ describe('FaqKBRoute', () => {
|
|
266
257
|
.auth(email, pwd)
|
267
258
|
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", attributes: { attr1: {one: "one", two: "two"}} })
|
268
259
|
.end((err, res) => {
|
269
|
-
|
270
|
-
console.log("res.body", res.body);
|
260
|
+
if (log) { console.log("res.body", res.body); }
|
271
261
|
res.should.have.status(200);
|
272
262
|
res.body.should.be.a('object');
|
273
263
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -281,8 +271,7 @@ describe('FaqKBRoute', () => {
|
|
281
271
|
.auth(email, pwd)
|
282
272
|
.send({ id_faq_kb: id_faq_kb, question: "question2", answer: "answer2", webhook_enabled: true, attributes: { two: "twooo" } })
|
283
273
|
.end((err, res) => {
|
284
|
-
|
285
|
-
console.log("res.body", res.body);
|
274
|
+
if (log) { console.log("res.body", res.body); }
|
286
275
|
res.should.have.status(200);
|
287
276
|
res.body.should.be.a('object');
|
288
277
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -306,8 +295,6 @@ describe('FaqKBRoute', () => {
|
|
306
295
|
|
307
296
|
it('update attributes', (done) => {
|
308
297
|
|
309
|
-
console.log("update attributes test start... ");
|
310
|
-
|
311
298
|
var email = "test-signup-" + Date.now() + "@email.com";
|
312
299
|
var pwd = "pwd";
|
313
300
|
|
@@ -318,8 +305,7 @@ describe('FaqKBRoute', () => {
|
|
318
305
|
.auth(email, pwd)
|
319
306
|
.send({ "name": "testbot", type: "internal" })
|
320
307
|
.end((err, res) => {
|
321
|
-
|
322
|
-
console.log("res.body", res.body);
|
308
|
+
if (log) { console.log("res.body", res.body); }
|
323
309
|
res.should.have.status(200);
|
324
310
|
res.body.should.be.a('object');
|
325
311
|
expect(res.body.name).to.equal("testbot");
|
@@ -330,8 +316,7 @@ describe('FaqKBRoute', () => {
|
|
330
316
|
.auth(email, pwd)
|
331
317
|
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
|
332
318
|
.end((err, res) => {
|
333
|
-
|
334
|
-
console.log("res.body", res.body);
|
319
|
+
if (log) { console.log("res.body", res.body); }
|
335
320
|
res.should.have.status(200);
|
336
321
|
res.body.should.be.a('object');
|
337
322
|
expect(res.body.id_faq_kb).to.equal(id_faq_kb);
|
@@ -353,9 +338,10 @@ describe('FaqKBRoute', () => {
|
|
353
338
|
}
|
354
339
|
})
|
355
340
|
.end((err, res) => {
|
356
|
-
|
357
|
-
|
358
|
-
|
341
|
+
if (log) {
|
342
|
+
console.log("res.body attributes", res.body);
|
343
|
+
console.log("res.body attributes", res.body.attributes);
|
344
|
+
}
|
359
345
|
res.should.have.status(200);
|
360
346
|
res.body.should.be.a('object');
|
361
347
|
expect(res.body.attributes).to.not.equal(undefined);
|
@@ -389,8 +375,7 @@ describe('FaqKBRoute', () => {
|
|
389
375
|
.auth(email, pwd)
|
390
376
|
.send({ "name": "testbot", type: "internal" })
|
391
377
|
.end((err, res) => {
|
392
|
-
|
393
|
-
console.log("res.body", res.body);
|
378
|
+
if (log) { console.log("res.body", res.body); }
|
394
379
|
res.should.have.status(200);
|
395
380
|
res.body.should.be.a('object');
|
396
381
|
expect(res.body.name).to.equal("testbot");
|
@@ -405,8 +390,8 @@ describe('FaqKBRoute', () => {
|
|
405
390
|
.field('delimiter', ';')
|
406
391
|
// .send({id_faq_kb: id_faq_kb})
|
407
392
|
.end((err, res) => {
|
408
|
-
console.log("err", err);
|
409
|
-
console.log("res.body", res.body);
|
393
|
+
if (err) { console.log("err", err); }
|
394
|
+
if (log) { console.log("res.body", res.body); }
|
410
395
|
res.should.have.status(200);
|
411
396
|
res.body.should.be.a('object');
|
412
397
|
|
@@ -420,12 +405,6 @@ describe('FaqKBRoute', () => {
|
|
420
405
|
|
421
406
|
});
|
422
407
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
408
|
it('uploadcsvWithLanguage', (done) => {
|
430
409
|
|
431
410
|
|
@@ -442,8 +421,7 @@ describe('FaqKBRoute', () => {
|
|
442
421
|
.auth(email, pwd)
|
443
422
|
.send({ "name": "testbot", type: "internal", language: "it" })
|
444
423
|
.end((err, res) => {
|
445
|
-
|
446
|
-
console.log("res.body", res.body);
|
424
|
+
if (log) { console.log("res.body", res.body); }
|
447
425
|
res.should.have.status(200);
|
448
426
|
res.body.should.be.a('object');
|
449
427
|
expect(res.body.name).to.equal("testbot");
|
@@ -459,8 +437,10 @@ describe('FaqKBRoute', () => {
|
|
459
437
|
.field('delimiter', ';')
|
460
438
|
// .send({id_faq_kb: id_faq_kb})
|
461
439
|
.end((err, res) => {
|
462
|
-
|
463
|
-
|
440
|
+
if (err) {
|
441
|
+
console.log("err", err);
|
442
|
+
}
|
443
|
+
if (log) { console.log("res.body", res.body); }
|
464
444
|
res.should.have.status(200);
|
465
445
|
res.body.should.be.a('object');
|
466
446
|
|
@@ -544,10 +524,7 @@ describe('FaqKBRoute', () => {
|
|
544
524
|
.auth(email, pwd)
|
545
525
|
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
|
546
526
|
.end((err, res) => {
|
547
|
-
|
548
|
-
// }
|
549
|
-
|
550
|
-
console.log("intentEngin on resbody (create faq): \n", res.body);
|
527
|
+
if (log) { console.log("intentEngin on resbody (create faq): \n", res.body); }
|
551
528
|
res.should.have.status(200);
|
552
529
|
|
553
530
|
done();
|
@@ -558,6 +535,94 @@ describe('FaqKBRoute', () => {
|
|
558
535
|
})
|
559
536
|
});
|
560
537
|
|
538
|
+
it('delete with _id', (done) => {
|
539
|
+
|
540
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
541
|
+
var pwd = "pwd";
|
542
|
+
|
543
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
544
|
+
projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
|
545
|
+
|
546
|
+
chai.request(server)
|
547
|
+
.post('/' + savedProject._id + '/faq_kb')
|
548
|
+
.auth(email, pwd)
|
549
|
+
.send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
|
550
|
+
.end((err, res) => {
|
551
|
+
if (log) { console.log("create chatbot res.body", res.body); }
|
552
|
+
res.should.have.status(200);
|
553
|
+
res.body.should.be.a('object');
|
554
|
+
expect(res.body.name).to.equal("testbot");
|
555
|
+
var id_faq_kb = res.body._id;
|
556
|
+
|
557
|
+
chai.request(server)
|
558
|
+
.post('/' + savedProject._id + '/faq')
|
559
|
+
.auth(email, pwd)
|
560
|
+
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
|
561
|
+
.end((err, res) => {
|
562
|
+
if (log) { console.log("create intent res.body", res.body); }
|
563
|
+
res.should.have.status(200);
|
564
|
+
let faqid = res.body._id;
|
565
|
+
|
566
|
+
chai.request(server)
|
567
|
+
.delete('/' + savedProject._id + '/faq/' + faqid)
|
568
|
+
.auth(email, pwd)
|
569
|
+
.end((err, res) => {
|
570
|
+
if (log) { console.log("delete intent res.body", res.body); }
|
571
|
+
res.should.have.status(200);
|
572
|
+
|
573
|
+
done();
|
574
|
+
})
|
575
|
+
|
576
|
+
})
|
577
|
+
})
|
578
|
+
})
|
579
|
+
})
|
580
|
+
});
|
581
|
+
|
582
|
+
it('delete with intent_id', (done) => {
|
583
|
+
|
584
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
585
|
+
var pwd = "pwd";
|
586
|
+
|
587
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
588
|
+
projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
|
589
|
+
|
590
|
+
chai.request(server)
|
591
|
+
.post('/' + savedProject._id + '/faq_kb')
|
592
|
+
.auth(email, pwd)
|
593
|
+
.send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
|
594
|
+
.end((err, res) => {
|
595
|
+
if (log) { console.log("create chatbot res.body", res.body); }
|
596
|
+
res.should.have.status(200);
|
597
|
+
res.body.should.be.a('object');
|
598
|
+
expect(res.body.name).to.equal("testbot");
|
599
|
+
var id_faq_kb = res.body._id;
|
600
|
+
|
601
|
+
chai.request(server)
|
602
|
+
.post('/' + savedProject._id + '/faq')
|
603
|
+
.auth(email, pwd)
|
604
|
+
.send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
|
605
|
+
.end((err, res) => {
|
606
|
+
if (log) { console.log("create intent res.body", res.body); }
|
607
|
+
res.should.have.status(200);
|
608
|
+
let faqid = res.body.intent_id;
|
609
|
+
|
610
|
+
chai.request(server)
|
611
|
+
.delete('/' + savedProject._id + '/faq/intentId' + faqid)
|
612
|
+
.auth(email, pwd)
|
613
|
+
.end((err, res) => {
|
614
|
+
if (log) { console.log("delete intent res.body", res.body); }
|
615
|
+
res.should.have.status(200);
|
616
|
+
|
617
|
+
done();
|
618
|
+
})
|
619
|
+
|
620
|
+
})
|
621
|
+
})
|
622
|
+
})
|
623
|
+
})
|
624
|
+
});
|
625
|
+
|
561
626
|
|
562
627
|
});
|
563
628
|
|
@@ -0,0 +1,134 @@
|
|
1
|
+
//During the test the env variable is set to test
|
2
|
+
process.env.NODE_ENV = 'test';
|
3
|
+
|
4
|
+
let log = false;
|
5
|
+
var projectService = require('../services/projectService');
|
6
|
+
var userService = require('../services/userService');
|
7
|
+
|
8
|
+
//Require the dev-dependencies
|
9
|
+
let chai = require('chai');
|
10
|
+
let chaiHttp = require('chai-http');
|
11
|
+
let server = require('../app');
|
12
|
+
let should = chai.should();
|
13
|
+
var fs = require('fs');
|
14
|
+
const path = require('path');
|
15
|
+
|
16
|
+
// chai.config.includeStack = true;
|
17
|
+
|
18
|
+
var expect = chai.expect;
|
19
|
+
var assert = chai.assert;
|
20
|
+
|
21
|
+
chai.use(chaiHttp);
|
22
|
+
|
23
|
+
describe('FaqKBRoute', () => {
|
24
|
+
|
25
|
+
describe('/create', () => {
|
26
|
+
|
27
|
+
// it('completions', (done) => {
|
28
|
+
|
29
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
30
|
+
// var pwd = "pwd";
|
31
|
+
|
32
|
+
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
33
|
+
// projectService.create("test-openai-create", savedUser._id).then((savedProject) => {
|
34
|
+
|
35
|
+
// chai.request(server)
|
36
|
+
// .post('/' + savedProject._id + '/kbsettings')
|
37
|
+
// .auth(email, pwd)
|
38
|
+
// .send({}) // can be empty
|
39
|
+
// .end((err, res) => {
|
40
|
+
// if (log) { console.log("create kbsettings res.body: ", res.body); }
|
41
|
+
// res.should.have.status(200);
|
42
|
+
// res.body.should.be.a('object');
|
43
|
+
|
44
|
+
// chai.request(server)
|
45
|
+
// .put('/' + savedProject._id + "/kbsettings/" + res.body._id)
|
46
|
+
// .auth(email, pwd)
|
47
|
+
// .send({ gptkey: "sk-12345678" })
|
48
|
+
// .end((err, res) => {
|
49
|
+
// if (log) { console.log("add kb to kb settings res.body: ", res.body); }
|
50
|
+
// res.should.have.status(200);
|
51
|
+
// res.body.should.be.a('object');
|
52
|
+
|
53
|
+
// chai.request(server)
|
54
|
+
// .post('/' + savedProject._id + '/openai')
|
55
|
+
// .auth(email, pwd)
|
56
|
+
// .send({ question: "Provide 3 names for a dog", context: "you are an awesome assistant", max_tokens: 100, temperature: 0, model: "gpt-3.5-turbo" })
|
57
|
+
// .end((err, res) => {
|
58
|
+
// console.log("res.body (1): ", res.body);
|
59
|
+
// console.log("res.status: ", res.status);
|
60
|
+
|
61
|
+
// done();
|
62
|
+
// })
|
63
|
+
|
64
|
+
// })
|
65
|
+
// })
|
66
|
+
// })
|
67
|
+
// })
|
68
|
+
// }).timeout(20000)
|
69
|
+
|
70
|
+
it('completions missing gptkey', (done) => {
|
71
|
+
|
72
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
73
|
+
var pwd = "pwd";
|
74
|
+
|
75
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
76
|
+
projectService.create("test-openai-create", savedUser._id).then((savedProject) => {
|
77
|
+
|
78
|
+
chai.request(server)
|
79
|
+
.post('/' + savedProject._id + '/kbsettings')
|
80
|
+
.auth(email, pwd)
|
81
|
+
.send({}) // can be empty
|
82
|
+
.end((err, res) => {
|
83
|
+
if (log) { console.log("create kbsettings res.body: ", res.body); }
|
84
|
+
res.should.have.status(200);
|
85
|
+
res.body.should.be.a('object');
|
86
|
+
|
87
|
+
chai.request(server)
|
88
|
+
.post('/' + savedProject._id + '/openai')
|
89
|
+
.auth(email, pwd)
|
90
|
+
.send({ question: "Provide 3 names for a dog", context: "you are an awesome assistant", max_tokens: 100, temperature: 0, model: "gpt-3.5-turbo" })
|
91
|
+
.end((err, res) => {
|
92
|
+
if (log) {console.log("res.body: ", res.body);}
|
93
|
+
res.should.have.status(400);
|
94
|
+
res.body.should.be.a('object');
|
95
|
+
expect(res.body.success).to.equal(false);
|
96
|
+
expect(res.body.message).to.equal("Missing gptkey parameter");
|
97
|
+
|
98
|
+
done();
|
99
|
+
})
|
100
|
+
})
|
101
|
+
})
|
102
|
+
})
|
103
|
+
}).timeout(20000)
|
104
|
+
|
105
|
+
it('completions missing settings', (done) => {
|
106
|
+
|
107
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
108
|
+
var pwd = "pwd";
|
109
|
+
|
110
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
111
|
+
projectService.create("test-openai-create", savedUser._id).then((savedProject) => {
|
112
|
+
|
113
|
+
chai.request(server)
|
114
|
+
.post('/' + savedProject._id + '/openai')
|
115
|
+
.auth(email, pwd)
|
116
|
+
.send({ question: "Provide 3 names for a dog", context: "you are an awesome assistant", max_tokens: 100, temperature: 0, model: "gpt-3.5-turbo" })
|
117
|
+
.end((err, res) => {
|
118
|
+
if (log) {console.log("res.body: ", res.body);}
|
119
|
+
res.should.have.status(400);
|
120
|
+
res.body.should.be.a('object');
|
121
|
+
expect(res.body.success).to.equal(false);
|
122
|
+
expect(res.body.message).to.equal("Missing gptkey parameter (settings not exist)");
|
123
|
+
|
124
|
+
done();
|
125
|
+
})
|
126
|
+
})
|
127
|
+
})
|
128
|
+
}).timeout(20000)
|
129
|
+
|
130
|
+
});
|
131
|
+
|
132
|
+
});
|
133
|
+
|
134
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
//During the test the env variable is set to test
|
2
|
+
process.env.NODE_ENV = 'test';
|
3
|
+
|
4
|
+
let chai = require('chai');
|
5
|
+
let chaiHttp = require('chai-http');
|
6
|
+
let server = require('../app');
|
7
|
+
|
8
|
+
chai.use(chaiHttp);
|
9
|
+
|
10
|
+
var expect = require('chai').expect;
|
11
|
+
var assert = require('chai').assert;
|
12
|
+
var config = require('../config/database');
|
13
|
+
|
14
|
+
var mongoose = require('mongoose');
|
15
|
+
var winston = require('../config/winston');
|
16
|
+
|
17
|
+
// var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
|
18
|
+
// if (!databaseUri) {
|
19
|
+
// console.log('DATABASE_URI not specified, falling back to localhost.');
|
20
|
+
// }
|
21
|
+
|
22
|
+
// mongoose.connect(databaseUri || config.database);
|
23
|
+
mongoose.connect(config.databasetest);
|
24
|
+
|
25
|
+
var userService = require('../services/userService');
|
26
|
+
|
27
|
+
|
28
|
+
describe('UserService()', function () {
|
29
|
+
|
30
|
+
it('loginemail', (done) => {
|
31
|
+
var now = Date.now();
|
32
|
+
var email = "test-UserService-signup-" + now + "@email.com";
|
33
|
+
var pwd = "pwd";
|
34
|
+
|
35
|
+
userService.signup(email , pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
|
36
|
+
expect(savedUser.email).to.equal("test-userservice-signup-" + now + "@email.com");
|
37
|
+
expect(savedUser.firstname).to.equal( "Test Firstname");
|
38
|
+
expect(savedUser.lastname).to.equal("Test lastname");
|
39
|
+
|
40
|
+
chai.request(server)
|
41
|
+
.post('/users/loginemail')
|
42
|
+
.auth(email, pwd)
|
43
|
+
.send({ "id_project": "123456789" })
|
44
|
+
.end((err, res) => {
|
45
|
+
console.log("res.body: ", res.body);
|
46
|
+
console.log("res.status: ", res.status);
|
47
|
+
|
48
|
+
done();
|
49
|
+
})
|
50
|
+
|
51
|
+
|
52
|
+
}).catch(function(err) {
|
53
|
+
winston.error("test reject", err);
|
54
|
+
assert.isNotOk(err,'Promise error');
|
55
|
+
done();
|
56
|
+
});
|
57
|
+
|
58
|
+
})
|
59
|
+
|
60
|
+
|
61
|
+
});
|
62
|
+
|
63
|
+
|
package/routes/openai_kbs.js
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
var express = require('express');
|
2
|
-
var OpenaiKbs = require('../models/openai_kbs');
|
3
|
-
var router = express.Router();
|
4
|
-
|
5
|
-
|
6
|
-
router.get('/', async (req, res) => {
|
7
|
-
|
8
|
-
let project_id = req.projectid;
|
9
|
-
|
10
|
-
OpenaiKbs.find({ id_project: project_id }, (err, kbs) => {
|
11
|
-
if (err) {
|
12
|
-
console.error("find all kbs error: ", err);
|
13
|
-
return res.status(500).send({ success: false, error: err });
|
14
|
-
} else {
|
15
|
-
return res.status(200).send(kbs);
|
16
|
-
}
|
17
|
-
})
|
18
|
-
})
|
19
|
-
|
20
|
-
router.post('/', async (req, res) => {
|
21
|
-
|
22
|
-
let body = req.body;
|
23
|
-
|
24
|
-
let new_kbs = new OpenaiKbs({
|
25
|
-
name: body.name,
|
26
|
-
url: body.url,
|
27
|
-
id_project: req.projectid,
|
28
|
-
gptkey: req.body.gptkey
|
29
|
-
})
|
30
|
-
|
31
|
-
new_kbs.save(function (err, savedKbs) {
|
32
|
-
if (err) {
|
33
|
-
console.error("save new kbs error: ", err);
|
34
|
-
return res.status(500).send({ success: false, error: err});
|
35
|
-
} else {
|
36
|
-
return res.status(200).send(savedKbs);
|
37
|
-
}
|
38
|
-
})
|
39
|
-
})
|
40
|
-
|
41
|
-
router.put('/', async (req, res) => {
|
42
|
-
// to be implemented
|
43
|
-
})
|
44
|
-
|
45
|
-
router.delete('/:kbs_id', async (req, res) => {
|
46
|
-
let kbs_id = req.params.kbs_id;
|
47
|
-
|
48
|
-
OpenaiKbs.findOneAndDelete( { _id: kbs_id }, (err, kbDeleted) => {
|
49
|
-
if (err) {
|
50
|
-
console.error("find one and delete kbs error: ", err);
|
51
|
-
return res.status(500).send({ success: false, error: err});
|
52
|
-
} else {
|
53
|
-
return res.status(200).send({ success: true, message: 'Knowledge Base deleted successfully', openai_kb: kbDeleted });
|
54
|
-
}
|
55
|
-
})
|
56
|
-
})
|
57
|
-
|
58
|
-
module.exports = router;
|
package/test/openaiKbsRoute.js
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
//During the test the env variable is set to test
|
2
|
-
process.env.NODE_ENV = 'test';
|
3
|
-
|
4
|
-
let log = false;
|
5
|
-
|
6
|
-
//Require the dev-dependencies
|
7
|
-
let chai = require('chai');
|
8
|
-
let chaiHttp = require('chai-http');
|
9
|
-
let server = require('../app');
|
10
|
-
let should = chai.should();
|
11
|
-
var fs = require('fs');
|
12
|
-
const path = require('path');
|
13
|
-
|
14
|
-
// chai.config.includeStack = true;
|
15
|
-
|
16
|
-
var expect = chai.expect;
|
17
|
-
var assert = chai.assert;
|
18
|
-
|
19
|
-
chai.use(chaiHttp);
|
20
|
-
|
21
|
-
describe('FaqKBRoute', () => {
|
22
|
-
|
23
|
-
describe('/create', () => {
|
24
|
-
|
25
|
-
it('home', (done) => {
|
26
|
-
|
27
|
-
})
|
28
|
-
|
29
|
-
it('create', (done) => {
|
30
|
-
|
31
|
-
var email = "test-signup-" + Date.now() + "@email.com";
|
32
|
-
var pwd = "pwd";
|
33
|
-
|
34
|
-
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
35
|
-
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
36
|
-
chai.request(server)
|
37
|
-
.post('/' + savedProject._id + '/faq_kb')
|
38
|
-
.auth(email, pwd)
|
39
|
-
.send({ "name": "testbot", type: "external", language: 'fr' })
|
40
|
-
.end((err, res) => {
|
41
|
-
if (log) {
|
42
|
-
console.log("res.body", res.body);
|
43
|
-
}
|
44
|
-
res.should.have.status(200);
|
45
|
-
res.body.should.be.a('object');
|
46
|
-
expect(res.body.name).to.equal("testbot");
|
47
|
-
expect(res.body.language).to.equal("fr");
|
48
|
-
|
49
|
-
chai.request(server)
|
50
|
-
.get('/' + savedProject._id + '/faq_kb/' + res.body._id)
|
51
|
-
.auth(email, pwd)
|
52
|
-
.end((err, res) => {
|
53
|
-
if (log) {
|
54
|
-
console.log("res.body", res.body);
|
55
|
-
}
|
56
|
-
res.should.have.status(200);
|
57
|
-
|
58
|
-
done();
|
59
|
-
});
|
60
|
-
});
|
61
|
-
|
62
|
-
|
63
|
-
});
|
64
|
-
});
|
65
|
-
|
66
|
-
}).timeout(20000);
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
});
|
72
|
-
|
73
|
-
});
|
74
|
-
|
75
|
-
|