@tiledesk/tiledesk-server 2.10.92 → 2.10.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/models/kbConstants.js +12 -0
- package/models/kb_setting.js +1 -0
- package/package.json +1 -1
- package/routes/admin.js +1 -2
- package/routes/kb.js +242 -3
- package/test/faqRoute.js +3 -3
- package/test/faqkbRoute.js +6 -6
- package/test/fileRoute.js +2 -2
- package/test/fixtures/exported_namespace.json +62 -0
- package/test/imageRoute.js +11 -11
- package/test/kbRoute.js +601 -562
- package/test/quoteManager.js +1 -1
- package/test/webhookRoute.js +1 -1
- /package/test/{TooManykbUrlsList.txt → fixtures/TooManykbUrlsList.txt} +0 -0
- /package/test/{example-faqs.csv → fixtures/example-faqs.csv} +0 -0
- /package/test/{example-json-intents.txt → fixtures/example-json-intents.txt} +0 -0
- /package/test/{example-json-multiple-operation-mock.js → fixtures/example-json-multiple-operation-mock.js} +0 -0
- /package/test/{example-json-rules.txt → fixtures/example-json-rules.txt} +0 -0
- /package/test/{example-json.txt → fixtures/example-json.txt} +0 -0
- /package/test/{example-kb-faqs.csv → fixtures/example-kb-faqs.csv} +0 -0
- /package/test/{example-webhook-json.txt → fixtures/example-webhook-json.txt} +0 -0
- /package/test/{example.json → fixtures/example.json} +0 -0
- /package/test/{kbUrlsList.txt → fixtures/kbUrlsList.txt} +0 -0
- /package/test/{sample.pdf → fixtures/sample.pdf} +0 -0
- /package/test/{test-image.png → fixtures/test-image.png} +0 -0
- /package/test/{chatbot-mock.js → mock/chatbotMock.js} +0 -0
- /package/test/mock/{MockTdCache.js → tdCacheMock.js} +0 -0
package/test/kbRoute.js
CHANGED
@@ -39,7 +39,6 @@ describe('KbRoute', () => {
|
|
39
39
|
|
40
40
|
describe('/create', () => {
|
41
41
|
|
42
|
-
|
43
42
|
// NEW TESTS
|
44
43
|
it('create-new-kb', (done) => {
|
45
44
|
|
@@ -444,7 +443,7 @@ describe('KbRoute', () => {
|
|
444
443
|
.post('/' + savedProject._id + '/kb/csv?namespace=' + namespace_id)
|
445
444
|
.auth(email, pwd)
|
446
445
|
.set('Content-Type', 'text/csv')
|
447
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-kb-faqs.csv')), 'example-kb-faqs.csv')
|
446
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/example-kb-faqs.csv')), 'example-kb-faqs.csv')
|
448
447
|
.field('delimiter', ';')
|
449
448
|
.end((err, res) => {
|
450
449
|
|
@@ -462,7 +461,6 @@ describe('KbRoute', () => {
|
|
462
461
|
|
463
462
|
}).timeout(10000)
|
464
463
|
|
465
|
-
|
466
464
|
/**
|
467
465
|
* If you try to add content to a project that has no namespace, it returns 403 forbidden.
|
468
466
|
*/
|
@@ -478,7 +476,7 @@ describe('KbRoute', () => {
|
|
478
476
|
.post('/' + savedProject._id + '/kb/multi?namespace=123456')
|
479
477
|
.auth(email, pwd)
|
480
478
|
.set('Content-Type', 'text/plain')
|
481
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
479
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
482
480
|
.end((err, res) => {
|
483
481
|
|
484
482
|
if (err) { console.error("err: ", err); }
|
@@ -498,7 +496,6 @@ describe('KbRoute', () => {
|
|
498
496
|
|
499
497
|
}).timeout(10000)
|
500
498
|
|
501
|
-
|
502
499
|
/**
|
503
500
|
* If you try to add content to a namespace that does not belong to the selected project and
|
504
501
|
* the project has at least one namesapce, it returns 403 forbidden.
|
@@ -526,7 +523,7 @@ describe('KbRoute', () => {
|
|
526
523
|
.post('/' + savedProject._id + '/kb/multi?namespace=fakenamespaceid')
|
527
524
|
.auth(email, pwd)
|
528
525
|
.set('Content-Type', 'text/plain')
|
529
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
526
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
530
527
|
.end((err, res) => {
|
531
528
|
|
532
529
|
if (err) { console.error("err: ", err); }
|
@@ -572,7 +569,7 @@ describe('KbRoute', () => {
|
|
572
569
|
.post('/' + savedProject._id + '/kb/multi?namespace=' + namespace_id)
|
573
570
|
.auth(email, pwd)
|
574
571
|
.set('Content-Type', 'text/plain')
|
575
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
572
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
576
573
|
.end((err, res) => {
|
577
574
|
|
578
575
|
if (err) { console.error("err: ", err); }
|
@@ -782,559 +779,6 @@ describe('KbRoute', () => {
|
|
782
779
|
});
|
783
780
|
});
|
784
781
|
|
785
|
-
|
786
|
-
// OLD TESTS
|
787
|
-
// it('createNewKb', (done) => {
|
788
|
-
|
789
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
790
|
-
// var pwd = "pwd";
|
791
|
-
|
792
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
793
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
794
|
-
|
795
|
-
// let kb = {
|
796
|
-
// name: "example_name5",
|
797
|
-
// type: "url",
|
798
|
-
// source: "https://www.exampleurl5.com",
|
799
|
-
// content: "",
|
800
|
-
// }
|
801
|
-
|
802
|
-
// chai.request(server)
|
803
|
-
// .post('/' + savedProject._id + '/kb')
|
804
|
-
// .auth(email, pwd)
|
805
|
-
// .send(kb) // can be empty
|
806
|
-
// .end((err, res) => {
|
807
|
-
|
808
|
-
// if (err) { console.error("err: ", err); }
|
809
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
810
|
-
|
811
|
-
// res.should.have.status(200);
|
812
|
-
// res.body.should.be.a('object');
|
813
|
-
|
814
|
-
// done();
|
815
|
-
|
816
|
-
|
817
|
-
// })
|
818
|
-
|
819
|
-
// });
|
820
|
-
// });
|
821
|
-
|
822
|
-
// }).timeout(10000);
|
823
|
-
|
824
|
-
// logic in standby
|
825
|
-
// it('createNewKb-namespaceNotBelongsProject', (done) => {
|
826
|
-
|
827
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
828
|
-
// var pwd = "pwd";
|
829
|
-
|
830
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
831
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
832
|
-
|
833
|
-
// let kb = {
|
834
|
-
// name: "example_name5",
|
835
|
-
// type: "url",
|
836
|
-
// source: "https://www.exampleurl5.com",
|
837
|
-
// content: "",
|
838
|
-
// namespace: "fakenamespace"
|
839
|
-
// }
|
840
|
-
|
841
|
-
// chai.request(server)
|
842
|
-
// .post('/' + savedProject._id + '/kb')
|
843
|
-
// .auth(email, pwd)
|
844
|
-
// .send(kb) // can be empty
|
845
|
-
// .end((err, res) => {
|
846
|
-
|
847
|
-
// if (err) { console.error("err: ", err); }
|
848
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
849
|
-
|
850
|
-
// res.should.have.status(403);
|
851
|
-
// res.body.should.be.a('object');
|
852
|
-
// expect(res.body.success).to.equal(false);
|
853
|
-
// expect(res.body.error).to.equal("Not allowed. The namespace does not belong to the current project.");
|
854
|
-
|
855
|
-
// done();
|
856
|
-
|
857
|
-
|
858
|
-
// })
|
859
|
-
|
860
|
-
// });
|
861
|
-
// });
|
862
|
-
|
863
|
-
//}).timeout(10000);
|
864
|
-
|
865
|
-
// it('createNewKb-replaceNamespace', (done) => {
|
866
|
-
|
867
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
868
|
-
// var pwd = "pwd";
|
869
|
-
|
870
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
871
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
872
|
-
|
873
|
-
// let kb = {
|
874
|
-
// name: "example_name5",
|
875
|
-
// type: "url",
|
876
|
-
// source: "https://www.exampleurl5.com",
|
877
|
-
// content: "",
|
878
|
-
// namespace: "fakenamespace"
|
879
|
-
// }
|
880
|
-
|
881
|
-
// chai.request(server)
|
882
|
-
// .post('/' + savedProject._id + '/kb')
|
883
|
-
// .auth(email, pwd)
|
884
|
-
// .send(kb) // can be empty
|
885
|
-
// .end((err, res) => {
|
886
|
-
|
887
|
-
// if (err) { console.error("err: ", err); }
|
888
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
889
|
-
|
890
|
-
// res.should.have.status(200);
|
891
|
-
// res.body.should.be.a('object');
|
892
|
-
// expect(res.body.value.namespace).not.equal("fakenamespace");
|
893
|
-
// expect(res.body.value.namespace).to.equal(savedProject._id.toString());
|
894
|
-
|
895
|
-
// done();
|
896
|
-
|
897
|
-
|
898
|
-
// })
|
899
|
-
|
900
|
-
// });
|
901
|
-
// });
|
902
|
-
|
903
|
-
// }).timeout(10000);
|
904
|
-
|
905
|
-
// it('getWithQueries', (done) => {
|
906
|
-
|
907
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
908
|
-
// var pwd = "pwd";
|
909
|
-
|
910
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
911
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
912
|
-
|
913
|
-
// let kb1 = {
|
914
|
-
// name: "example_name1",
|
915
|
-
// type: "url",
|
916
|
-
// source: "https://www.exampleurl1.com",
|
917
|
-
// content: ""
|
918
|
-
// }
|
919
|
-
|
920
|
-
// let kb2 = {
|
921
|
-
// name: "example_name2",
|
922
|
-
// type: "text",
|
923
|
-
// source: "example_name2",
|
924
|
-
// content: "example content"
|
925
|
-
// }
|
926
|
-
|
927
|
-
// let kb3 = {
|
928
|
-
// name: "example_name3",
|
929
|
-
// type: "url",
|
930
|
-
// source: "https://www.exampleurl3.com",
|
931
|
-
// content: ""
|
932
|
-
// }
|
933
|
-
|
934
|
-
// chai.request(server)
|
935
|
-
// .post('/' + savedProject._id + "/kb")
|
936
|
-
// .auth(email, pwd)
|
937
|
-
// .send(kb1)
|
938
|
-
// .end((err, res) => {
|
939
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
940
|
-
// res.should.have.status(200);
|
941
|
-
|
942
|
-
// setTimeout(() => {
|
943
|
-
// chai.request(server)
|
944
|
-
// .post('/' + savedProject._id + "/kb")
|
945
|
-
// .auth(email, pwd)
|
946
|
-
// .send(kb2)
|
947
|
-
// .end((err, res) => {
|
948
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
949
|
-
// res.should.have.status(200);
|
950
|
-
|
951
|
-
// setTimeout(() => {
|
952
|
-
// chai.request(server)
|
953
|
-
// .post('/' + savedProject._id + "/kb")
|
954
|
-
// .auth(email, pwd)
|
955
|
-
// .send(kb3)
|
956
|
-
// .end((err, res) => {
|
957
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
958
|
-
// res.should.have.status(200);
|
959
|
-
|
960
|
-
// let query = "?status=100&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example";
|
961
|
-
// //let query = "";
|
962
|
-
// console.log("query: ", query);
|
963
|
-
|
964
|
-
// chai.request(server)
|
965
|
-
// .get('/' + savedProject._id + "/kb" + query)
|
966
|
-
// .auth(email, pwd)
|
967
|
-
// .end((err, res) => {
|
968
|
-
// if (log) { console.log("getall res.body: ", res.body); }
|
969
|
-
// res.should.have.status(200);
|
970
|
-
// res.body.should.be.a('object');
|
971
|
-
// res.body.kbs.should.be.a('array');
|
972
|
-
// expect(res.body.kbs.length).to.equal(2);
|
973
|
-
// expect(res.body.count).to.equal(2);
|
974
|
-
// res.body.query.should.be.a('object');
|
975
|
-
// expect(res.body.query.status).to.equal(100);
|
976
|
-
// expect(res.body.query.limit).to.equal(5);
|
977
|
-
// expect(res.body.query.page).to.equal(0);
|
978
|
-
// expect(res.body.query.direction).to.equal(-1);
|
979
|
-
// expect(res.body.query.sortField).to.equal("updatedAt");
|
980
|
-
// expect(res.body.query.search).to.equal("example");
|
981
|
-
|
982
|
-
// done();
|
983
|
-
|
984
|
-
// })
|
985
|
-
|
986
|
-
// })
|
987
|
-
// }, 1000)
|
988
|
-
// })
|
989
|
-
// }, 1000)
|
990
|
-
|
991
|
-
|
992
|
-
// })
|
993
|
-
// })
|
994
|
-
// })
|
995
|
-
// }).timeout(20000)
|
996
|
-
|
997
|
-
// it('scrapeSingle', (done) => {
|
998
|
-
|
999
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1000
|
-
// var pwd = "pwd";
|
1001
|
-
|
1002
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1003
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1004
|
-
|
1005
|
-
// let kb = {
|
1006
|
-
// name: "example_name6",
|
1007
|
-
// type: "url",
|
1008
|
-
// source: "https://www.exampleurl6.com",
|
1009
|
-
// content: ""
|
1010
|
-
// }
|
1011
|
-
|
1012
|
-
// chai.request(server)
|
1013
|
-
// .post('/' + savedProject._id + '/kb')
|
1014
|
-
// .auth(email, pwd)
|
1015
|
-
// .send(kb) // can be empty
|
1016
|
-
// .end((err, res) => {
|
1017
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
1018
|
-
// res.should.have.status(200);
|
1019
|
-
|
1020
|
-
// let kbid = res.body.value._id;
|
1021
|
-
// console.log("kbid: ", kbid)
|
1022
|
-
// chai.request(server)
|
1023
|
-
// .post('/' + savedProject._id + "/kb/scrape/single")
|
1024
|
-
// .auth(email, pwd)
|
1025
|
-
// .send({ id: kbid })
|
1026
|
-
// .end((err, res) => {
|
1027
|
-
// if (log) { console.log("single scrape res.body: ", res.body); }
|
1028
|
-
// //res.should.have.status(200);
|
1029
|
-
// // res.body.should.be.a('object');
|
1030
|
-
// // expect(res.body.id_project).to.equal(savedProject._id.toString())
|
1031
|
-
// // expect(res.body.maxKbsNumber).to.equal(3);
|
1032
|
-
// // expect(res.body.maxPagesNumber).to.equal(1000);
|
1033
|
-
// // expect(res.body.kbs).is.an('array').that.is.empty;
|
1034
|
-
// done();
|
1035
|
-
|
1036
|
-
// })
|
1037
|
-
|
1038
|
-
|
1039
|
-
// // res.body.should.be.a('object');
|
1040
|
-
// // expect(res.body.id_project).to.equal(savedProject._id.toString());
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
// })
|
1046
|
-
|
1047
|
-
// });
|
1048
|
-
// });
|
1049
|
-
|
1050
|
-
// });
|
1051
|
-
|
1052
|
-
// it('scrapeSingle-namespaceNotBelongsProject', (done) => {
|
1053
|
-
|
1054
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1055
|
-
// var pwd = "pwd";
|
1056
|
-
|
1057
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1058
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1059
|
-
|
1060
|
-
// let kb = {
|
1061
|
-
// name: "example_name6",
|
1062
|
-
// type: "url",
|
1063
|
-
// source: "https://www.exampleurl6.com",
|
1064
|
-
// content: ""
|
1065
|
-
// }
|
1066
|
-
|
1067
|
-
// chai.request(server)
|
1068
|
-
// .post('/' + savedProject._id + '/kb')
|
1069
|
-
// .auth(email, pwd)
|
1070
|
-
// .send(kb) // can be empty
|
1071
|
-
// .end((err, res) => {
|
1072
|
-
// if (log) { console.log("create kb res.body: ", res.body); }
|
1073
|
-
// res.should.have.status(200);
|
1074
|
-
|
1075
|
-
// let kbid = res.body.value._id;
|
1076
|
-
// console.log("kbid: ", kbid)
|
1077
|
-
// chai.request(server)
|
1078
|
-
// .post('/' + savedProject._id + "/kb/scrape/single")
|
1079
|
-
// .auth(email, pwd)
|
1080
|
-
// .send({ id: kbid })
|
1081
|
-
// .end((err, res) => {
|
1082
|
-
// if (log) { console.log("single scrape res.body: ", res.body); }
|
1083
|
-
// //res.should.have.status(200);
|
1084
|
-
// // res.body.should.be.a('object');
|
1085
|
-
// // expect(res.body.id_project).to.equal(savedProject._id.toString())
|
1086
|
-
// // expect(res.body.maxKbsNumber).to.equal(3);
|
1087
|
-
// // expect(res.body.maxPagesNumber).to.equal(1000);
|
1088
|
-
// // expect(res.body.kbs).is.an('array').that.is.empty;
|
1089
|
-
// done();
|
1090
|
-
|
1091
|
-
// })
|
1092
|
-
|
1093
|
-
|
1094
|
-
// // res.body.should.be.a('object');
|
1095
|
-
// // expect(res.body.id_project).to.equal(savedProject._id.toString());
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
// })
|
1101
|
-
// });
|
1102
|
-
// });
|
1103
|
-
// });
|
1104
|
-
|
1105
|
-
// it('multiadd', (done) => {
|
1106
|
-
|
1107
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1108
|
-
// var pwd = "pwd";
|
1109
|
-
|
1110
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1111
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1112
|
-
|
1113
|
-
// chai.request(server)
|
1114
|
-
// .post('/' + savedProject._id + '/kb/multi')
|
1115
|
-
// .auth(email, pwd)
|
1116
|
-
// .set('Content-Type', 'text/plain')
|
1117
|
-
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1118
|
-
// .end((err, res) => {
|
1119
|
-
|
1120
|
-
// // console.log("res.body: ", res.body)
|
1121
|
-
// res.should.have.status(200);
|
1122
|
-
// expect(res.body.length).to.equal(4)
|
1123
|
-
|
1124
|
-
// done();
|
1125
|
-
|
1126
|
-
// // setTimeout(() => {
|
1127
|
-
|
1128
|
-
// // chai.request(server)
|
1129
|
-
// // .post('/' + savedProject._id + '/kb/multi')
|
1130
|
-
// // .auth(email, pwd)
|
1131
|
-
// // .set('Content-Type', 'text/plain')
|
1132
|
-
// // .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1133
|
-
// // .end((err, res) => {
|
1134
|
-
|
1135
|
-
// // // console.log("res.body: ", res.body);
|
1136
|
-
// // res.should.have.status(200);
|
1137
|
-
// // expect(res.body.length).to.equal(4)
|
1138
|
-
|
1139
|
-
// // done()
|
1140
|
-
// // })
|
1141
|
-
// // }, 2000)
|
1142
|
-
|
1143
|
-
// })
|
1144
|
-
|
1145
|
-
// });
|
1146
|
-
// });
|
1147
|
-
|
1148
|
-
// }).timeout(10000)
|
1149
|
-
|
1150
|
-
// it('multiaddFail', (done) => {
|
1151
|
-
|
1152
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1153
|
-
// var pwd = "pwd";
|
1154
|
-
|
1155
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1156
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1157
|
-
|
1158
|
-
// chai.request(server)
|
1159
|
-
// .post('/' + savedProject._id + '/kb/multi')
|
1160
|
-
// .auth(email, pwd)
|
1161
|
-
// .set('Content-Type', 'text/plain')
|
1162
|
-
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1163
|
-
// .end((err, res) => {
|
1164
|
-
|
1165
|
-
// // console.log("res.body: ", res.body)
|
1166
|
-
// res.should.have.status(200);
|
1167
|
-
// expect(res.body.length).to.equal(4)
|
1168
|
-
|
1169
|
-
// setTimeout(() => {
|
1170
|
-
|
1171
|
-
// chai.request(server)
|
1172
|
-
// .post('/' + savedProject._id + '/kb/multi')
|
1173
|
-
// .auth(email, pwd)
|
1174
|
-
// .set('Content-Type', 'text/plain')
|
1175
|
-
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1176
|
-
// .end((err, res) => {
|
1177
|
-
|
1178
|
-
// // console.log("res.body: ", res.body);
|
1179
|
-
// res.should.have.status(200);
|
1180
|
-
// expect(res.body.length).to.equal(4)
|
1181
|
-
|
1182
|
-
// done()
|
1183
|
-
// })
|
1184
|
-
// }, 2000)
|
1185
|
-
|
1186
|
-
// })
|
1187
|
-
|
1188
|
-
// });
|
1189
|
-
// });
|
1190
|
-
|
1191
|
-
// }).timeout(10000)
|
1192
|
-
|
1193
|
-
// it('tooManyUrls', (done) => {
|
1194
|
-
|
1195
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1196
|
-
// var pwd = "pwd";
|
1197
|
-
|
1198
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1199
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1200
|
-
|
1201
|
-
// chai.request(server)
|
1202
|
-
// .post('/' + savedProject._id + '/kb/multi')
|
1203
|
-
// .auth(email, pwd)
|
1204
|
-
// .set('Content-Type', 'text/plain')
|
1205
|
-
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './TooManykbUrlsList.txt')), 'TooManykbUrlsList.txt')
|
1206
|
-
// .end((err, res) => {
|
1207
|
-
|
1208
|
-
// // console.log("res.body: ", res.body)
|
1209
|
-
// res.should.have.status(403);
|
1210
|
-
// expect(res.body.success).to.equal(false);
|
1211
|
-
// expect(res.body.error).to.equal("Too many urls. Can't index more than 300 urls at a time.");
|
1212
|
-
|
1213
|
-
// done()
|
1214
|
-
|
1215
|
-
// })
|
1216
|
-
|
1217
|
-
// });
|
1218
|
-
// });
|
1219
|
-
|
1220
|
-
// })
|
1221
|
-
|
1222
|
-
// logic in standby
|
1223
|
-
// it('askkb-namespaceNotBelongsProject', (done) => {
|
1224
|
-
|
1225
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1226
|
-
// var pwd = "pwd";
|
1227
|
-
|
1228
|
-
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1229
|
-
// projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
1230
|
-
|
1231
|
-
// /**
|
1232
|
-
// * README
|
1233
|
-
// * Namespace should be equal to savedProject._id;
|
1234
|
-
// * A generic mongodb ID (like user id) is used instead for test porpouse
|
1235
|
-
// */
|
1236
|
-
// chai.request(server)
|
1237
|
-
// .post('/' + savedProject._id + "/kb/qa")
|
1238
|
-
// .auth(email, pwd)
|
1239
|
-
// .send({ model: "gpt-4", namespace: savedUser._id, question: "sample question"})
|
1240
|
-
// .end((err, res) => {
|
1241
|
-
|
1242
|
-
// if (err) { console.log("error: ", err) };
|
1243
|
-
// if (log) { console.log("res.body: ", res.body) };
|
1244
|
-
|
1245
|
-
// res.should.have.status(403);
|
1246
|
-
// res.body.should.be.a('object');
|
1247
|
-
// expect(res.body.success).to.equal(false);
|
1248
|
-
// expect(res.body.error).to.equal("Not allowed. The namespace does not belong to the current project.");
|
1249
|
-
|
1250
|
-
// done();
|
1251
|
-
// })
|
1252
|
-
// })
|
1253
|
-
// })
|
1254
|
-
// }).timeout(10000)
|
1255
|
-
|
1256
|
-
|
1257
|
-
// it('sitemap', (done) => {
|
1258
|
-
|
1259
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1260
|
-
// var pwd = "pwd";
|
1261
|
-
|
1262
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1263
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1264
|
-
|
1265
|
-
// chai.request(server)
|
1266
|
-
// .post('/' + savedProject._id + '/kb/sitemap')
|
1267
|
-
// .auth(email, pwd)
|
1268
|
-
// // .send({ sitemap: "https://www.wired.it/sitemap.xml" })
|
1269
|
-
// .send({ sitemap: "https://gethelp.tiledesk.com/sitemap.xml" })
|
1270
|
-
// .end((err, res) => {
|
1271
|
-
|
1272
|
-
// if (err) { console.log("error: ", err) };
|
1273
|
-
// if (log) { console.log("res.body: ", res.body) }
|
1274
|
-
|
1275
|
-
// res.should.have.status(200);
|
1276
|
-
// res.body.should.be.a('object');
|
1277
|
-
// res.body.sites.should.be.a('array');
|
1278
|
-
|
1279
|
-
// done();
|
1280
|
-
|
1281
|
-
// })
|
1282
|
-
|
1283
|
-
// });
|
1284
|
-
// });
|
1285
|
-
|
1286
|
-
// }).timeout(10000)
|
1287
|
-
|
1288
|
-
// Ask KB
|
1289
|
-
// it('askkb-key-from-integrations', (done) => {
|
1290
|
-
|
1291
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
1292
|
-
// var pwd = "pwd";
|
1293
|
-
|
1294
|
-
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1295
|
-
// projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
1296
|
-
|
1297
|
-
// chai.request(server)
|
1298
|
-
// .post('/' + savedProject._id + "/integration/")
|
1299
|
-
// .auth(email, pwd)
|
1300
|
-
// .send({ name: "openai", value: { apikey: "sk-testkey", organization: "Testkey" } })
|
1301
|
-
// .end((err, res) => {
|
1302
|
-
|
1303
|
-
// if (err) { console.error("err: ", err) };
|
1304
|
-
// if (log) { console.log("res.body: ", res.body) };
|
1305
|
-
// console.log("Integration created..")
|
1306
|
-
|
1307
|
-
// chai.request(server)
|
1308
|
-
// .get('/' + savedProject._id + '/kb/namespace/all')
|
1309
|
-
// .auth(email, pwd)
|
1310
|
-
// .end((err, res) => {
|
1311
|
-
|
1312
|
-
// if (err) { console.error("err: ", err); }
|
1313
|
-
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1314
|
-
|
1315
|
-
// console.log("namespace created..")
|
1316
|
-
|
1317
|
-
// chai.request(server)
|
1318
|
-
// .post('/' + savedProject._id + "/kb/qa")
|
1319
|
-
// .auth(email, pwd)
|
1320
|
-
// .send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question" })
|
1321
|
-
// .end((err, res) => {
|
1322
|
-
|
1323
|
-
// if (err) { console.error("err: ", err) };
|
1324
|
-
// if (log) { console.log("res.body: ", res.body) };
|
1325
|
-
// console.log("res.body: ", res.body)
|
1326
|
-
// done();
|
1327
|
-
// })
|
1328
|
-
|
1329
|
-
|
1330
|
-
// })
|
1331
|
-
|
1332
|
-
// })
|
1333
|
-
// })
|
1334
|
-
// })
|
1335
|
-
// }).timeout(10000)
|
1336
|
-
|
1337
|
-
// Ask KB
|
1338
782
|
it('askkb-key-from-env', (done) => {
|
1339
783
|
|
1340
784
|
var email = "test-signup-" + Date.now() + "@email.com";
|
@@ -1369,7 +813,6 @@ describe('KbRoute', () => {
|
|
1369
813
|
})
|
1370
814
|
}).timeout(10000)
|
1371
815
|
|
1372
|
-
|
1373
816
|
it('webhook', (done) => {
|
1374
817
|
|
1375
818
|
var email = "test-signup-" + Date.now() + "@email.com";
|
@@ -1518,7 +961,6 @@ describe('KbRoute', () => {
|
|
1518
961
|
|
1519
962
|
describe('/namespaces', () => {
|
1520
963
|
|
1521
|
-
|
1522
964
|
/**
|
1523
965
|
* Get all namespaces of a project.
|
1524
966
|
* If there isn't namespaces for a project_id, the default namespace is created and returned.
|
@@ -1678,6 +1120,52 @@ describe('KbRoute', () => {
|
|
1678
1120
|
});
|
1679
1121
|
})
|
1680
1122
|
|
1123
|
+
it('import-namespace', (done) => {
|
1124
|
+
|
1125
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
1126
|
+
var pwd = "pwd";
|
1127
|
+
|
1128
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1129
|
+
projectService.create("test-namespace-import", savedUser._id).then((savedProject) => {
|
1130
|
+
|
1131
|
+
chai.request(server)
|
1132
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
1133
|
+
.auth(email, pwd)
|
1134
|
+
.end((err, res) => {
|
1135
|
+
|
1136
|
+
if (err) { console.error("err: ", err); }
|
1137
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1138
|
+
|
1139
|
+
res.should.have.status(200);
|
1140
|
+
res.body.should.be.a('array');
|
1141
|
+
expect(res.body[0].name).to.equal("Default");
|
1142
|
+
|
1143
|
+
let namespace_id = res.body[0].id;
|
1144
|
+
|
1145
|
+
chai.request(server)
|
1146
|
+
.post('/' + savedProject._id + '/kb/namespace/import/' + namespace_id)
|
1147
|
+
.auth(email, pwd)
|
1148
|
+
.set('Content-Type', 'text/plain')
|
1149
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/exported_namespace.json')), 'exported_namespace.json')
|
1150
|
+
.end((err, res) => {
|
1151
|
+
|
1152
|
+
if (err) { console.error("err: ", err); }
|
1153
|
+
if (log) { console.log("import contents res.body: ", res.body); }
|
1154
|
+
|
1155
|
+
res.should.have.status(200);
|
1156
|
+
res.body.should.be.a('object');
|
1157
|
+
expect(res.body.success).to.equal(true);
|
1158
|
+
expect(res.body.message).to.equal("Contents imported successfully");
|
1159
|
+
|
1160
|
+
done();
|
1161
|
+
|
1162
|
+
})
|
1163
|
+
|
1164
|
+
})
|
1165
|
+
})
|
1166
|
+
})
|
1167
|
+
})
|
1168
|
+
|
1681
1169
|
/**
|
1682
1170
|
* Update namespaces
|
1683
1171
|
*/
|
@@ -1953,5 +1441,556 @@ describe('KbRoute', () => {
|
|
1953
1441
|
})
|
1954
1442
|
});
|
1955
1443
|
|
1444
|
+
// OLD TESTS
|
1445
|
+
// it('createNewKb', (done) => {
|
1446
|
+
|
1447
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1448
|
+
// var pwd = "pwd";
|
1449
|
+
|
1450
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1451
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1452
|
+
|
1453
|
+
// let kb = {
|
1454
|
+
// name: "example_name5",
|
1455
|
+
// type: "url",
|
1456
|
+
// source: "https://www.exampleurl5.com",
|
1457
|
+
// content: "",
|
1458
|
+
// }
|
1459
|
+
|
1460
|
+
// chai.request(server)
|
1461
|
+
// .post('/' + savedProject._id + '/kb')
|
1462
|
+
// .auth(email, pwd)
|
1463
|
+
// .send(kb) // can be empty
|
1464
|
+
// .end((err, res) => {
|
1465
|
+
|
1466
|
+
// if (err) { console.error("err: ", err); }
|
1467
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1468
|
+
|
1469
|
+
// res.should.have.status(200);
|
1470
|
+
// res.body.should.be.a('object');
|
1471
|
+
|
1472
|
+
// done();
|
1473
|
+
|
1474
|
+
|
1475
|
+
// })
|
1476
|
+
|
1477
|
+
// });
|
1478
|
+
// });
|
1479
|
+
|
1480
|
+
// }).timeout(10000);
|
1481
|
+
|
1482
|
+
// logic in standby
|
1483
|
+
// it('createNewKb-namespaceNotBelongsProject', (done) => {
|
1484
|
+
|
1485
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1486
|
+
// var pwd = "pwd";
|
1487
|
+
|
1488
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1489
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1490
|
+
|
1491
|
+
// let kb = {
|
1492
|
+
// name: "example_name5",
|
1493
|
+
// type: "url",
|
1494
|
+
// source: "https://www.exampleurl5.com",
|
1495
|
+
// content: "",
|
1496
|
+
// namespace: "fakenamespace"
|
1497
|
+
// }
|
1498
|
+
|
1499
|
+
// chai.request(server)
|
1500
|
+
// .post('/' + savedProject._id + '/kb')
|
1501
|
+
// .auth(email, pwd)
|
1502
|
+
// .send(kb) // can be empty
|
1503
|
+
// .end((err, res) => {
|
1504
|
+
|
1505
|
+
// if (err) { console.error("err: ", err); }
|
1506
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1507
|
+
|
1508
|
+
// res.should.have.status(403);
|
1509
|
+
// res.body.should.be.a('object');
|
1510
|
+
// expect(res.body.success).to.equal(false);
|
1511
|
+
// expect(res.body.error).to.equal("Not allowed. The namespace does not belong to the current project.");
|
1512
|
+
|
1513
|
+
// done();
|
1514
|
+
|
1515
|
+
|
1516
|
+
// })
|
1517
|
+
|
1518
|
+
// });
|
1519
|
+
// });
|
1520
|
+
|
1521
|
+
//}).timeout(10000);
|
1522
|
+
|
1523
|
+
// it('createNewKb-replaceNamespace', (done) => {
|
1524
|
+
|
1525
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1526
|
+
// var pwd = "pwd";
|
1527
|
+
|
1528
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1529
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1530
|
+
|
1531
|
+
// let kb = {
|
1532
|
+
// name: "example_name5",
|
1533
|
+
// type: "url",
|
1534
|
+
// source: "https://www.exampleurl5.com",
|
1535
|
+
// content: "",
|
1536
|
+
// namespace: "fakenamespace"
|
1537
|
+
// }
|
1538
|
+
|
1539
|
+
// chai.request(server)
|
1540
|
+
// .post('/' + savedProject._id + '/kb')
|
1541
|
+
// .auth(email, pwd)
|
1542
|
+
// .send(kb) // can be empty
|
1543
|
+
// .end((err, res) => {
|
1544
|
+
|
1545
|
+
// if (err) { console.error("err: ", err); }
|
1546
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1547
|
+
|
1548
|
+
// res.should.have.status(200);
|
1549
|
+
// res.body.should.be.a('object');
|
1550
|
+
// expect(res.body.value.namespace).not.equal("fakenamespace");
|
1551
|
+
// expect(res.body.value.namespace).to.equal(savedProject._id.toString());
|
1552
|
+
|
1553
|
+
// done();
|
1554
|
+
|
1555
|
+
|
1556
|
+
// })
|
1557
|
+
|
1558
|
+
// });
|
1559
|
+
// });
|
1560
|
+
|
1561
|
+
// }).timeout(10000);
|
1562
|
+
|
1563
|
+
// it('getWithQueries', (done) => {
|
1564
|
+
|
1565
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1566
|
+
// var pwd = "pwd";
|
1567
|
+
|
1568
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1569
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1570
|
+
|
1571
|
+
// let kb1 = {
|
1572
|
+
// name: "example_name1",
|
1573
|
+
// type: "url",
|
1574
|
+
// source: "https://www.exampleurl1.com",
|
1575
|
+
// content: ""
|
1576
|
+
// }
|
1577
|
+
|
1578
|
+
// let kb2 = {
|
1579
|
+
// name: "example_name2",
|
1580
|
+
// type: "text",
|
1581
|
+
// source: "example_name2",
|
1582
|
+
// content: "example content"
|
1583
|
+
// }
|
1584
|
+
|
1585
|
+
// let kb3 = {
|
1586
|
+
// name: "example_name3",
|
1587
|
+
// type: "url",
|
1588
|
+
// source: "https://www.exampleurl3.com",
|
1589
|
+
// content: ""
|
1590
|
+
// }
|
1591
|
+
|
1592
|
+
// chai.request(server)
|
1593
|
+
// .post('/' + savedProject._id + "/kb")
|
1594
|
+
// .auth(email, pwd)
|
1595
|
+
// .send(kb1)
|
1596
|
+
// .end((err, res) => {
|
1597
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1598
|
+
// res.should.have.status(200);
|
1599
|
+
|
1600
|
+
// setTimeout(() => {
|
1601
|
+
// chai.request(server)
|
1602
|
+
// .post('/' + savedProject._id + "/kb")
|
1603
|
+
// .auth(email, pwd)
|
1604
|
+
// .send(kb2)
|
1605
|
+
// .end((err, res) => {
|
1606
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1607
|
+
// res.should.have.status(200);
|
1608
|
+
|
1609
|
+
// setTimeout(() => {
|
1610
|
+
// chai.request(server)
|
1611
|
+
// .post('/' + savedProject._id + "/kb")
|
1612
|
+
// .auth(email, pwd)
|
1613
|
+
// .send(kb3)
|
1614
|
+
// .end((err, res) => {
|
1615
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1616
|
+
// res.should.have.status(200);
|
1617
|
+
|
1618
|
+
// let query = "?status=100&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example";
|
1619
|
+
// //let query = "";
|
1620
|
+
// console.log("query: ", query);
|
1621
|
+
|
1622
|
+
// chai.request(server)
|
1623
|
+
// .get('/' + savedProject._id + "/kb" + query)
|
1624
|
+
// .auth(email, pwd)
|
1625
|
+
// .end((err, res) => {
|
1626
|
+
// if (log) { console.log("getall res.body: ", res.body); }
|
1627
|
+
// res.should.have.status(200);
|
1628
|
+
// res.body.should.be.a('object');
|
1629
|
+
// res.body.kbs.should.be.a('array');
|
1630
|
+
// expect(res.body.kbs.length).to.equal(2);
|
1631
|
+
// expect(res.body.count).to.equal(2);
|
1632
|
+
// res.body.query.should.be.a('object');
|
1633
|
+
// expect(res.body.query.status).to.equal(100);
|
1634
|
+
// expect(res.body.query.limit).to.equal(5);
|
1635
|
+
// expect(res.body.query.page).to.equal(0);
|
1636
|
+
// expect(res.body.query.direction).to.equal(-1);
|
1637
|
+
// expect(res.body.query.sortField).to.equal("updatedAt");
|
1638
|
+
// expect(res.body.query.search).to.equal("example");
|
1639
|
+
|
1640
|
+
// done();
|
1641
|
+
|
1642
|
+
// })
|
1643
|
+
|
1644
|
+
// })
|
1645
|
+
// }, 1000)
|
1646
|
+
// })
|
1647
|
+
// }, 1000)
|
1648
|
+
|
1649
|
+
|
1650
|
+
// })
|
1651
|
+
// })
|
1652
|
+
// })
|
1653
|
+
// }).timeout(20000)
|
1654
|
+
|
1655
|
+
// it('scrapeSingle', (done) => {
|
1656
|
+
|
1657
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1658
|
+
// var pwd = "pwd";
|
1659
|
+
|
1660
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1661
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1662
|
+
|
1663
|
+
// let kb = {
|
1664
|
+
// name: "example_name6",
|
1665
|
+
// type: "url",
|
1666
|
+
// source: "https://www.exampleurl6.com",
|
1667
|
+
// content: ""
|
1668
|
+
// }
|
1669
|
+
|
1670
|
+
// chai.request(server)
|
1671
|
+
// .post('/' + savedProject._id + '/kb')
|
1672
|
+
// .auth(email, pwd)
|
1673
|
+
// .send(kb) // can be empty
|
1674
|
+
// .end((err, res) => {
|
1675
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1676
|
+
// res.should.have.status(200);
|
1677
|
+
|
1678
|
+
// let kbid = res.body.value._id;
|
1679
|
+
// console.log("kbid: ", kbid)
|
1680
|
+
// chai.request(server)
|
1681
|
+
// .post('/' + savedProject._id + "/kb/scrape/single")
|
1682
|
+
// .auth(email, pwd)
|
1683
|
+
// .send({ id: kbid })
|
1684
|
+
// .end((err, res) => {
|
1685
|
+
// if (log) { console.log("single scrape res.body: ", res.body); }
|
1686
|
+
// //res.should.have.status(200);
|
1687
|
+
// // res.body.should.be.a('object');
|
1688
|
+
// // expect(res.body.id_project).to.equal(savedProject._id.toString())
|
1689
|
+
// // expect(res.body.maxKbsNumber).to.equal(3);
|
1690
|
+
// // expect(res.body.maxPagesNumber).to.equal(1000);
|
1691
|
+
// // expect(res.body.kbs).is.an('array').that.is.empty;
|
1692
|
+
// done();
|
1693
|
+
|
1694
|
+
// })
|
1695
|
+
|
1696
|
+
|
1697
|
+
// // res.body.should.be.a('object');
|
1698
|
+
// // expect(res.body.id_project).to.equal(savedProject._id.toString());
|
1699
|
+
|
1700
|
+
|
1701
|
+
|
1702
|
+
|
1703
|
+
// })
|
1704
|
+
|
1705
|
+
// });
|
1706
|
+
// });
|
1707
|
+
|
1708
|
+
// });
|
1709
|
+
|
1710
|
+
// it('scrapeSingle-namespaceNotBelongsProject', (done) => {
|
1711
|
+
|
1712
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1713
|
+
// var pwd = "pwd";
|
1714
|
+
|
1715
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1716
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1717
|
+
|
1718
|
+
// let kb = {
|
1719
|
+
// name: "example_name6",
|
1720
|
+
// type: "url",
|
1721
|
+
// source: "https://www.exampleurl6.com",
|
1722
|
+
// content: ""
|
1723
|
+
// }
|
1724
|
+
|
1725
|
+
// chai.request(server)
|
1726
|
+
// .post('/' + savedProject._id + '/kb')
|
1727
|
+
// .auth(email, pwd)
|
1728
|
+
// .send(kb) // can be empty
|
1729
|
+
// .end((err, res) => {
|
1730
|
+
// if (log) { console.log("create kb res.body: ", res.body); }
|
1731
|
+
// res.should.have.status(200);
|
1732
|
+
|
1733
|
+
// let kbid = res.body.value._id;
|
1734
|
+
// console.log("kbid: ", kbid)
|
1735
|
+
// chai.request(server)
|
1736
|
+
// .post('/' + savedProject._id + "/kb/scrape/single")
|
1737
|
+
// .auth(email, pwd)
|
1738
|
+
// .send({ id: kbid })
|
1739
|
+
// .end((err, res) => {
|
1740
|
+
// if (log) { console.log("single scrape res.body: ", res.body); }
|
1741
|
+
// //res.should.have.status(200);
|
1742
|
+
// // res.body.should.be.a('object');
|
1743
|
+
// // expect(res.body.id_project).to.equal(savedProject._id.toString())
|
1744
|
+
// // expect(res.body.maxKbsNumber).to.equal(3);
|
1745
|
+
// // expect(res.body.maxPagesNumber).to.equal(1000);
|
1746
|
+
// // expect(res.body.kbs).is.an('array').that.is.empty;
|
1747
|
+
// done();
|
1748
|
+
|
1749
|
+
// })
|
1750
|
+
|
1751
|
+
|
1752
|
+
// // res.body.should.be.a('object');
|
1753
|
+
// // expect(res.body.id_project).to.equal(savedProject._id.toString());
|
1754
|
+
|
1755
|
+
|
1756
|
+
|
1757
|
+
|
1758
|
+
// })
|
1759
|
+
// });
|
1760
|
+
// });
|
1761
|
+
// });
|
1762
|
+
|
1763
|
+
// it('multiadd', (done) => {
|
1764
|
+
|
1765
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1766
|
+
// var pwd = "pwd";
|
1767
|
+
|
1768
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1769
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1770
|
+
|
1771
|
+
// chai.request(server)
|
1772
|
+
// .post('/' + savedProject._id + '/kb/multi')
|
1773
|
+
// .auth(email, pwd)
|
1774
|
+
// .set('Content-Type', 'text/plain')
|
1775
|
+
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1776
|
+
// .end((err, res) => {
|
1777
|
+
|
1778
|
+
// // console.log("res.body: ", res.body)
|
1779
|
+
// res.should.have.status(200);
|
1780
|
+
// expect(res.body.length).to.equal(4)
|
1781
|
+
|
1782
|
+
// done();
|
1783
|
+
|
1784
|
+
// // setTimeout(() => {
|
1785
|
+
|
1786
|
+
// // chai.request(server)
|
1787
|
+
// // .post('/' + savedProject._id + '/kb/multi')
|
1788
|
+
// // .auth(email, pwd)
|
1789
|
+
// // .set('Content-Type', 'text/plain')
|
1790
|
+
// // .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1791
|
+
// // .end((err, res) => {
|
1792
|
+
|
1793
|
+
// // // console.log("res.body: ", res.body);
|
1794
|
+
// // res.should.have.status(200);
|
1795
|
+
// // expect(res.body.length).to.equal(4)
|
1796
|
+
|
1797
|
+
// // done()
|
1798
|
+
// // })
|
1799
|
+
// // }, 2000)
|
1800
|
+
|
1801
|
+
// })
|
1802
|
+
|
1803
|
+
// });
|
1804
|
+
// });
|
1805
|
+
|
1806
|
+
// }).timeout(10000)
|
1807
|
+
|
1808
|
+
// it('multiaddFail', (done) => {
|
1809
|
+
|
1810
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1811
|
+
// var pwd = "pwd";
|
1812
|
+
|
1813
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1814
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1815
|
+
|
1816
|
+
// chai.request(server)
|
1817
|
+
// .post('/' + savedProject._id + '/kb/multi')
|
1818
|
+
// .auth(email, pwd)
|
1819
|
+
// .set('Content-Type', 'text/plain')
|
1820
|
+
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1821
|
+
// .end((err, res) => {
|
1822
|
+
|
1823
|
+
// // console.log("res.body: ", res.body)
|
1824
|
+
// res.should.have.status(200);
|
1825
|
+
// expect(res.body.length).to.equal(4)
|
1826
|
+
|
1827
|
+
// setTimeout(() => {
|
1828
|
+
|
1829
|
+
// chai.request(server)
|
1830
|
+
// .post('/' + savedProject._id + '/kb/multi')
|
1831
|
+
// .auth(email, pwd)
|
1832
|
+
// .set('Content-Type', 'text/plain')
|
1833
|
+
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './kbUrlsList.txt')), 'kbUrlsList.txt')
|
1834
|
+
// .end((err, res) => {
|
1835
|
+
|
1836
|
+
// // console.log("res.body: ", res.body);
|
1837
|
+
// res.should.have.status(200);
|
1838
|
+
// expect(res.body.length).to.equal(4)
|
1839
|
+
|
1840
|
+
// done()
|
1841
|
+
// })
|
1842
|
+
// }, 2000)
|
1843
|
+
|
1844
|
+
// })
|
1845
|
+
|
1846
|
+
// });
|
1847
|
+
// });
|
1848
|
+
|
1849
|
+
// }).timeout(10000)
|
1850
|
+
|
1851
|
+
// it('tooManyUrls', (done) => {
|
1852
|
+
|
1853
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1854
|
+
// var pwd = "pwd";
|
1855
|
+
|
1856
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1857
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1858
|
+
|
1859
|
+
// chai.request(server)
|
1860
|
+
// .post('/' + savedProject._id + '/kb/multi')
|
1861
|
+
// .auth(email, pwd)
|
1862
|
+
// .set('Content-Type', 'text/plain')
|
1863
|
+
// .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './TooManykbUrlsList.txt')), 'TooManykbUrlsList.txt')
|
1864
|
+
// .end((err, res) => {
|
1865
|
+
|
1866
|
+
// // console.log("res.body: ", res.body)
|
1867
|
+
// res.should.have.status(403);
|
1868
|
+
// expect(res.body.success).to.equal(false);
|
1869
|
+
// expect(res.body.error).to.equal("Too many urls. Can't index more than 300 urls at a time.");
|
1870
|
+
|
1871
|
+
// done()
|
1872
|
+
|
1873
|
+
// })
|
1874
|
+
|
1875
|
+
// });
|
1876
|
+
// });
|
1877
|
+
|
1878
|
+
// })
|
1879
|
+
|
1880
|
+
// logic in standby
|
1881
|
+
// it('askkb-namespaceNotBelongsProject', (done) => {
|
1882
|
+
|
1883
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1884
|
+
// var pwd = "pwd";
|
1885
|
+
|
1886
|
+
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1887
|
+
// projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
1888
|
+
|
1889
|
+
// /**
|
1890
|
+
// * README
|
1891
|
+
// * Namespace should be equal to savedProject._id;
|
1892
|
+
// * A generic mongodb ID (like user id) is used instead for test porpouse
|
1893
|
+
// */
|
1894
|
+
// chai.request(server)
|
1895
|
+
// .post('/' + savedProject._id + "/kb/qa")
|
1896
|
+
// .auth(email, pwd)
|
1897
|
+
// .send({ model: "gpt-4", namespace: savedUser._id, question: "sample question"})
|
1898
|
+
// .end((err, res) => {
|
1899
|
+
|
1900
|
+
// if (err) { console.log("error: ", err) };
|
1901
|
+
// if (log) { console.log("res.body: ", res.body) };
|
1902
|
+
|
1903
|
+
// res.should.have.status(403);
|
1904
|
+
// res.body.should.be.a('object');
|
1905
|
+
// expect(res.body.success).to.equal(false);
|
1906
|
+
// expect(res.body.error).to.equal("Not allowed. The namespace does not belong to the current project.");
|
1907
|
+
|
1908
|
+
// done();
|
1909
|
+
// })
|
1910
|
+
// })
|
1911
|
+
// })
|
1912
|
+
// }).timeout(10000)
|
1913
|
+
|
1914
|
+
|
1915
|
+
// it('sitemap', (done) => {
|
1916
|
+
|
1917
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1918
|
+
// var pwd = "pwd";
|
1919
|
+
|
1920
|
+
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1921
|
+
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
1922
|
+
|
1923
|
+
// chai.request(server)
|
1924
|
+
// .post('/' + savedProject._id + '/kb/sitemap')
|
1925
|
+
// .auth(email, pwd)
|
1926
|
+
// // .send({ sitemap: "https://www.wired.it/sitemap.xml" })
|
1927
|
+
// .send({ sitemap: "https://gethelp.tiledesk.com/sitemap.xml" })
|
1928
|
+
// .end((err, res) => {
|
1929
|
+
|
1930
|
+
// if (err) { console.log("error: ", err) };
|
1931
|
+
// if (log) { console.log("res.body: ", res.body) }
|
1932
|
+
|
1933
|
+
// res.should.have.status(200);
|
1934
|
+
// res.body.should.be.a('object');
|
1935
|
+
// res.body.sites.should.be.a('array');
|
1936
|
+
|
1937
|
+
// done();
|
1938
|
+
|
1939
|
+
// })
|
1940
|
+
|
1941
|
+
// });
|
1942
|
+
// });
|
1943
|
+
|
1944
|
+
// }).timeout(10000)
|
1945
|
+
|
1946
|
+
// Ask KB
|
1947
|
+
// it('askkb-key-from-integrations', (done) => {
|
1948
|
+
|
1949
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1950
|
+
// var pwd = "pwd";
|
1951
|
+
|
1952
|
+
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1953
|
+
// projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
1954
|
+
|
1955
|
+
// chai.request(server)
|
1956
|
+
// .post('/' + savedProject._id + "/integration/")
|
1957
|
+
// .auth(email, pwd)
|
1958
|
+
// .send({ name: "openai", value: { apikey: "sk-testkey", organization: "Testkey" } })
|
1959
|
+
// .end((err, res) => {
|
1960
|
+
|
1961
|
+
// if (err) { console.error("err: ", err) };
|
1962
|
+
// if (log) { console.log("res.body: ", res.body) };
|
1963
|
+
// console.log("Integration created..")
|
1964
|
+
|
1965
|
+
// chai.request(server)
|
1966
|
+
// .get('/' + savedProject._id + '/kb/namespace/all')
|
1967
|
+
// .auth(email, pwd)
|
1968
|
+
// .end((err, res) => {
|
1969
|
+
|
1970
|
+
// if (err) { console.error("err: ", err); }
|
1971
|
+
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1972
|
+
|
1973
|
+
// console.log("namespace created..")
|
1974
|
+
|
1975
|
+
// chai.request(server)
|
1976
|
+
// .post('/' + savedProject._id + "/kb/qa")
|
1977
|
+
// .auth(email, pwd)
|
1978
|
+
// .send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question" })
|
1979
|
+
// .end((err, res) => {
|
1980
|
+
|
1981
|
+
// if (err) { console.error("err: ", err) };
|
1982
|
+
// if (log) { console.log("res.body: ", res.body) };
|
1983
|
+
// console.log("res.body: ", res.body)
|
1984
|
+
// done();
|
1985
|
+
// })
|
1986
|
+
|
1987
|
+
|
1988
|
+
// })
|
1989
|
+
|
1990
|
+
// })
|
1991
|
+
// })
|
1992
|
+
// })
|
1993
|
+
// }).timeout(10000)
|
1994
|
+
|
1956
1995
|
|
1957
1996
|
|