@tiledesk/tiledesk-server 2.13.49 → 2.13.50
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 +5 -0
- package/app.js +5 -3
- package/config/kb/embedding.js +7 -0
- package/config/kb/engine.hybrid.js +10 -0
- package/config/kb/engine.js +10 -0
- package/jobs.js +4 -1
- package/models/kb_setting.js +60 -15
- package/models/profile.js +54 -5
- package/models/request.js +1 -1
- package/package.json +4 -4
- package/pubmodules/apps/listener.js +2 -1
- package/routes/kb.js +548 -626
- package/routes/webhook.js +86 -38
- package/services/aiManager.js +464 -0
- package/services/aiService.js +4 -2
- package/test/kbRoute.js +956 -910
package/test/kbRoute.js
CHANGED
|
@@ -4,7 +4,7 @@ process.env.GPTKEY = "fakegptkey";
|
|
|
4
4
|
process.env.LOG_LEVEL = 'critical'
|
|
5
5
|
process.env.KB_WEBHOOK_TOKEN = "testtoken"
|
|
6
6
|
process.env.PINECONE_INDEX = "test-index";
|
|
7
|
-
process.env.PINECONE_TYPE = "
|
|
7
|
+
process.env.PINECONE_TYPE = "serverless";
|
|
8
8
|
process.env.PINECONE_INDEX_HYBRID = "test-index-hybrid";
|
|
9
9
|
process.env.PINECONE_TYPE_HYBRID = "serverless";
|
|
10
10
|
process.env.ADMIN_EMAIL = "admin@tiledesk.com";
|
|
@@ -48,10 +48,13 @@ chai.use(chaiHttp);
|
|
|
48
48
|
|
|
49
49
|
describe('KbRoute', () => {
|
|
50
50
|
|
|
51
|
-
describe('
|
|
51
|
+
describe('Namespaces', () => {
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Get all namespaces of a project.
|
|
55
|
+
* If there isn't namespaces for a project_id, the default namespace is created and returned.
|
|
56
|
+
*/
|
|
57
|
+
it('get-all-namespaces', (done) => {
|
|
55
58
|
|
|
56
59
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
57
60
|
var pwd = "pwd";
|
|
@@ -65,48 +68,115 @@ describe('KbRoute', () => {
|
|
|
65
68
|
.end((err, res) => {
|
|
66
69
|
|
|
67
70
|
if (err) { console.error("err: ", err); }
|
|
68
|
-
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
71
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
69
72
|
|
|
70
73
|
res.should.have.status(200);
|
|
74
|
+
res.body.should.be.a('array');
|
|
71
75
|
expect(res.body.length).to.equal(1);
|
|
72
|
-
|
|
76
|
+
should.not.exist(res.body[0]._id);
|
|
77
|
+
expect(res.body[0].id).to.equal(savedProject._id.toString());
|
|
78
|
+
expect(res.body[0].name).to.equal("Default");
|
|
79
|
+
should.exist(res.body[0].engine);
|
|
80
|
+
expect(res.body[0].engine.name).to.equal('pinecone');
|
|
81
|
+
expect(res.body[0].engine.type).to.equal('serverless');
|
|
82
|
+
expect(res.body[0].engine.vector_size).to.equal(1536);
|
|
83
|
+
expect(res.body[0].engine.index_name).to.equal('test-index');
|
|
84
|
+
should.exist(res.body[0].embedding);
|
|
85
|
+
expect(res.body[0].embedding.provider).to.equal('openai')
|
|
86
|
+
expect(res.body[0].embedding.name).to.equal('text-embedding-ada-002')
|
|
87
|
+
expect(res.body[0].embedding.dimension).to.equal(1536)
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
done();
|
|
90
|
+
})
|
|
75
91
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('create-namespaces-with-engine-similarity', (done) => {
|
|
98
|
+
|
|
99
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
100
|
+
var pwd = "pwd";
|
|
101
|
+
|
|
102
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
103
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
83
104
|
|
|
105
|
+
chai.request(server)
|
|
106
|
+
.post('/' + savedProject._id + '/kb/namespace')
|
|
107
|
+
.auth(email, pwd)
|
|
108
|
+
.send({ name: "MyCustomNamespace" })
|
|
109
|
+
.end((err, res) => {
|
|
110
|
+
|
|
111
|
+
if (err) { console.error("err: ", err) }
|
|
112
|
+
if (log) { console.log("create new namespace res.body: ", res.body) }
|
|
113
|
+
|
|
114
|
+
res.should.have.status(200);
|
|
115
|
+
res.body.should.be.a('object');
|
|
116
|
+
should.not.exist(res.body._id)
|
|
117
|
+
should.exist(res.body.id)
|
|
118
|
+
expect(res.body.name).to.equal('MyCustomNamespace');
|
|
119
|
+
should.exist(res.body.engine)
|
|
120
|
+
expect(res.body.engine.name).to.equal('pinecone');
|
|
121
|
+
expect(res.body.engine.type).to.equal('serverless');
|
|
122
|
+
expect(res.body.engine.vector_size).to.equal(1536);
|
|
123
|
+
expect(res.body.engine.index_name).to.equal('test-index');
|
|
124
|
+
should.exist(res.body.embedding);
|
|
125
|
+
expect(res.body.embedding.provider).to.equal('openai')
|
|
126
|
+
expect(res.body.embedding.name).to.equal('text-embedding-ada-002')
|
|
127
|
+
expect(res.body.embedding.dimension).to.equal(1536)
|
|
128
|
+
|
|
129
|
+
// Get again all namespace. A new default namespace should not be created.
|
|
84
130
|
chai.request(server)
|
|
85
|
-
.
|
|
131
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
86
132
|
.auth(email, pwd)
|
|
87
|
-
.send(kb) // can be empty
|
|
88
133
|
.end((err, res) => {
|
|
89
134
|
|
|
90
135
|
if (err) { console.error("err: ", err); }
|
|
91
|
-
if (log) { console.log("
|
|
136
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
92
137
|
|
|
93
138
|
res.should.have.status(200);
|
|
94
|
-
res.body.should.be.a('
|
|
95
|
-
expect(res.body.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
expect(res.body.value.source).to.equal("https://www.exampleurl5.com")
|
|
99
|
-
expect(res.body.value.status).to.equal(-1)
|
|
139
|
+
res.body.should.be.a('array');
|
|
140
|
+
expect(res.body.length).to.equal(1);
|
|
141
|
+
should.not.exist(res.body[0]._id);
|
|
142
|
+
should.exist(res.body[0].id);
|
|
100
143
|
|
|
101
144
|
done();
|
|
102
145
|
})
|
|
103
146
|
})
|
|
104
147
|
});
|
|
105
148
|
});
|
|
106
|
-
|
|
107
149
|
})
|
|
108
150
|
|
|
109
|
-
it('create-
|
|
151
|
+
it('create-namespaces-with-engine-hybrid-rejected', (done) => {
|
|
152
|
+
|
|
153
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
154
|
+
var pwd = "pwd";
|
|
155
|
+
|
|
156
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
157
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
158
|
+
|
|
159
|
+
chai.request(server)
|
|
160
|
+
.post('/' + savedProject._id + '/kb/namespace')
|
|
161
|
+
.auth(email, pwd)
|
|
162
|
+
.send({ name: "MyCustomNamespace", hybrid: true })
|
|
163
|
+
.end((err, res) => {
|
|
164
|
+
|
|
165
|
+
if (err) { console.error("err: ", err) }
|
|
166
|
+
if (log) { console.log("create new namespace res.body: ", res.body) }
|
|
167
|
+
|
|
168
|
+
res.should.have.status(403);
|
|
169
|
+
res.body.should.be.a('object');
|
|
170
|
+
expect(res.body.success).to.equal(false);
|
|
171
|
+
expect(res.body.error).to.equal('Hybrid mode is not allowed for the current project');
|
|
172
|
+
|
|
173
|
+
done();
|
|
174
|
+
})
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('create-namespaces-with-engine-hybrid-accepted', (done) => {
|
|
110
180
|
|
|
111
181
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
112
182
|
var pwd = "pwd";
|
|
@@ -114,57 +184,120 @@ describe('KbRoute', () => {
|
|
|
114
184
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
115
185
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
116
186
|
|
|
187
|
+
chai.request(server)
|
|
188
|
+
.post('/auth/signin')
|
|
189
|
+
.send({ email: "admin@tiledesk.com", password: "adminadmin" })
|
|
190
|
+
.end((err, res) => {
|
|
191
|
+
|
|
192
|
+
if (err) { console.error("err: ", err) }
|
|
193
|
+
if (log) { console.log("login with superadmin res.body: ", res.body) };
|
|
194
|
+
|
|
195
|
+
res.should.have.status(200);
|
|
196
|
+
res.body.should.be.a('object');
|
|
197
|
+
expect(res.body.success).to.equal(true);
|
|
198
|
+
expect(res.body.token).not.equal(null);
|
|
199
|
+
|
|
200
|
+
let superadmin_token = res.body.token;
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
chai.request(server)
|
|
204
|
+
.put('/projects/' + savedProject._id)
|
|
205
|
+
.set('Authorization', superadmin_token)
|
|
206
|
+
.send({ profile: custom_profile_sample })
|
|
207
|
+
.end((err, res) => {
|
|
208
|
+
|
|
209
|
+
if (err) { console.error("err: ", err) }
|
|
210
|
+
if (log) { console.log("update project res.body: ", res.body) }
|
|
211
|
+
|
|
212
|
+
res.should.have.status(200);
|
|
213
|
+
res.body.should.be.a('object');
|
|
214
|
+
expect(res.body.profile.customization.hybrid).to.equal(true);
|
|
215
|
+
|
|
216
|
+
chai.request(server)
|
|
217
|
+
.post('/' + savedProject._id + '/kb/namespace')
|
|
218
|
+
.auth(email, pwd)
|
|
219
|
+
.send({ name: "MyCustomNamespace", hybrid: true })
|
|
220
|
+
.end((err, res) => {
|
|
221
|
+
|
|
222
|
+
if (err) { console.error("err: ", err) }
|
|
223
|
+
if (log) { console.log("create new namespace res.body: ", res.body) }
|
|
224
|
+
|
|
225
|
+
res.should.have.status(200);
|
|
226
|
+
res.body.should.be.a('object');
|
|
227
|
+
should.not.exist(res.body._id)
|
|
228
|
+
should.exist(res.body.id)
|
|
229
|
+
expect(res.body.name).to.equal('MyCustomNamespace');
|
|
230
|
+
|
|
231
|
+
should.exist(res.body.engine)
|
|
232
|
+
expect(res.body.engine.name).to.equal('pinecone');
|
|
233
|
+
expect(res.body.engine.type).to.equal('serverless');
|
|
234
|
+
expect(res.body.engine.vector_size).to.equal(1536);
|
|
235
|
+
expect(res.body.engine.index_name).to.equal('test-index-hybrid');
|
|
236
|
+
should.exist(res.body.embedding);
|
|
237
|
+
expect(res.body.embedding.provider).to.equal('openai')
|
|
238
|
+
expect(res.body.embedding.name).to.equal('text-embedding-ada-002')
|
|
239
|
+
expect(res.body.embedding.dimension).to.equal(1536)
|
|
240
|
+
|
|
241
|
+
done();
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
})
|
|
248
|
+
});
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('import-namespace', (done) => {
|
|
252
|
+
|
|
253
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
254
|
+
var pwd = "pwd";
|
|
255
|
+
|
|
256
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
257
|
+
projectService.create("test-namespace-import", savedUser._id).then((savedProject) => {
|
|
258
|
+
|
|
117
259
|
chai.request(server)
|
|
118
260
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
119
261
|
.auth(email, pwd)
|
|
120
262
|
.end((err, res) => {
|
|
121
263
|
|
|
122
264
|
if (err) { console.error("err: ", err); }
|
|
123
|
-
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
265
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
124
266
|
|
|
125
267
|
res.should.have.status(200);
|
|
126
|
-
|
|
268
|
+
res.body.should.be.a('array');
|
|
269
|
+
expect(res.body[0].name).to.equal("Default");
|
|
127
270
|
|
|
128
271
|
let namespace_id = res.body[0].id;
|
|
129
|
-
if (log) { console.log("namespace_id: ", namespace_id); }
|
|
130
|
-
|
|
131
|
-
let kb = {
|
|
132
|
-
name: "example_text1",
|
|
133
|
-
type: "text",
|
|
134
|
-
source: "example_text1",
|
|
135
|
-
content: "Example text",
|
|
136
|
-
namespace: namespace_id
|
|
137
|
-
}
|
|
138
272
|
|
|
139
273
|
chai.request(server)
|
|
140
|
-
.post('/' + savedProject._id + '/kb')
|
|
274
|
+
.post('/' + savedProject._id + '/kb/namespace/import/' + namespace_id)
|
|
141
275
|
.auth(email, pwd)
|
|
142
|
-
.
|
|
276
|
+
.set('Content-Type', 'text/plain')
|
|
277
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/exported_namespace.json')), 'exported_namespace.json')
|
|
143
278
|
.end((err, res) => {
|
|
144
279
|
|
|
145
280
|
if (err) { console.error("err: ", err); }
|
|
146
|
-
if (log) { console.log("
|
|
281
|
+
if (log) { console.log("import contents res.body: ", res.body); }
|
|
147
282
|
|
|
148
283
|
res.should.have.status(200);
|
|
149
284
|
res.body.should.be.a('object');
|
|
150
|
-
expect(res.body.
|
|
151
|
-
expect(res.body.
|
|
152
|
-
expect(res.body.value.type).to.equal("text")
|
|
153
|
-
expect(res.body.value.source).to.equal("example_text1")
|
|
154
|
-
expect(res.body.value.status).to.equal(-1)
|
|
155
|
-
expect(typeof res.body.value.scrape_type === "undefined").to.be.true;
|
|
156
|
-
expect(typeof res.body.value.scrape_options === "undefined").to.be.true;
|
|
157
|
-
|
|
285
|
+
expect(res.body.success).to.equal(true);
|
|
286
|
+
expect(res.body.message).to.equal("Contents imported successfully");
|
|
158
287
|
|
|
159
288
|
done();
|
|
289
|
+
|
|
160
290
|
})
|
|
161
|
-
})
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
291
|
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
})
|
|
165
295
|
})
|
|
166
296
|
|
|
167
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Update namespaces
|
|
299
|
+
*/
|
|
300
|
+
it('update-namespace', (done) => {
|
|
168
301
|
|
|
169
302
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
170
303
|
var pwd = "pwd";
|
|
@@ -172,65 +305,63 @@ describe('KbRoute', () => {
|
|
|
172
305
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
173
306
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
174
307
|
|
|
308
|
+
// Get all namespaces. Create default namespace and return.
|
|
175
309
|
chai.request(server)
|
|
176
310
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
177
311
|
.auth(email, pwd)
|
|
178
312
|
.end((err, res) => {
|
|
179
313
|
|
|
180
314
|
if (err) { console.error("err: ", err); }
|
|
181
|
-
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
315
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
182
316
|
|
|
183
317
|
res.should.have.status(200);
|
|
318
|
+
res.body.should.be.a('array');
|
|
184
319
|
expect(res.body.length).to.equal(1);
|
|
320
|
+
expect(res.body[0].id).to.equal(savedProject._id.toString());
|
|
321
|
+
expect(res.body[0].name).to.equal("Default");
|
|
185
322
|
|
|
186
323
|
let namespace_id = res.body[0].id;
|
|
187
324
|
|
|
188
|
-
let
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
325
|
+
let new_settings = {
|
|
326
|
+
model: 'gpt-4o',
|
|
327
|
+
max_tokens: 256,
|
|
328
|
+
temperature: 0.3,
|
|
329
|
+
top_k: 6,
|
|
330
|
+
context: "You are an awesome AI Assistant."
|
|
194
331
|
}
|
|
195
332
|
|
|
333
|
+
// Update namespace
|
|
196
334
|
chai.request(server)
|
|
197
|
-
.
|
|
335
|
+
.put('/' + savedProject._id + '/kb/namespace/' + namespace_id)
|
|
198
336
|
.auth(email, pwd)
|
|
199
|
-
.send(
|
|
337
|
+
.send({ name: "New Name", preview_settings: new_settings })
|
|
200
338
|
.end((err, res) => {
|
|
201
339
|
|
|
202
|
-
if (err) { console.error("err: ", err)
|
|
203
|
-
if (log) { console.log("
|
|
340
|
+
if (err) { console.error("err: ", err) }
|
|
341
|
+
if (log) { console.log("update namespace res.body: ", res.body) }
|
|
204
342
|
|
|
205
343
|
res.should.have.status(200);
|
|
206
344
|
res.body.should.be.a('object');
|
|
345
|
+
should.not.exist(res.body._id);
|
|
346
|
+
should.exist(res.body.id);
|
|
347
|
+
expect(res.body.name).to.equal('New Name');
|
|
348
|
+
expect(res.body.preview_settings.model).to.equal('gpt-4o')
|
|
349
|
+
expect(res.body.preview_settings.max_tokens).to.equal(256)
|
|
350
|
+
expect(res.body.preview_settings.temperature).to.equal(0.3)
|
|
351
|
+
expect(res.body.preview_settings.top_k).to.equal(6)
|
|
207
352
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
chai.request(server)
|
|
211
|
-
.get('/' + savedProject._id + '/kb/namespace/' + namespace_id + '/chunks/' + content_id)
|
|
212
|
-
.auth(email, pwd)
|
|
213
|
-
.end((err, res) => {
|
|
214
|
-
|
|
215
|
-
if (err) { console.error("err: ", err )};
|
|
216
|
-
if (log) { console.log("res.body: ", res.body )};
|
|
217
|
-
|
|
218
|
-
res.should.have.status(200);
|
|
219
|
-
/**
|
|
220
|
-
* Unable to verify the response due to an external request
|
|
221
|
-
*/
|
|
222
|
-
expect(res.body.success).to.equal(true);
|
|
223
|
-
expect(res.body.message).to.equal("Get chunks skipped in test environment");
|
|
353
|
+
done();
|
|
224
354
|
|
|
225
|
-
done();
|
|
226
|
-
})
|
|
227
355
|
})
|
|
228
356
|
})
|
|
229
357
|
});
|
|
230
358
|
});
|
|
231
359
|
})
|
|
232
360
|
|
|
233
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Delete default namespace - Forbidden
|
|
363
|
+
*/
|
|
364
|
+
it('fail-to-delete-default-namespace', (done) => {
|
|
234
365
|
|
|
235
366
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
236
367
|
var pwd = "pwd";
|
|
@@ -238,198 +369,125 @@ describe('KbRoute', () => {
|
|
|
238
369
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
239
370
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
240
371
|
|
|
241
|
-
|
|
242
|
-
* Get all namespace. If no namespace exists, a default namespace is created and returned
|
|
243
|
-
*/
|
|
372
|
+
// Get all namespaces. Create default namespace and return.
|
|
244
373
|
chai.request(server)
|
|
245
374
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
246
375
|
.auth(email, pwd)
|
|
247
376
|
.end((err, res) => {
|
|
248
377
|
|
|
249
378
|
if (err) { console.error("err: ", err); }
|
|
250
|
-
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
379
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
251
380
|
|
|
252
381
|
res.should.have.status(200);
|
|
253
|
-
|
|
254
|
-
expect(res.body
|
|
382
|
+
res.body.should.be.a('array');
|
|
383
|
+
expect(res.body.length).to.equal(1);
|
|
384
|
+
expect(res.body[0].id).to.equal(savedProject._id.toString());
|
|
385
|
+
expect(res.body[0].name).to.equal("Default");
|
|
255
386
|
|
|
256
387
|
let namespace_id = res.body[0].id;
|
|
257
388
|
|
|
258
|
-
|
|
259
|
-
name: "example_name1",
|
|
260
|
-
type: "url",
|
|
261
|
-
namespace: namespace_id,
|
|
262
|
-
source: "https://www.exampleurl1.com",
|
|
263
|
-
content: ""
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
let kb2 = {
|
|
267
|
-
name: "example_name2",
|
|
268
|
-
type: "text",
|
|
269
|
-
namespace: namespace_id,
|
|
270
|
-
source: "example_name2",
|
|
271
|
-
content: "example content"
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
let kb3 = {
|
|
275
|
-
name: "example_name3",
|
|
276
|
-
type: "url",
|
|
277
|
-
namespace: namespace_id,
|
|
278
|
-
source: "https://www.exampleurl3.com",
|
|
279
|
-
content: ""
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Add contents to default namespace
|
|
285
|
-
*/
|
|
389
|
+
// Update namespace
|
|
286
390
|
chai.request(server)
|
|
287
|
-
.
|
|
391
|
+
.delete('/' + savedProject._id + '/kb/namespace/' + namespace_id)
|
|
288
392
|
.auth(email, pwd)
|
|
289
|
-
.send(kb1)
|
|
290
393
|
.end((err, res) => {
|
|
291
394
|
|
|
292
|
-
if (err) { console.error("err: ", err)
|
|
293
|
-
if (log) { console.log("
|
|
294
|
-
res.should.have.status(200);
|
|
295
|
-
|
|
296
|
-
setTimeout(() => {
|
|
297
|
-
chai.request(server)
|
|
298
|
-
.post('/' + savedProject._id + "/kb")
|
|
299
|
-
.auth(email, pwd)
|
|
300
|
-
.send(kb2)
|
|
301
|
-
.end((err, res) => {
|
|
302
|
-
|
|
303
|
-
if (err) { console.error("err: ", err); }
|
|
304
|
-
if (log) { console.log("create kb2 res.body: ", res.body); }
|
|
305
|
-
|
|
306
|
-
res.should.have.status(200);
|
|
307
|
-
|
|
308
|
-
setTimeout(() => {
|
|
309
|
-
chai.request(server)
|
|
310
|
-
.post('/' + savedProject._id + "/kb")
|
|
311
|
-
.auth(email, pwd)
|
|
312
|
-
.send(kb3)
|
|
313
|
-
.end((err, res) => {
|
|
314
|
-
|
|
315
|
-
if (err) { console.error("err: ", err); }
|
|
316
|
-
if (log) { console.log("create kb3 res.body: ", res.body); }
|
|
317
|
-
|
|
318
|
-
res.should.have.status(200);
|
|
319
|
-
|
|
320
|
-
let query = "?status=-1&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example&namespace=" + namespace_id;
|
|
321
|
-
//let query = "?namespace=" + namespace_id;
|
|
322
|
-
|
|
323
|
-
chai.request(server)
|
|
324
|
-
.get('/' + savedProject._id + "/kb" + query)
|
|
325
|
-
.auth(email, pwd)
|
|
326
|
-
.end((err, res) => {
|
|
327
|
-
|
|
328
|
-
if (err) { console.error("err: ", err)}
|
|
329
|
-
if (log) { console.log("getall res.body: ", res.body); }
|
|
330
|
-
|
|
331
|
-
res.should.have.status(200);
|
|
332
|
-
res.body.should.be.a('object');
|
|
333
|
-
res.body.kbs.should.be.a('array');
|
|
334
|
-
expect(res.body.kbs.length).to.equal(2);
|
|
335
|
-
expect(res.body.count).to.equal(2);
|
|
336
|
-
res.body.query.should.be.a('object');
|
|
337
|
-
expect(res.body.query.status).to.equal(-1);
|
|
338
|
-
expect(res.body.query.limit).to.equal(5);
|
|
339
|
-
expect(res.body.query.page).to.equal(0);
|
|
340
|
-
expect(res.body.query.direction).to.equal(-1);
|
|
341
|
-
expect(res.body.query.sortField).to.equal("updatedAt");
|
|
342
|
-
expect(res.body.query.search).to.equal("example");
|
|
395
|
+
if (err) { console.error("err: ", err) }
|
|
396
|
+
if (log) { console.log("delete namespace res.body: ", res.body) }
|
|
343
397
|
|
|
344
|
-
|
|
398
|
+
res.should.have.status(403);
|
|
399
|
+
res.body.should.be.a('object');
|
|
400
|
+
expect(res.body.success).to.equal(false);
|
|
401
|
+
expect(res.body.error).to.equal('Default namespace cannot be deleted');
|
|
345
402
|
|
|
346
|
-
|
|
403
|
+
done();
|
|
347
404
|
|
|
348
|
-
})
|
|
349
|
-
}, 1000)
|
|
350
|
-
})
|
|
351
|
-
}, 1000)
|
|
352
405
|
})
|
|
353
406
|
})
|
|
354
|
-
})
|
|
355
|
-
})
|
|
356
|
-
})
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
})
|
|
357
410
|
|
|
358
|
-
it('get-
|
|
411
|
+
it('get-chatbots-from-namespace', (done) => {
|
|
359
412
|
|
|
360
413
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
361
414
|
var pwd = "pwd";
|
|
362
415
|
|
|
363
|
-
userService.signup(email, pwd, "Test Firstname", "Test
|
|
364
|
-
projectService.create(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
* Get all namespace. If no namespace exists, a default namespace is created and returned
|
|
368
|
-
*/
|
|
369
|
-
chai.request(server)
|
|
370
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
371
|
-
.auth(email, pwd)
|
|
372
|
-
.end((err, res) => {
|
|
373
|
-
|
|
374
|
-
if (err) { console.error("err: ", err); }
|
|
375
|
-
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
376
|
-
|
|
377
|
-
res.should.have.status(200);
|
|
378
|
-
expect(res.body[0].name === 'Default');
|
|
379
|
-
expect(res.body[0].id === savedProject._id);
|
|
380
|
-
|
|
381
|
-
let namespace_id = res.body[0].id;
|
|
382
|
-
|
|
383
|
-
let kb1 = {
|
|
384
|
-
name: "example_name1",
|
|
385
|
-
type: "url",
|
|
386
|
-
namespace: namespace_id,
|
|
387
|
-
source: "https://www.exampleurl1.com",
|
|
388
|
-
content: ""
|
|
389
|
-
}
|
|
416
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
417
|
+
projectService.create('test-faqkb-create', savedUser._id).then((savedProject) => {
|
|
418
|
+
faqService.create(savedProject._id, savedUser._id, { name: "testbot1" }).then((savedBot1) => {
|
|
419
|
+
faqService.create(savedProject._id, savedUser._id, { name: "testbot2" }).then((savedBot2) => {
|
|
390
420
|
|
|
391
|
-
/**
|
|
392
|
-
* Add contents to default namespace
|
|
393
|
-
*/
|
|
394
421
|
chai.request(server)
|
|
395
|
-
.
|
|
422
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
396
423
|
.auth(email, pwd)
|
|
397
|
-
.send(kb1)
|
|
398
424
|
.end((err, res) => {
|
|
399
425
|
|
|
400
426
|
if (err) { console.error("err: ", err); }
|
|
401
|
-
if (log) { console.log("
|
|
427
|
+
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
402
428
|
|
|
403
429
|
res.should.have.status(200);
|
|
404
430
|
|
|
405
|
-
let namespace_id =
|
|
431
|
+
let namespace_id = res.body[0].id;
|
|
432
|
+
if (log) { console.log("namespace_id: ", namespace_id) }
|
|
406
433
|
|
|
407
|
-
let
|
|
434
|
+
let newFaq1 = new faq({
|
|
435
|
+
id_faq_kb: savedBot1._id,
|
|
436
|
+
id_project: savedProject._id,
|
|
437
|
+
intent_id: "new-faq-1",
|
|
438
|
+
createdBy: savedUser._id,
|
|
439
|
+
updatedBy: savedUser._id,
|
|
440
|
+
actions: [{ "_tdActionType": "askgptv2", "_tdActionId": "f58212f9-1a8c-4623-b6fa-0f34e57d9999", "namespace": namespace_id }]
|
|
441
|
+
})
|
|
408
442
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
.
|
|
412
|
-
.end((err, res) => {
|
|
443
|
+
newFaq1.save((err, saved1) => {
|
|
444
|
+
if (err) { console.error("err1: ", err) };
|
|
445
|
+
if (log) { console.log("faq1 saved: ", saved1) };
|
|
413
446
|
|
|
414
|
-
|
|
415
|
-
|
|
447
|
+
let newFaq2 = new faq({
|
|
448
|
+
id_faq_kb: savedBot2._id,
|
|
449
|
+
id_project: savedProject._id,
|
|
450
|
+
intent_id: "new-faq-2",
|
|
451
|
+
createdBy: savedUser._id,
|
|
452
|
+
updatedBy: savedUser._id,
|
|
453
|
+
actions: [{ "_tdActionType": "reply", "_tdActionId": "f58212f9-1a8c-4623-b6fa-0f34e57d9998" }]
|
|
454
|
+
})
|
|
416
455
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
expect(res.body.kbs.length).to.equal(0);
|
|
421
|
-
expect(res.body.count).to.equal(0);
|
|
456
|
+
newFaq2.save((err, saved2) => {
|
|
457
|
+
if (err) { console.error("err2: ", err) };
|
|
458
|
+
if (log) { console.log("faq2 saved: ", saved2) };
|
|
422
459
|
|
|
423
|
-
|
|
460
|
+
chai.request(server)
|
|
461
|
+
.get('/' + savedProject._id + '/kb/namespace/' + namespace_id + '/chatbots')
|
|
462
|
+
.auth(email, pwd)
|
|
463
|
+
.end((err, res) => {
|
|
424
464
|
|
|
465
|
+
if (err) { console.error("err: ", err) };
|
|
466
|
+
if (log) { console.log("get chatbots from namespace res.body: ", res.body) };
|
|
467
|
+
|
|
468
|
+
res.should.have.status(200);
|
|
469
|
+
res.body.should.be.a('array');
|
|
470
|
+
expect(res.body.length).to.equal(1);
|
|
471
|
+
expect(res.body[0]._id).to.equal((savedBot1._id).toString());
|
|
472
|
+
expect(res.body[0].name).to.equal('testbot1');
|
|
473
|
+
|
|
474
|
+
done();
|
|
475
|
+
})
|
|
425
476
|
})
|
|
477
|
+
})
|
|
426
478
|
})
|
|
479
|
+
|
|
427
480
|
})
|
|
481
|
+
})
|
|
428
482
|
})
|
|
429
483
|
})
|
|
430
|
-
}).timeout(
|
|
484
|
+
}).timeout(10000)
|
|
431
485
|
|
|
432
|
-
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
describe('Contents', () => {
|
|
489
|
+
|
|
490
|
+
it('add-new-content', (done) => {
|
|
433
491
|
|
|
434
492
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
435
493
|
var pwd = "pwd";
|
|
@@ -443,39 +501,66 @@ describe('KbRoute', () => {
|
|
|
443
501
|
.end((err, res) => {
|
|
444
502
|
|
|
445
503
|
if (err) { console.error("err: ", err); }
|
|
446
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
504
|
+
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
447
505
|
|
|
448
|
-
res.should.have.status(200)
|
|
506
|
+
res.should.have.status(200);
|
|
449
507
|
expect(res.body.length).to.equal(1);
|
|
508
|
+
expect(res.body[0].engine.index_name).to.equal('test-index');
|
|
450
509
|
|
|
451
510
|
let namespace_id = res.body[0].id;
|
|
452
511
|
|
|
512
|
+
let kb = {
|
|
513
|
+
name: "example_name5",
|
|
514
|
+
type: "url",
|
|
515
|
+
source: "https://www.exampleurl5.com",
|
|
516
|
+
content: "",
|
|
517
|
+
namespace: namespace_id
|
|
518
|
+
}
|
|
519
|
+
|
|
453
520
|
chai.request(server)
|
|
454
|
-
.post('/' + savedProject._id + '/kb
|
|
521
|
+
.post('/' + savedProject._id + '/kb')
|
|
455
522
|
.auth(email, pwd)
|
|
456
|
-
.
|
|
457
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/example-kb-faqs.csv')), 'example-kb-faqs.csv')
|
|
458
|
-
.field('delimiter', ';')
|
|
523
|
+
.send(kb)
|
|
459
524
|
.end((err, res) => {
|
|
460
525
|
|
|
461
526
|
if (err) { console.error("err: ", err); }
|
|
462
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
527
|
+
if (log) { console.log("create kb res.body: ", res.body); }
|
|
463
528
|
|
|
464
529
|
res.should.have.status(200);
|
|
530
|
+
res.body.should.be.a('object');
|
|
531
|
+
expect(res.body.success).to.equal(true);
|
|
532
|
+
expect(res.body.message).to.equal("Schedule scrape skipped in test environment");
|
|
533
|
+
|
|
534
|
+
let realResponse = res.body.data;
|
|
535
|
+
expect(realResponse.lastErrorObject.updatedExisting).to.equal(false);
|
|
536
|
+
expect(realResponse.value.id_project).to.equal(namespace_id)
|
|
537
|
+
expect(realResponse.value.namespace).to.equal(namespace_id)
|
|
538
|
+
expect(realResponse.value.name).to.equal("example_name5")
|
|
539
|
+
expect(realResponse.value.type).to.equal("url")
|
|
540
|
+
expect(realResponse.value.source).to.equal("https://www.exampleurl5.com")
|
|
541
|
+
expect(realResponse.value.status).to.equal(-1)
|
|
542
|
+
should.not.exist(realResponse.engine)
|
|
543
|
+
should.not.exist(realResponse.value.engine)
|
|
544
|
+
should.not.exist(realResponse.embedding)
|
|
545
|
+
should.not.exist(realResponse.value.embedding)
|
|
546
|
+
|
|
547
|
+
let scheduleJson = res.body.schedule_json;
|
|
548
|
+
expect(scheduleJson.namespace).to.equal(namespace_id)
|
|
549
|
+
expect(scheduleJson.type).to.equal("url")
|
|
550
|
+
expect(scheduleJson.source).to.equal("https://www.exampleurl5.com")
|
|
551
|
+
expect(scheduleJson.hybrid).to.equal(false);
|
|
552
|
+
should.exist(scheduleJson.engine)
|
|
553
|
+
should.exist(scheduleJson.embedding)
|
|
465
554
|
|
|
466
555
|
done();
|
|
467
|
-
|
|
468
556
|
})
|
|
469
557
|
})
|
|
470
558
|
});
|
|
471
559
|
});
|
|
472
560
|
|
|
473
|
-
})
|
|
561
|
+
})
|
|
474
562
|
|
|
475
|
-
|
|
476
|
-
* If you try to add content to a project that has no namespace, it returns 403 forbidden.
|
|
477
|
-
*/
|
|
478
|
-
it('add-multiple-urls-no-namespaces', (done) => {
|
|
563
|
+
it('add-new-text-content', (done) => {
|
|
479
564
|
|
|
480
565
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
481
566
|
var pwd = "pwd";
|
|
@@ -484,34 +569,57 @@ describe('KbRoute', () => {
|
|
|
484
569
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
485
570
|
|
|
486
571
|
chai.request(server)
|
|
487
|
-
.
|
|
572
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
488
573
|
.auth(email, pwd)
|
|
489
|
-
.set('Content-Type', 'text/plain')
|
|
490
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
|
491
574
|
.end((err, res) => {
|
|
492
575
|
|
|
493
576
|
if (err) { console.error("err: ", err); }
|
|
494
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
577
|
+
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
495
578
|
|
|
496
|
-
res.should.have.status(
|
|
497
|
-
res.
|
|
498
|
-
expect(res.body.success).to.equal(false);
|
|
499
|
-
let error_response = "No namespace found for the selected project " + savedProject._id + ". Cannot add content to a non-existent namespace."
|
|
500
|
-
expect(res.body.error).to.equal(error_response);
|
|
579
|
+
res.should.have.status(200);
|
|
580
|
+
expect(res.body.length).to.equal(1);
|
|
501
581
|
|
|
502
|
-
|
|
582
|
+
let namespace_id = res.body[0].id;
|
|
583
|
+
if (log) { console.log("namespace_id: ", namespace_id); }
|
|
503
584
|
|
|
585
|
+
let kb = {
|
|
586
|
+
name: "example_text1",
|
|
587
|
+
type: "text",
|
|
588
|
+
source: "example_text1",
|
|
589
|
+
content: "Example text",
|
|
590
|
+
namespace: namespace_id
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
chai.request(server)
|
|
594
|
+
.post('/' + savedProject._id + '/kb')
|
|
595
|
+
.auth(email, pwd)
|
|
596
|
+
.send(kb) // can be empty
|
|
597
|
+
.end((err, res) => {
|
|
598
|
+
|
|
599
|
+
if (err) { console.error("err: ", err); }
|
|
600
|
+
if (log) { console.log("create kb res.body: ", res.body); }
|
|
601
|
+
|
|
602
|
+
res.should.have.status(200);
|
|
603
|
+
res.body.should.be.a('object');
|
|
604
|
+
|
|
605
|
+
let realResponse = res.body.data;
|
|
606
|
+
expect(realResponse.value.id_project).to.equal(namespace_id)
|
|
607
|
+
expect(realResponse.value.name).to.equal("example_text1")
|
|
608
|
+
expect(realResponse.value.type).to.equal("text")
|
|
609
|
+
expect(realResponse.value.source).to.equal("example_text1")
|
|
610
|
+
expect(realResponse.value.status).to.equal(-1)
|
|
611
|
+
expect(typeof realResponse.value.scrape_type === "undefined").to.be.true;
|
|
612
|
+
expect(typeof realResponse.value.scrape_options === "undefined").to.be.true;
|
|
613
|
+
|
|
614
|
+
done();
|
|
615
|
+
})
|
|
504
616
|
})
|
|
505
617
|
});
|
|
506
618
|
});
|
|
507
619
|
|
|
508
|
-
})
|
|
620
|
+
})
|
|
509
621
|
|
|
510
|
-
|
|
511
|
-
* If you try to add content to a namespace that does not belong to the selected project and
|
|
512
|
-
* the project has at least one namesapce, it returns 403 forbidden.
|
|
513
|
-
*/
|
|
514
|
-
it('add-multiple-urls-namespace-not-belong-project', (done) => {
|
|
622
|
+
it('get-content-chunks', (done) => {
|
|
515
623
|
|
|
516
624
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
517
625
|
var pwd = "pwd";
|
|
@@ -525,37 +633,60 @@ describe('KbRoute', () => {
|
|
|
525
633
|
.end((err, res) => {
|
|
526
634
|
|
|
527
635
|
if (err) { console.error("err: ", err); }
|
|
528
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
636
|
+
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
529
637
|
|
|
530
|
-
res.should.have.status(200)
|
|
638
|
+
res.should.have.status(200);
|
|
531
639
|
expect(res.body.length).to.equal(1);
|
|
532
640
|
|
|
641
|
+
let namespace_id = res.body[0].id;
|
|
642
|
+
|
|
643
|
+
let kb = {
|
|
644
|
+
name: "example_text1",
|
|
645
|
+
type: "text",
|
|
646
|
+
source: "example_text1",
|
|
647
|
+
content: "Example text",
|
|
648
|
+
namespace: namespace_id
|
|
649
|
+
}
|
|
650
|
+
|
|
533
651
|
chai.request(server)
|
|
534
|
-
.post('/' + savedProject._id + '/kb
|
|
652
|
+
.post('/' + savedProject._id + '/kb')
|
|
535
653
|
.auth(email, pwd)
|
|
536
|
-
.
|
|
537
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
|
654
|
+
.send(kb) // can be empty
|
|
538
655
|
.end((err, res) => {
|
|
539
656
|
|
|
540
657
|
if (err) { console.error("err: ", err); }
|
|
541
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
658
|
+
if (log) { console.log("create kb res.body: ", res.body); }
|
|
542
659
|
|
|
543
|
-
res.should.have.status(
|
|
544
|
-
res.should.be.a('object');
|
|
545
|
-
expect(res.body.success).to.equal(false);
|
|
546
|
-
let error_response = "Not allowed. The namespace does not belong to the current project."
|
|
547
|
-
expect(res.body.error).to.equal(error_response);
|
|
660
|
+
res.should.have.status(200);
|
|
661
|
+
res.body.should.be.a('object');
|
|
548
662
|
|
|
549
|
-
|
|
663
|
+
let realResponse = res.body.data;
|
|
664
|
+
let content_id = realResponse.value._id;
|
|
665
|
+
|
|
666
|
+
chai.request(server)
|
|
667
|
+
.get('/' + savedProject._id + '/kb/namespace/' + namespace_id + '/chunks/' + content_id)
|
|
668
|
+
.auth(email, pwd)
|
|
669
|
+
.end((err, res) => {
|
|
670
|
+
|
|
671
|
+
if (err) { console.error("err: ", err )};
|
|
672
|
+
if (log) { console.log("res.body: ", res.body )};
|
|
673
|
+
|
|
674
|
+
res.should.have.status(200);
|
|
675
|
+
/**
|
|
676
|
+
* Unable to verify the response due to an external request
|
|
677
|
+
*/
|
|
678
|
+
expect(res.body.success).to.equal(true);
|
|
679
|
+
expect(res.body.message).to.equal("Get chunks skipped in test environment");
|
|
550
680
|
|
|
681
|
+
done();
|
|
682
|
+
})
|
|
551
683
|
})
|
|
552
684
|
})
|
|
553
685
|
});
|
|
554
686
|
});
|
|
687
|
+
})
|
|
555
688
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
it('add-multiple-urls-success', (done) => {
|
|
689
|
+
it('get-contents-with-queries', (done) => {
|
|
559
690
|
|
|
560
691
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
561
692
|
var pwd = "pwd";
|
|
@@ -563,42 +694,124 @@ describe('KbRoute', () => {
|
|
|
563
694
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
564
695
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
565
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Get all namespace. If no namespace exists, a default namespace is created and returned
|
|
699
|
+
*/
|
|
566
700
|
chai.request(server)
|
|
567
701
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
568
702
|
.auth(email, pwd)
|
|
569
703
|
.end((err, res) => {
|
|
570
704
|
|
|
571
705
|
if (err) { console.error("err: ", err); }
|
|
572
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
706
|
+
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
573
707
|
|
|
574
|
-
res.should.have.status(200)
|
|
575
|
-
expect(res.body.
|
|
708
|
+
res.should.have.status(200);
|
|
709
|
+
expect(res.body[0].name === 'Default');
|
|
710
|
+
expect(res.body[0].id === savedProject._id);
|
|
576
711
|
|
|
577
712
|
let namespace_id = res.body[0].id;
|
|
578
713
|
|
|
714
|
+
let kb1 = {
|
|
715
|
+
name: "example_name1",
|
|
716
|
+
type: "url",
|
|
717
|
+
namespace: namespace_id,
|
|
718
|
+
source: "https://www.exampleurl1.com",
|
|
719
|
+
content: ""
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
let kb2 = {
|
|
723
|
+
name: "example_name2",
|
|
724
|
+
type: "text",
|
|
725
|
+
namespace: namespace_id,
|
|
726
|
+
source: "example_name2",
|
|
727
|
+
content: "example content"
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
let kb3 = {
|
|
731
|
+
name: "example_name3",
|
|
732
|
+
type: "url",
|
|
733
|
+
namespace: namespace_id,
|
|
734
|
+
source: "https://www.exampleurl3.com",
|
|
735
|
+
content: ""
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Add contents to default namespace
|
|
741
|
+
*/
|
|
579
742
|
chai.request(server)
|
|
580
|
-
.post('/' + savedProject._id +
|
|
743
|
+
.post('/' + savedProject._id + "/kb")
|
|
581
744
|
.auth(email, pwd)
|
|
582
|
-
.
|
|
583
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
|
745
|
+
.send(kb1)
|
|
584
746
|
.end((err, res) => {
|
|
585
747
|
|
|
586
748
|
if (err) { console.error("err: ", err); }
|
|
587
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
588
|
-
|
|
749
|
+
if (log) { console.log("create kb1 res.body: ", res.body); }
|
|
589
750
|
res.should.have.status(200);
|
|
590
|
-
expect(res.body.length).to.equal(4)
|
|
591
751
|
|
|
592
|
-
|
|
752
|
+
setTimeout(() => {
|
|
753
|
+
chai.request(server)
|
|
754
|
+
.post('/' + savedProject._id + "/kb")
|
|
755
|
+
.auth(email, pwd)
|
|
756
|
+
.send(kb2)
|
|
757
|
+
.end((err, res) => {
|
|
593
758
|
|
|
759
|
+
if (err) { console.error("err: ", err); }
|
|
760
|
+
if (log) { console.log("create kb2 res.body: ", res.body); }
|
|
761
|
+
|
|
762
|
+
res.should.have.status(200);
|
|
763
|
+
|
|
764
|
+
setTimeout(() => {
|
|
765
|
+
chai.request(server)
|
|
766
|
+
.post('/' + savedProject._id + "/kb")
|
|
767
|
+
.auth(email, pwd)
|
|
768
|
+
.send(kb3)
|
|
769
|
+
.end((err, res) => {
|
|
770
|
+
|
|
771
|
+
if (err) { console.error("err: ", err); }
|
|
772
|
+
if (log) { console.log("create kb3 res.body: ", res.body); }
|
|
773
|
+
|
|
774
|
+
res.should.have.status(200);
|
|
775
|
+
|
|
776
|
+
let query = "?status=-1&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example&namespace=" + namespace_id;
|
|
777
|
+
//let query = "?namespace=" + namespace_id;
|
|
778
|
+
|
|
779
|
+
chai.request(server)
|
|
780
|
+
.get('/' + savedProject._id + "/kb" + query)
|
|
781
|
+
.auth(email, pwd)
|
|
782
|
+
.end((err, res) => {
|
|
783
|
+
|
|
784
|
+
if (err) { console.error("err: ", err)}
|
|
785
|
+
if (log) { console.log("getall res.body: ", res.body); }
|
|
786
|
+
|
|
787
|
+
res.should.have.status(200);
|
|
788
|
+
res.body.should.be.a('object');
|
|
789
|
+
res.body.kbs.should.be.a('array');
|
|
790
|
+
expect(res.body.kbs.length).to.equal(2);
|
|
791
|
+
expect(res.body.count).to.equal(2);
|
|
792
|
+
res.body.query.should.be.a('object');
|
|
793
|
+
expect(res.body.query.status).to.equal(-1);
|
|
794
|
+
expect(res.body.query.limit).to.equal(5);
|
|
795
|
+
expect(res.body.query.page).to.equal(0);
|
|
796
|
+
expect(res.body.query.direction).to.equal(-1);
|
|
797
|
+
expect(res.body.query.sortField).to.equal("updatedAt");
|
|
798
|
+
expect(res.body.query.search).to.equal("example");
|
|
799
|
+
|
|
800
|
+
done();
|
|
801
|
+
|
|
802
|
+
})
|
|
803
|
+
|
|
804
|
+
})
|
|
805
|
+
}, 1000)
|
|
806
|
+
})
|
|
807
|
+
}, 1000)
|
|
594
808
|
})
|
|
595
809
|
})
|
|
596
|
-
})
|
|
597
|
-
})
|
|
598
|
-
|
|
599
|
-
}).timeout(10000)
|
|
810
|
+
})
|
|
811
|
+
})
|
|
812
|
+
}).timeout(20000)
|
|
600
813
|
|
|
601
|
-
it('
|
|
814
|
+
it('get-contents-with-queries-namespace-not-belong-project', (done) => {
|
|
602
815
|
|
|
603
816
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
604
817
|
var pwd = "pwd";
|
|
@@ -606,46 +819,73 @@ describe('KbRoute', () => {
|
|
|
606
819
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
607
820
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
608
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Get all namespace. If no namespace exists, a default namespace is created and returned
|
|
824
|
+
*/
|
|
609
825
|
chai.request(server)
|
|
610
826
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
611
827
|
.auth(email, pwd)
|
|
612
828
|
.end((err, res) => {
|
|
613
829
|
|
|
614
830
|
if (err) { console.error("err: ", err); }
|
|
615
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
831
|
+
if (log) { console.log("get namespaces res.body: ", res.body); }
|
|
616
832
|
|
|
617
|
-
res.should.have.status(200)
|
|
618
|
-
expect(res.body.
|
|
833
|
+
res.should.have.status(200);
|
|
834
|
+
expect(res.body[0].name === 'Default');
|
|
835
|
+
expect(res.body[0].id === savedProject._id);
|
|
619
836
|
|
|
620
837
|
let namespace_id = res.body[0].id;
|
|
621
838
|
|
|
839
|
+
let kb1 = {
|
|
840
|
+
name: "example_name1",
|
|
841
|
+
type: "url",
|
|
842
|
+
namespace: namespace_id,
|
|
843
|
+
source: "https://www.exampleurl1.com",
|
|
844
|
+
content: ""
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Add contents to default namespace
|
|
849
|
+
*/
|
|
622
850
|
chai.request(server)
|
|
623
|
-
.post('/' + savedProject._id +
|
|
851
|
+
.post('/' + savedProject._id + "/kb")
|
|
624
852
|
.auth(email, pwd)
|
|
625
|
-
.send(
|
|
853
|
+
.send(kb1)
|
|
626
854
|
.end((err, res) => {
|
|
627
855
|
|
|
628
856
|
if (err) { console.error("err: ", err); }
|
|
629
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
857
|
+
if (log) { console.log("create kb1 res.body: ", res.body); }
|
|
630
858
|
|
|
631
859
|
res.should.have.status(200);
|
|
632
|
-
expect(res.body.length).to.equal(1)
|
|
633
|
-
expect(res.body[0].scrape_type).to.equal(4)
|
|
634
|
-
expect(typeof res.body[0].scrape_options === "undefined").to.be.false;
|
|
635
|
-
expect(res.body[0].scrape_options.tags_to_extract.length).to.equal(2);
|
|
636
|
-
expect(res.body[0].scrape_options.unwanted_tags.length).to.equal(2);
|
|
637
|
-
expect(res.body[0].scrape_options.unwanted_classnames.length).to.equal(2);
|
|
638
860
|
|
|
639
|
-
|
|
861
|
+
let namespace_id = "fakenamespaceid";
|
|
862
|
+
|
|
863
|
+
let query = "?status=100&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example&namespace=" + namespace_id;
|
|
864
|
+
|
|
865
|
+
chai.request(server)
|
|
866
|
+
.get('/' + savedProject._id + "/kb" + query)
|
|
867
|
+
.auth(email, pwd)
|
|
868
|
+
.end((err, res) => {
|
|
869
|
+
|
|
870
|
+
if (err) { console.error("err: ", err); }
|
|
871
|
+
if (log) { console.log("getall res.body: ", res.body); }
|
|
872
|
+
|
|
873
|
+
res.should.have.status(200);
|
|
874
|
+
res.body.should.be.a('object');
|
|
875
|
+
res.body.kbs.should.be.a('array');
|
|
876
|
+
expect(res.body.kbs.length).to.equal(0);
|
|
877
|
+
expect(res.body.count).to.equal(0);
|
|
878
|
+
|
|
879
|
+
done();
|
|
640
880
|
|
|
881
|
+
})
|
|
641
882
|
})
|
|
642
883
|
})
|
|
643
|
-
})
|
|
644
|
-
})
|
|
645
|
-
|
|
646
|
-
}).timeout(10000)
|
|
884
|
+
})
|
|
885
|
+
})
|
|
886
|
+
}).timeout(20000)
|
|
647
887
|
|
|
648
|
-
it('add-multiple-
|
|
888
|
+
it('add-multiple-faqs-with-csv', (done) => {
|
|
649
889
|
|
|
650
890
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
651
891
|
var pwd = "pwd";
|
|
@@ -663,25 +903,65 @@ describe('KbRoute', () => {
|
|
|
663
903
|
|
|
664
904
|
res.should.have.status(200)
|
|
665
905
|
expect(res.body.length).to.equal(1);
|
|
906
|
+
let namespace = res.body[0];
|
|
907
|
+
let namespace_id = namespace.id;
|
|
666
908
|
|
|
667
|
-
|
|
909
|
+
expect(namespace.engine.name).to.equal("pinecone");
|
|
910
|
+
expect(namespace.engine.type).to.equal("serverless");
|
|
911
|
+
expect(namespace.engine.index_name).to.equal("test-index");
|
|
912
|
+
expect(namespace.embedding.provider).to.equal("openai");
|
|
913
|
+
expect(namespace.embedding.name).to.equal("text-embedding-ada-002");
|
|
914
|
+
expect(namespace.embedding.dimension).to.equal(1536);
|
|
668
915
|
|
|
669
916
|
chai.request(server)
|
|
670
|
-
.post('/' + savedProject._id + '/kb/
|
|
917
|
+
.post('/' + savedProject._id + '/kb/csv?namespace=' + namespace_id)
|
|
671
918
|
.auth(email, pwd)
|
|
672
|
-
.
|
|
919
|
+
.set('Content-Type', 'text/csv')
|
|
920
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/example-kb-faqs.csv')), 'example-kb-faqs.csv')
|
|
921
|
+
.field('delimiter', ';')
|
|
673
922
|
.end((err, res) => {
|
|
674
923
|
|
|
675
924
|
if (err) { console.error("err: ", err); }
|
|
676
925
|
if (log) { console.log("res.body: ", res.body) }
|
|
677
926
|
|
|
678
927
|
res.should.have.status(200);
|
|
679
|
-
|
|
680
|
-
expect(res.body
|
|
681
|
-
expect(
|
|
928
|
+
res.body.should.be.a('object');
|
|
929
|
+
expect(res.body.success).to.equal(true);
|
|
930
|
+
expect(res.body.message).to.equal("Schedule scrape skipped in test environment");
|
|
931
|
+
|
|
932
|
+
let realResponse = res.body.data;
|
|
933
|
+
realResponse.should.be.a('array');
|
|
934
|
+
expect(realResponse.length).to.equal(2);
|
|
935
|
+
expect(realResponse[0].namespace).to.equal(namespace_id);
|
|
936
|
+
expect(realResponse[0].type).to.equal('faq');
|
|
937
|
+
expect(realResponse[0].source).to.equal('Question 1');
|
|
938
|
+
should.not.exist(realResponse[0].engine)
|
|
939
|
+
should.not.exist(realResponse[0].embedding)
|
|
940
|
+
expect(realResponse[1].namespace).to.equal(namespace_id);
|
|
941
|
+
expect(realResponse[1].type).to.equal('faq');
|
|
942
|
+
expect(realResponse[1].source).to.equal('Question 2');
|
|
943
|
+
should.not.exist(realResponse[1].engine)
|
|
944
|
+
should.not.exist(realResponse[1].embedding)
|
|
945
|
+
|
|
946
|
+
let scheduleJson = res.body.schedule_json;
|
|
947
|
+
scheduleJson.should.be.a('array');
|
|
948
|
+
expect(scheduleJson.length).to.equal(2);
|
|
949
|
+
expect(scheduleJson[0].namespace).to.equal(namespace_id);
|
|
950
|
+
expect(scheduleJson[0].type).to.equal('faq');
|
|
951
|
+
expect(scheduleJson[0].source).to.equal('Question 1');
|
|
952
|
+
should.exist(scheduleJson[0].engine)
|
|
953
|
+
should.exist(scheduleJson[0].embedding)
|
|
954
|
+
expect(scheduleJson[0].engine.index_name).to.equal(namespace.engine.index_name);
|
|
955
|
+
expect(scheduleJson[0].embedding.provider).to.equal(namespace.embedding.provider);
|
|
956
|
+
expect(scheduleJson[0].embedding.name).to.equal(namespace.embedding.name);
|
|
957
|
+
|
|
958
|
+
expect(scheduleJson[1].namespace).to.equal(namespace_id);
|
|
959
|
+
expect(scheduleJson[1].type).to.equal('faq');
|
|
960
|
+
expect(scheduleJson[1].source).to.equal('Question 2');
|
|
961
|
+
should.exist(scheduleJson[0].engine)
|
|
962
|
+
should.exist(scheduleJson[0].embedding)
|
|
682
963
|
|
|
683
964
|
done();
|
|
684
|
-
|
|
685
965
|
})
|
|
686
966
|
})
|
|
687
967
|
});
|
|
@@ -689,7 +969,10 @@ describe('KbRoute', () => {
|
|
|
689
969
|
|
|
690
970
|
}).timeout(10000)
|
|
691
971
|
|
|
692
|
-
|
|
972
|
+
/**
|
|
973
|
+
* If you try to add content to a project that has no namespace, it returns 403 forbidden.
|
|
974
|
+
*/
|
|
975
|
+
it('add-multiple-urls-no-namespaces', (done) => {
|
|
693
976
|
|
|
694
977
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
695
978
|
var pwd = "pwd";
|
|
@@ -698,29 +981,34 @@ describe('KbRoute', () => {
|
|
|
698
981
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
699
982
|
|
|
700
983
|
chai.request(server)
|
|
701
|
-
.post('/' + savedProject._id + '/kb/
|
|
984
|
+
.post('/' + savedProject._id + '/kb/multi?namespace=123456')
|
|
702
985
|
.auth(email, pwd)
|
|
703
|
-
|
|
704
|
-
.
|
|
986
|
+
.set('Content-Type', 'text/plain')
|
|
987
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
|
705
988
|
.end((err, res) => {
|
|
706
989
|
|
|
707
|
-
if (err) { console.
|
|
990
|
+
if (err) { console.error("err: ", err); }
|
|
708
991
|
if (log) { console.log("res.body: ", res.body) }
|
|
709
992
|
|
|
710
|
-
res.should.have.status(
|
|
711
|
-
res.
|
|
712
|
-
res.body.
|
|
993
|
+
res.should.have.status(404);
|
|
994
|
+
res.should.be.a('object')
|
|
995
|
+
expect(res.body.success).to.equal(false);
|
|
996
|
+
let error_response = "Namespace not found with id 123456"
|
|
997
|
+
expect(res.body.error).to.equal(error_response);
|
|
713
998
|
|
|
714
999
|
done();
|
|
715
1000
|
|
|
716
1001
|
})
|
|
717
|
-
|
|
718
1002
|
});
|
|
719
1003
|
});
|
|
720
1004
|
|
|
721
1005
|
}).timeout(10000)
|
|
722
1006
|
|
|
723
|
-
|
|
1007
|
+
/**
|
|
1008
|
+
* If you try to add content to a namespace that does not belong to the selected project and
|
|
1009
|
+
* the project has at least one namesapce, it returns 403 forbidden.
|
|
1010
|
+
*/
|
|
1011
|
+
it('add-multiple-urls-namespace-not-belong-project', (done) => {
|
|
724
1012
|
|
|
725
1013
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
726
1014
|
var pwd = "pwd";
|
|
@@ -739,287 +1027,146 @@ describe('KbRoute', () => {
|
|
|
739
1027
|
res.should.have.status(200)
|
|
740
1028
|
expect(res.body.length).to.equal(1);
|
|
741
1029
|
|
|
742
|
-
let namespace_id = res.body[0].id;
|
|
743
|
-
|
|
744
|
-
let kb = {
|
|
745
|
-
name: "https://www.exampleurl6.com",
|
|
746
|
-
type: "url",
|
|
747
|
-
source: "https://www.exampleurl6.com",
|
|
748
|
-
content: "",
|
|
749
|
-
namespace: namespace_id
|
|
750
|
-
}
|
|
751
|
-
|
|
752
1030
|
chai.request(server)
|
|
753
|
-
.post('/' + savedProject._id + '/kb')
|
|
1031
|
+
.post('/' + savedProject._id + '/kb/multi?namespace=fakenamespaceid')
|
|
754
1032
|
.auth(email, pwd)
|
|
755
|
-
.
|
|
1033
|
+
.set('Content-Type', 'text/plain')
|
|
1034
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
|
756
1035
|
.end((err, res) => {
|
|
757
1036
|
|
|
758
1037
|
if (err) { console.error("err: ", err); }
|
|
759
|
-
if (log) { console.log("
|
|
760
|
-
|
|
761
|
-
res.should.have.status(200);
|
|
762
|
-
|
|
763
|
-
let kbid = res.body.value._id;
|
|
764
|
-
|
|
765
|
-
chai.request(server)
|
|
766
|
-
.post('/' + savedProject._id + "/kb/scrape/single")
|
|
767
|
-
.auth(email, pwd)
|
|
768
|
-
.send({ id: kbid })
|
|
769
|
-
.end((err, res) => {
|
|
770
|
-
|
|
771
|
-
if (err) { console.error("err: ", err); }
|
|
772
|
-
if (log) { console.log("single scrape res.body: ", res.body); }
|
|
1038
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
773
1039
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
1040
|
+
res.should.have.status(404);
|
|
1041
|
+
res.should.be.a('object');
|
|
1042
|
+
expect(res.body.success).to.equal(false);
|
|
1043
|
+
let error_response = "Namespace not found with id fakenamespaceid";
|
|
1044
|
+
expect(res.body.error).to.equal(error_response);
|
|
777
1045
|
|
|
778
|
-
|
|
779
|
-
// res.body.should.be.a('object');
|
|
780
|
-
// expect(res.body.id_project).to.equal(savedProject._id.toString())
|
|
781
|
-
// expect(res.body.maxKbsNumber).to.equal(3);
|
|
782
|
-
// expect(res.body.maxPagesNumber).to.equal(1000);
|
|
783
|
-
// expect(res.body.kbs).is.an('array').that.is.empty;
|
|
784
|
-
done();
|
|
1046
|
+
done();
|
|
785
1047
|
|
|
786
|
-
})
|
|
787
1048
|
})
|
|
788
1049
|
})
|
|
789
1050
|
});
|
|
790
1051
|
});
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
it('askkb-key-from-env', (done) => {
|
|
794
|
-
|
|
795
|
-
var email = "test-signup-" + Date.now() + "@email.com";
|
|
796
|
-
var pwd = "pwd";
|
|
797
|
-
|
|
798
|
-
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
799
|
-
projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
|
800
|
-
|
|
801
|
-
chai.request(server)
|
|
802
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
803
|
-
.auth(email, pwd)
|
|
804
|
-
.end((err, res) => {
|
|
805
|
-
|
|
806
|
-
if (err) { console.error("err: ", err); }
|
|
807
|
-
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
808
|
-
|
|
809
|
-
chai.request(server)
|
|
810
|
-
.post('/' + savedProject._id + "/kb/qa")
|
|
811
|
-
.auth(email, pwd)
|
|
812
|
-
.send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question", advancedPrompt: true, system_context: "You are a robot coming from future" })
|
|
813
|
-
.end((err, res) => {
|
|
814
|
-
|
|
815
|
-
if (err) { console.error("err: ", err) };
|
|
816
|
-
if (log) { console.log("res.body: ", res.body) };
|
|
817
|
-
|
|
818
|
-
done();
|
|
819
|
-
})
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
})
|
|
823
|
-
})
|
|
824
|
-
})
|
|
825
|
-
}).timeout(10000)
|
|
826
|
-
|
|
827
|
-
it('askkb-with-hybrid-search', (done) => {
|
|
828
|
-
|
|
829
|
-
var email = "test-signup-" + Date.now() + "@email.com";
|
|
830
|
-
var pwd = "pwd";
|
|
831
|
-
|
|
832
|
-
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
833
|
-
projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
|
834
|
-
|
|
835
|
-
chai.request(server)
|
|
836
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
837
|
-
.auth(email, pwd)
|
|
838
|
-
.end((err, res) => {
|
|
839
|
-
|
|
840
|
-
if (err) { console.error("err: ", err); }
|
|
841
|
-
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
842
|
-
|
|
843
|
-
res.should.have.status(200)
|
|
844
|
-
expect(res.body.length).to.equal(1);
|
|
845
|
-
expect(res.body[0].type === "serverless");
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
chai.request(server)
|
|
849
|
-
.post('/' + savedProject._id + "/kb/qa")
|
|
850
|
-
.auth(email, pwd)
|
|
851
|
-
.send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question", advancedPrompt: true, system_context: "You are a robot coming from future" })
|
|
852
|
-
.end((err, res) => {
|
|
853
|
-
|
|
854
|
-
if (err) { console.error("err: ", err) };
|
|
855
|
-
if (log) { console.log("res.body: ", res.body) };
|
|
856
|
-
|
|
857
|
-
res.should.have.status(200);
|
|
858
|
-
expect(res.body.data);
|
|
859
|
-
expect(res.body.data.search_type === "hybrid");
|
|
860
|
-
|
|
861
|
-
done();
|
|
862
|
-
})
|
|
863
|
-
|
|
864
1052
|
|
|
865
|
-
})
|
|
866
|
-
})
|
|
867
|
-
})
|
|
868
1053
|
}).timeout(10000)
|
|
869
1054
|
|
|
870
|
-
it('
|
|
1055
|
+
it('add-multiple-urls-success', (done) => {
|
|
871
1056
|
|
|
872
1057
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
873
1058
|
var pwd = "pwd";
|
|
874
1059
|
|
|
875
1060
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
876
|
-
projectService.create("test-
|
|
1061
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
877
1062
|
|
|
878
1063
|
chai.request(server)
|
|
879
1064
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
880
1065
|
.auth(email, pwd)
|
|
881
1066
|
.end((err, res) => {
|
|
882
1067
|
|
|
883
|
-
if (err) { console.
|
|
884
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
885
|
-
|
|
886
|
-
res.should.have.status(200);
|
|
887
|
-
res.body.should.be.a('array');
|
|
888
|
-
|
|
889
|
-
let namespace_id = res.body[0].id;
|
|
890
|
-
|
|
891
|
-
let kb = {
|
|
892
|
-
name: "example_name6",
|
|
893
|
-
type: "url",
|
|
894
|
-
source: "https://www.exampleurl6.com",
|
|
895
|
-
content: "",
|
|
896
|
-
namespace: namespace_id
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
chai.request(server)
|
|
900
|
-
.post('/' + savedProject._id + '/kb/')
|
|
901
|
-
.auth(email, pwd)
|
|
902
|
-
.send(kb)
|
|
903
|
-
.end((err, res) => {
|
|
904
|
-
|
|
905
|
-
if (err) { console.log("error: ", err) };
|
|
906
|
-
if (log) { console.log("res.body: ", res.body) };
|
|
907
|
-
|
|
908
|
-
res.should.have.status(200);
|
|
909
|
-
res.body.should.be.a('object');
|
|
910
|
-
|
|
911
|
-
let kb_id = res.body.value._id;
|
|
912
|
-
|
|
913
|
-
chai.request(server)
|
|
914
|
-
.post('/webhook/kb/status')
|
|
915
|
-
.set("x-auth-token", "testtoken")
|
|
916
|
-
.send({ id: kb_id, status: 300 })
|
|
917
|
-
.end((err, res) => {
|
|
918
|
-
|
|
919
|
-
if (err) { console.error("err: ", err) };
|
|
920
|
-
if (log) { console.log("res.body: ", res.body) };
|
|
921
|
-
|
|
922
|
-
res.should.have.status(200);
|
|
923
|
-
res.body.should.be.a('object');
|
|
924
|
-
expect(res.body.status).to.equal(300);
|
|
1068
|
+
if (err) { console.error("err: ", err); }
|
|
1069
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
925
1070
|
|
|
926
|
-
|
|
1071
|
+
res.should.have.status(200)
|
|
1072
|
+
expect(res.body.length).to.equal(1);
|
|
927
1073
|
|
|
928
|
-
|
|
1074
|
+
let namespace = res.body[0];
|
|
1075
|
+
let namespace_id = namespace.id;
|
|
929
1076
|
|
|
1077
|
+
chai.request(server)
|
|
1078
|
+
.post('/' + savedProject._id + '/kb/multi?namespace=' + namespace_id)
|
|
1079
|
+
.auth(email, pwd)
|
|
1080
|
+
.set('Content-Type', 'text/plain')
|
|
1081
|
+
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/kbUrlsList.txt')), 'kbUrlsList.txt')
|
|
1082
|
+
.end((err, res) => {
|
|
930
1083
|
|
|
931
|
-
|
|
932
|
-
|
|
1084
|
+
if (err) { console.error("err: ", err); }
|
|
1085
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
933
1086
|
|
|
1087
|
+
res.should.have.status(200);
|
|
934
1088
|
|
|
1089
|
+
let realResponse = res.body.result;
|
|
1090
|
+
expect(realResponse.length).to.equal(4);
|
|
1091
|
+
expect(realResponse[0].namespace).to.equal(namespace_id);
|
|
1092
|
+
expect(realResponse[0].source).to.equal('https://gethelp.tiledesk.com/articles/article1');
|
|
1093
|
+
should.not.exist(realResponse[0].engine);
|
|
1094
|
+
should.not.exist(realResponse[0].embedding);
|
|
1095
|
+
expect(realResponse[1].namespace).to.equal(namespace_id);
|
|
1096
|
+
expect(realResponse[1].source).to.equal('https://gethelp.tiledesk.com/articles/article2');
|
|
1097
|
+
|
|
1098
|
+
let scheduleJson = res.body.schedule_json;
|
|
1099
|
+
expect(scheduleJson.length).to.equal(4);
|
|
1100
|
+
expect(scheduleJson[0].namespace).to.equal(namespace_id);
|
|
1101
|
+
expect(scheduleJson[0].source).to.equal('https://gethelp.tiledesk.com/articles/article1');
|
|
1102
|
+
should.exist(scheduleJson[0].engine);
|
|
1103
|
+
should.exist(scheduleJson[0].embedding);
|
|
1104
|
+
expect(scheduleJson[0].engine.index_name).to.equal(namespace.engine.index_name);
|
|
1105
|
+
expect(scheduleJson[0].embedding.provider).to.equal(namespace.embedding.provider);
|
|
1106
|
+
expect(scheduleJson[0].embedding.name).to.equal(namespace.embedding.name);
|
|
1107
|
+
|
|
1108
|
+
expect(scheduleJson[1].namespace).to.equal(namespace_id);
|
|
1109
|
+
expect(scheduleJson[1].source).to.equal('https://gethelp.tiledesk.com/articles/article2');
|
|
935
1110
|
|
|
1111
|
+
done();
|
|
936
1112
|
|
|
1113
|
+
})
|
|
1114
|
+
})
|
|
937
1115
|
});
|
|
938
1116
|
});
|
|
1117
|
+
|
|
939
1118
|
}).timeout(10000)
|
|
940
1119
|
|
|
941
|
-
it('
|
|
1120
|
+
it('add-multiple-urls-with-scrape-option-success-type-4', (done) => {
|
|
942
1121
|
|
|
943
1122
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
944
1123
|
var pwd = "pwd";
|
|
945
1124
|
|
|
946
1125
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
947
|
-
projectService.create("test-
|
|
1126
|
+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
948
1127
|
|
|
949
1128
|
chai.request(server)
|
|
950
1129
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
951
1130
|
.auth(email, pwd)
|
|
952
1131
|
.end((err, res) => {
|
|
953
1132
|
|
|
954
|
-
if (err) { console.
|
|
955
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
1133
|
+
if (err) { console.error("err: ", err); }
|
|
1134
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
956
1135
|
|
|
957
|
-
res.should.have.status(200)
|
|
958
|
-
res.body.
|
|
1136
|
+
res.should.have.status(200)
|
|
1137
|
+
expect(res.body.length).to.equal(1);
|
|
959
1138
|
|
|
960
1139
|
let namespace_id = res.body[0].id;
|
|
961
1140
|
|
|
962
|
-
let kb = {
|
|
963
|
-
name: "example_name6",
|
|
964
|
-
type: "url",
|
|
965
|
-
source: "https://www.exampleurl6.com",
|
|
966
|
-
content: "",
|
|
967
|
-
namespace: namespace_id
|
|
968
|
-
}
|
|
969
|
-
|
|
970
1141
|
chai.request(server)
|
|
971
|
-
.post('/' + savedProject._id + '/kb/')
|
|
1142
|
+
.post('/' + savedProject._id + '/kb/multi?namespace=' + namespace_id)
|
|
972
1143
|
.auth(email, pwd)
|
|
973
|
-
.send(
|
|
1144
|
+
.send({ list:["https://gethelp.tiledesk.com/article"], scrape_type: 4, scrape_options: { tags_to_extract: ["article","p"], unwanted_tags:["script","style"], unwanted_classnames:["header","related-articles"]}})
|
|
974
1145
|
.end((err, res) => {
|
|
975
1146
|
|
|
976
|
-
if (err) { console.
|
|
977
|
-
if (log) { console.log("res.body: ", res.body) }
|
|
1147
|
+
if (err) { console.error("err: ", err); }
|
|
1148
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
978
1149
|
|
|
979
1150
|
res.should.have.status(200);
|
|
980
|
-
res.body.should.be.a('object');
|
|
981
|
-
|
|
982
|
-
let kb_id = res.body.value._id;
|
|
983
|
-
|
|
984
|
-
chai.request(server)
|
|
985
|
-
.post('/webhook/kb/reindex')
|
|
986
|
-
.set("x-auth-token", "testtoken")
|
|
987
|
-
.send({ content_id: kb_id })
|
|
988
|
-
.end((err, res) => {
|
|
989
|
-
|
|
990
|
-
if (err) { console.error("err: ", err) };
|
|
991
|
-
if (log) { console.log("res.body: ", res.body) };
|
|
992
|
-
|
|
993
|
-
res.should.have.status(200);
|
|
994
|
-
res.body.should.be.a('object');
|
|
995
|
-
expect(res.body.success).to.equal(true);
|
|
996
|
-
expect(res.body.message).to.equal("Content queued for reindexing");
|
|
997
|
-
|
|
998
|
-
done();
|
|
999
1151
|
|
|
1000
|
-
|
|
1152
|
+
let realResponse = res.body.result;
|
|
1153
|
+
expect(realResponse.length).to.equal(1)
|
|
1154
|
+
expect(realResponse[0].scrape_type).to.equal(4)
|
|
1155
|
+
expect(typeof realResponse[0].scrape_options === "undefined").to.be.false;
|
|
1156
|
+
expect(realResponse[0].scrape_options.tags_to_extract.length).to.equal(2);
|
|
1157
|
+
expect(realResponse[0].scrape_options.unwanted_tags.length).to.equal(2);
|
|
1158
|
+
expect(realResponse[0].scrape_options.unwanted_classnames.length).to.equal(2);
|
|
1001
1159
|
|
|
1160
|
+
done();
|
|
1002
1161
|
|
|
1003
1162
|
})
|
|
1004
1163
|
})
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
1164
|
});
|
|
1010
1165
|
});
|
|
1011
|
-
}).timeout(10000)
|
|
1012
1166
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
describe('/namespaces', () => {
|
|
1167
|
+
}).timeout(10000)
|
|
1017
1168
|
|
|
1018
|
-
|
|
1019
|
-
* Get all namespaces of a project.
|
|
1020
|
-
* If there isn't namespaces for a project_id, the default namespace is created and returned.
|
|
1021
|
-
*/
|
|
1022
|
-
it('get-namespaces-1', (done) => {
|
|
1169
|
+
it('add-multiple-urls-with-scrape-option-success-type-3', (done) => {
|
|
1023
1170
|
|
|
1024
1171
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1025
1172
|
var pwd = "pwd";
|
|
@@ -1033,99 +1180,39 @@ describe('KbRoute', () => {
|
|
|
1033
1180
|
.end((err, res) => {
|
|
1034
1181
|
|
|
1035
1182
|
if (err) { console.error("err: ", err); }
|
|
1036
|
-
if (log) { console.log("
|
|
1183
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
1037
1184
|
|
|
1038
|
-
res.should.have.status(200)
|
|
1039
|
-
res.body.should.be.a('array');
|
|
1185
|
+
res.should.have.status(200)
|
|
1040
1186
|
expect(res.body.length).to.equal(1);
|
|
1041
|
-
should.not.exist(res.body[0]._id);
|
|
1042
|
-
//expect(res.body[0]._id).to.equal(undefined);
|
|
1043
|
-
expect(res.body[0].id).to.equal(savedProject._id.toString());
|
|
1044
|
-
expect(res.body[0].name).to.equal("Default");
|
|
1045
|
-
should.exist(res.body[0].engine)
|
|
1046
|
-
expect(res.body[0].engine.name).to.equal('pinecone')
|
|
1047
1187
|
|
|
1048
|
-
|
|
1188
|
+
let namespace_id = res.body[0].id;
|
|
1189
|
+
|
|
1190
|
+
chai.request(server)
|
|
1191
|
+
.post('/' + savedProject._id + '/kb/multi?namespace=' + namespace_id)
|
|
1192
|
+
.auth(email, pwd)
|
|
1193
|
+
.send({ list:["https://gethelp.tiledesk.com/article"], refresh_rate: 'daily', scrape_type: 3 })
|
|
1194
|
+
.end((err, res) => {
|
|
1049
1195
|
|
|
1196
|
+
if (err) { console.error("err: ", err); }
|
|
1197
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
1050
1198
|
|
|
1051
|
-
|
|
1199
|
+
res.should.have.status(200);
|
|
1200
|
+
|
|
1201
|
+
let realResponse = res.body.result;
|
|
1202
|
+
expect(realResponse.length).to.equal(1)
|
|
1203
|
+
expect(realResponse[0].scrape_type).to.equal(3)
|
|
1204
|
+
expect(typeof realResponse[0].scrape_options === null);
|
|
1205
|
+
|
|
1206
|
+
done();
|
|
1052
1207
|
|
|
1208
|
+
})
|
|
1209
|
+
})
|
|
1053
1210
|
});
|
|
1054
1211
|
});
|
|
1055
1212
|
|
|
1056
|
-
})
|
|
1057
|
-
|
|
1058
|
-
/**
|
|
1059
|
-
* Get all namespaces of a project.
|
|
1060
|
-
* If there isn't namespaces for a project_id, the default namespace is created and returned.
|
|
1061
|
-
* WARNING: not working due to namspace creation limit (on trial plan)
|
|
1062
|
-
*/
|
|
1063
|
-
// it('create-and-get-namespaces', (done) => {
|
|
1064
|
-
|
|
1065
|
-
// var email = "test-signup-" + Date.now() + "@email.com";
|
|
1066
|
-
// var pwd = "pwd";
|
|
1067
|
-
|
|
1068
|
-
// userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
1069
|
-
// projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
1070
|
-
|
|
1071
|
-
// // Get all namespaces. Create default namespace and return.
|
|
1072
|
-
// chai.request(server)
|
|
1073
|
-
// .get('/' + savedProject._id + '/kb/namespace/all')
|
|
1074
|
-
// .auth(email, pwd)
|
|
1075
|
-
// .end((err, res) => {
|
|
1076
|
-
|
|
1077
|
-
// if (err) { console.error("err: ", err); }
|
|
1078
|
-
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1079
|
-
// console.log("get all namespaces res.body: ", res.body);
|
|
1080
|
-
// res.should.have.status(200);
|
|
1081
|
-
// res.body.should.be.a('array');
|
|
1082
|
-
// expect(res.body.length).to.equal(1);
|
|
1083
|
-
// should.not.exist(res.body[0]._id);
|
|
1084
|
-
// expect(res.body[0].id).to.equal(savedProject._id.toString());
|
|
1085
|
-
// expect(res.body[0].name).to.equal("Default");
|
|
1086
|
-
|
|
1087
|
-
// // Create another namespace
|
|
1088
|
-
// chai.request(server)
|
|
1089
|
-
// .post('/' + savedProject._id + '/kb/namespace')
|
|
1090
|
-
// .auth(email, pwd)
|
|
1091
|
-
// .send({ name: "MyCustomNamespace" })
|
|
1092
|
-
// .end((err, res) => {
|
|
1093
|
-
|
|
1094
|
-
// if (err) { console.error("err: ", err) }
|
|
1095
|
-
// if (log) { console.log("create new namespace res.body: ", res.body) }
|
|
1096
|
-
// console.log("create new namespace res.body: ", res.body)
|
|
1097
|
-
// res.should.have.status(200);
|
|
1098
|
-
// res.body.should.be.a('object');
|
|
1099
|
-
// should.not.exist(res.body._id)
|
|
1100
|
-
// should.exist(res.body.id)
|
|
1101
|
-
// expect(res.body.name).to.equal('MyCustomNamespace');
|
|
1102
|
-
|
|
1103
|
-
// // Get again all namespace. A new default namespace should not be created.
|
|
1104
|
-
// chai.request(server)
|
|
1105
|
-
// .get('/' + savedProject._id + '/kb/namespace/all')
|
|
1106
|
-
// .auth(email, pwd)
|
|
1107
|
-
// .end((err, res) => {
|
|
1108
|
-
|
|
1109
|
-
// if (err) { console.error("err: ", err); }
|
|
1110
|
-
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1111
|
-
|
|
1112
|
-
// res.should.have.status(200);
|
|
1113
|
-
// res.body.should.be.a('array');
|
|
1114
|
-
// expect(res.body.length).to.equal(2);
|
|
1115
|
-
// should.not.exist(res.body[0]._id);
|
|
1116
|
-
// should.not.exist(res.body[1]._id);
|
|
1117
|
-
// should.exist(res.body[0].id);
|
|
1118
|
-
// should.exist(res.body[1].id);
|
|
1119
|
-
|
|
1120
|
-
// done();
|
|
1121
|
-
// })
|
|
1122
|
-
// })
|
|
1123
|
-
// })
|
|
1124
|
-
// });
|
|
1125
|
-
// });
|
|
1126
|
-
// })
|
|
1213
|
+
}).timeout(10000)
|
|
1127
1214
|
|
|
1128
|
-
it('
|
|
1215
|
+
it('expand-sitemap', (done) => {
|
|
1129
1216
|
|
|
1130
1217
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1131
1218
|
var pwd = "pwd";
|
|
@@ -1134,74 +1221,88 @@ describe('KbRoute', () => {
|
|
|
1134
1221
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
1135
1222
|
|
|
1136
1223
|
chai.request(server)
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1224
|
+
.post('/' + savedProject._id + '/kb/sitemap')
|
|
1225
|
+
.auth(email, pwd)
|
|
1226
|
+
// .send({ sitemap: "https://www.wired.it/sitemap.xml" })
|
|
1227
|
+
.send({ sitemap: "https://gethelp.tiledesk.com/sitemap.xml" })
|
|
1228
|
+
.end((err, res) => {
|
|
1141
1229
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1230
|
+
if (err) { console.log("error: ", err) };
|
|
1231
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
1232
|
+
|
|
1233
|
+
res.should.have.status(200);
|
|
1234
|
+
res.body.should.be.a('object');
|
|
1235
|
+
res.body.sites.should.be.a('array');
|
|
1236
|
+
|
|
1237
|
+
done();
|
|
1238
|
+
|
|
1239
|
+
})
|
|
1144
1240
|
|
|
1145
|
-
res.should.have.status(200);
|
|
1146
|
-
res.body.should.be.a('object');
|
|
1147
|
-
should.not.exist(res.body._id)
|
|
1148
|
-
should.exist(res.body.id)
|
|
1149
|
-
expect(res.body.name).to.equal('MyCustomNamespace');
|
|
1150
|
-
should.exist(res.body.engine)
|
|
1151
|
-
expect(res.body.engine.name).to.equal('pinecone');
|
|
1152
|
-
expect(res.body.engine.type).to.equal('serverless');
|
|
1153
|
-
|
|
1154
|
-
// Get again all namespace. A new default namespace should not be created.
|
|
1155
|
-
chai.request(server)
|
|
1156
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1157
|
-
.auth(email, pwd)
|
|
1158
|
-
.end((err, res) => {
|
|
1159
|
-
|
|
1160
|
-
if (err) { console.error("err: ", err); }
|
|
1161
|
-
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1162
|
-
|
|
1163
|
-
res.should.have.status(200);
|
|
1164
|
-
res.body.should.be.a('array');
|
|
1165
|
-
expect(res.body.length).to.equal(1);
|
|
1166
|
-
should.not.exist(res.body[0]._id);
|
|
1167
|
-
should.exist(res.body[0].id);
|
|
1168
|
-
|
|
1169
|
-
done();
|
|
1170
|
-
})
|
|
1171
|
-
})
|
|
1172
1241
|
});
|
|
1173
1242
|
});
|
|
1174
|
-
})
|
|
1175
1243
|
|
|
1176
|
-
|
|
1244
|
+
}).timeout(10000)
|
|
1245
|
+
|
|
1246
|
+
it('import-sitemap', (done) => {
|
|
1177
1247
|
|
|
1178
1248
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1179
1249
|
var pwd = "pwd";
|
|
1180
|
-
|
|
1181
|
-
userService.signup(email, pwd, "Test Firstname", "Test
|
|
1182
|
-
projectService.create("test-
|
|
1250
|
+
|
|
1251
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
1252
|
+
projectService.create("test-kb-import-sitemap", savedUser._id).then((savedProject) => {
|
|
1183
1253
|
|
|
1184
1254
|
chai.request(server)
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1255
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1256
|
+
.auth(email, pwd)
|
|
1257
|
+
.end((err, res) => {
|
|
1258
|
+
|
|
1259
|
+
if (err) { console.error("err: ", err); }
|
|
1260
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
1189
1261
|
|
|
1190
|
-
|
|
1191
|
-
|
|
1262
|
+
res.should.have.status(200)
|
|
1263
|
+
expect(res.body.length).to.equal(1);
|
|
1192
1264
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1265
|
+
let namespace_id = res.body[0].id;
|
|
1266
|
+
|
|
1267
|
+
let content = {
|
|
1268
|
+
name: "https://www.sitemaps.org/sitemap.xml",
|
|
1269
|
+
type: "sitemap",
|
|
1270
|
+
source: "https://www.sitemaps.org/sitemap.xml",
|
|
1271
|
+
content: "",
|
|
1272
|
+
namespace: namespace_id
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
chai.request(server)
|
|
1276
|
+
.post('/' + savedProject._id + '/kb/sitemap/import?namespace=' + namespace_id)
|
|
1277
|
+
.auth(email, pwd)
|
|
1278
|
+
.send(content)
|
|
1279
|
+
.end((err, res) => {
|
|
1280
|
+
|
|
1281
|
+
if (err) { console.error("err: ", err); }
|
|
1282
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
1283
|
+
|
|
1284
|
+
let realResponse = res.body.result;
|
|
1285
|
+
realResponse.should.be.a('array');
|
|
1286
|
+
should.exist(realResponse[0]._id);
|
|
1287
|
+
should.exist(realResponse[0].sitemap_origin_id);
|
|
1288
|
+
let sitemap_content = realResponse.find(e => e.type === 'sitemap');
|
|
1289
|
+
expect(sitemap_content).not.equal(null);
|
|
1290
|
+
expect(realResponse[0].sitemap_origin).to.equal("https://www.sitemaps.org/sitemap.xml");
|
|
1291
|
+
|
|
1292
|
+
let scheduleJson = res.body.schedule_json;
|
|
1293
|
+
scheduleJson.should.be.a('array');
|
|
1294
|
+
should.exist(scheduleJson[0].engine)
|
|
1295
|
+
should.exist(scheduleJson[0].embedding)
|
|
1296
|
+
|
|
1297
|
+
done();
|
|
1298
|
+
})
|
|
1299
|
+
|
|
1300
|
+
})
|
|
1301
|
+
})
|
|
1302
|
+
})
|
|
1303
|
+
}).timeout(3000)
|
|
1304
|
+
|
|
1305
|
+
it('scrape-single', (done) => {
|
|
1205
1306
|
|
|
1206
1307
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1207
1308
|
var pwd = "pwd";
|
|
@@ -1210,69 +1311,83 @@ describe('KbRoute', () => {
|
|
|
1210
1311
|
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
|
|
1211
1312
|
|
|
1212
1313
|
chai.request(server)
|
|
1213
|
-
.
|
|
1214
|
-
.
|
|
1314
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1315
|
+
.auth(email, pwd)
|
|
1215
1316
|
.end((err, res) => {
|
|
1216
1317
|
|
|
1217
|
-
if (err) { console.error("err: ", err) }
|
|
1218
|
-
if (log) { console.log("
|
|
1318
|
+
if (err) { console.error("err: ", err); }
|
|
1319
|
+
if (log) { console.log("res.body: ", res.body) }
|
|
1219
1320
|
|
|
1220
|
-
res.should.have.status(200)
|
|
1221
|
-
res.body.
|
|
1222
|
-
expect(res.body.
|
|
1223
|
-
expect(res.body.token).not.equal(null);
|
|
1321
|
+
res.should.have.status(200)
|
|
1322
|
+
expect(res.body.length).to.equal(1);
|
|
1323
|
+
expect(res.body[0].id_project).to.equal(savedProject._id.toString())
|
|
1224
1324
|
|
|
1225
|
-
let
|
|
1325
|
+
let namespace_id = res.body[0].id;
|
|
1226
1326
|
|
|
1327
|
+
let kb = {
|
|
1328
|
+
name: "https://www.exampleurl6.com",
|
|
1329
|
+
type: "url",
|
|
1330
|
+
source: "https://www.exampleurl6.com",
|
|
1331
|
+
content: "",
|
|
1332
|
+
namespace: namespace_id
|
|
1333
|
+
}
|
|
1227
1334
|
|
|
1228
1335
|
chai.request(server)
|
|
1229
|
-
.
|
|
1230
|
-
.
|
|
1231
|
-
.send(
|
|
1336
|
+
.post('/' + savedProject._id + '/kb')
|
|
1337
|
+
.auth(email, pwd)
|
|
1338
|
+
.send(kb)
|
|
1232
1339
|
.end((err, res) => {
|
|
1233
1340
|
|
|
1234
|
-
if (err) { console.error("err: ", err) }
|
|
1235
|
-
if (log) { console.log("
|
|
1341
|
+
if (err) { console.error("err: ", err); }
|
|
1342
|
+
if (log) { console.log("create kb res.body: ", res.body); }
|
|
1236
1343
|
|
|
1237
1344
|
res.should.have.status(200);
|
|
1238
|
-
|
|
1239
|
-
|
|
1345
|
+
|
|
1346
|
+
let realResponse = res.body.data;
|
|
1347
|
+
let savedKb = realResponse.value;
|
|
1348
|
+
expect(savedKb.id_project).to.equal(savedProject._id.toString())
|
|
1349
|
+
|
|
1350
|
+
kb.id = realResponse.value._id;
|
|
1240
1351
|
|
|
1241
1352
|
chai.request(server)
|
|
1242
|
-
.post('/' + savedProject._id +
|
|
1353
|
+
.post('/' + savedProject._id + "/kb/scrape/single")
|
|
1243
1354
|
.auth(email, pwd)
|
|
1244
|
-
.send(
|
|
1355
|
+
.send(kb)
|
|
1245
1356
|
.end((err, res) => {
|
|
1246
|
-
|
|
1247
|
-
if (err) { console.error("err: ", err) }
|
|
1248
|
-
if (log) { console.log("
|
|
1249
|
-
|
|
1357
|
+
|
|
1358
|
+
if (err) { console.error("err: ", err); }
|
|
1359
|
+
if (log) { console.log("single scrape res.body: ", res.body); }
|
|
1360
|
+
|
|
1250
1361
|
res.should.have.status(200);
|
|
1251
1362
|
res.body.should.be.a('object');
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
expect(res.body.
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
expect(res.body.engine.
|
|
1258
|
-
|
|
1363
|
+
expect(res.body.success).to.equal(true);
|
|
1364
|
+
expect(res.body.message).to.equal("Skip indexing in test environment");
|
|
1365
|
+
expect(res.body.data.type).to.equal('url');
|
|
1366
|
+
expect(res.body.data.namespace).to.equal(namespace_id);
|
|
1367
|
+
should.exist(res.body.data.engine);
|
|
1368
|
+
expect(res.body.data.engine.index_name).to.equal("test-index");
|
|
1369
|
+
expect(res.body.data.engine.vector_size).to.equal(1536);
|
|
1370
|
+
should.exist(res.body.data.embedding);
|
|
1371
|
+
expect(res.body.data.embedding.provider).to.equal("openai");
|
|
1372
|
+
expect(res.body.data.embedding.name).to.equal("text-embedding-ada-002");
|
|
1373
|
+
expect(res.body.data.embedding.dimension).to.equal(1536);
|
|
1374
|
+
|
|
1259
1375
|
done();
|
|
1376
|
+
|
|
1260
1377
|
})
|
|
1261
1378
|
})
|
|
1262
|
-
|
|
1263
1379
|
})
|
|
1264
|
-
|
|
1265
|
-
})
|
|
1380
|
+
});
|
|
1266
1381
|
});
|
|
1267
|
-
})
|
|
1382
|
+
}).timeout(5000);
|
|
1383
|
+
|
|
1384
|
+
it('askkb-key-from-env', (done) => {
|
|
1268
1385
|
|
|
1269
|
-
it('import-namespace', (done) => {
|
|
1270
|
-
|
|
1271
1386
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1272
1387
|
var pwd = "pwd";
|
|
1273
1388
|
|
|
1274
1389
|
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
1275
|
-
projectService.create("test-
|
|
1390
|
+
projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
|
1276
1391
|
|
|
1277
1392
|
chai.request(server)
|
|
1278
1393
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
@@ -1282,48 +1397,46 @@ describe('KbRoute', () => {
|
|
|
1282
1397
|
if (err) { console.error("err: ", err); }
|
|
1283
1398
|
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1284
1399
|
|
|
1285
|
-
res.should.have.status(200)
|
|
1286
|
-
res.body.should.be.a('array');
|
|
1287
|
-
expect(res.body[0].name).to.equal("Default");
|
|
1288
|
-
|
|
1289
|
-
let namespace_id = res.body[0].id;
|
|
1400
|
+
res.should.have.status(200)
|
|
1290
1401
|
|
|
1291
1402
|
chai.request(server)
|
|
1292
|
-
.post('/' + savedProject._id +
|
|
1403
|
+
.post('/' + savedProject._id + "/kb/qa")
|
|
1293
1404
|
.auth(email, pwd)
|
|
1294
|
-
.
|
|
1295
|
-
.attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './fixtures/exported_namespace.json')), 'exported_namespace.json')
|
|
1405
|
+
.send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question", advancedPrompt: true, system_context: "You are a robot coming from future" })
|
|
1296
1406
|
.end((err, res) => {
|
|
1297
1407
|
|
|
1298
|
-
if (err) { console.error("err: ", err)
|
|
1299
|
-
if (log) { console.log("
|
|
1408
|
+
if (err) { console.error("err: ", err) };
|
|
1409
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1300
1410
|
|
|
1301
|
-
res.should.have.status(200)
|
|
1302
|
-
res.body.should.be.a('object');
|
|
1411
|
+
res.should.have.status(200)
|
|
1303
1412
|
expect(res.body.success).to.equal(true);
|
|
1304
|
-
expect(res.body.message).to.equal("
|
|
1413
|
+
expect(res.body.message).to.equal("Question skipped in test environment");
|
|
1414
|
+
res.body.data.model.should.be.a('object');
|
|
1415
|
+
expect(res.body.data.model.provider).to.equal("openai")
|
|
1416
|
+
expect(res.body.data.model.name).to.equal("gpt-4o")
|
|
1417
|
+
expect(res.body.data.model.api_key).to.equal("fakegptkey");
|
|
1418
|
+
expect(res.body.data.question).to.equal("sample question");
|
|
1419
|
+
should.exist(res.body.data.engine);
|
|
1420
|
+
should.exist(res.body.data.embedding);
|
|
1421
|
+
expect(res.body.data.embedding.api_key).to.equal("fakegptkey");
|
|
1305
1422
|
|
|
1306
1423
|
done();
|
|
1307
|
-
|
|
1308
1424
|
})
|
|
1309
1425
|
|
|
1426
|
+
|
|
1310
1427
|
})
|
|
1311
1428
|
})
|
|
1312
1429
|
})
|
|
1313
|
-
})
|
|
1430
|
+
}).timeout(10000)
|
|
1314
1431
|
|
|
1315
|
-
|
|
1316
|
-
* Update namespaces
|
|
1317
|
-
*/
|
|
1318
|
-
it('update-namespace', (done) => {
|
|
1432
|
+
it('askkb-with-hybrid-search', (done) => {
|
|
1319
1433
|
|
|
1320
1434
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1321
1435
|
var pwd = "pwd";
|
|
1322
1436
|
|
|
1323
|
-
userService.signup(email, pwd, "Test Firstname", "Test
|
|
1324
|
-
projectService.create("test-
|
|
1437
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
|
1438
|
+
projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
|
1325
1439
|
|
|
1326
|
-
// Get all namespaces. Create default namespace and return.
|
|
1327
1440
|
chai.request(server)
|
|
1328
1441
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1329
1442
|
.auth(email, pwd)
|
|
@@ -1332,260 +1445,193 @@ describe('KbRoute', () => {
|
|
|
1332
1445
|
if (err) { console.error("err: ", err); }
|
|
1333
1446
|
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1334
1447
|
|
|
1335
|
-
res.should.have.status(200)
|
|
1336
|
-
res.body.should.be.a('array');
|
|
1448
|
+
res.should.have.status(200)
|
|
1337
1449
|
expect(res.body.length).to.equal(1);
|
|
1338
|
-
expect(res.body[0].
|
|
1339
|
-
expect(res.body[0].name).to.equal("Default");
|
|
1340
|
-
|
|
1341
|
-
let namespace_id = res.body[0].id;
|
|
1450
|
+
expect(res.body[0].type === "serverless");
|
|
1342
1451
|
|
|
1343
|
-
let new_settings = {
|
|
1344
|
-
model: 'gpt-4o',
|
|
1345
|
-
max_tokens: 256,
|
|
1346
|
-
temperature: 0.3,
|
|
1347
|
-
top_k: 6,
|
|
1348
|
-
context: "You are an awesome AI Assistant."
|
|
1349
|
-
}
|
|
1350
1452
|
|
|
1351
|
-
// Update namespace
|
|
1352
1453
|
chai.request(server)
|
|
1353
|
-
.
|
|
1454
|
+
.post('/' + savedProject._id + "/kb/qa")
|
|
1354
1455
|
.auth(email, pwd)
|
|
1355
|
-
.send({
|
|
1456
|
+
.send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question", advancedPrompt: true, system_context: "You are a robot coming from future" })
|
|
1356
1457
|
.end((err, res) => {
|
|
1357
1458
|
|
|
1358
|
-
if (err) { console.error("err: ", err) }
|
|
1359
|
-
if (log) { console.log("
|
|
1459
|
+
if (err) { console.error("err: ", err) };
|
|
1460
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1360
1461
|
|
|
1361
1462
|
res.should.have.status(200);
|
|
1362
|
-
res.body.
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
expect(res.body.
|
|
1367
|
-
expect(res.body.
|
|
1368
|
-
expect(res.body.
|
|
1369
|
-
expect(res.body.
|
|
1463
|
+
expect(res.body.data);
|
|
1464
|
+
expect(res.body.success).to.equal(true);
|
|
1465
|
+
expect(res.body.message).to.equal("Question skipped in test environment");
|
|
1466
|
+
res.body.data.model.should.be.a('object');
|
|
1467
|
+
expect(res.body.data.model.provider).to.equal("openai")
|
|
1468
|
+
expect(res.body.data.model.name).to.equal("gpt-4o")
|
|
1469
|
+
expect(res.body.data.model.api_key).to.equal("fakegptkey");
|
|
1470
|
+
expect(res.body.data.search_type === "hybrid");
|
|
1471
|
+
expect(res.body.data.question).to.equal("sample question");
|
|
1472
|
+
should.exist(res.body.data.engine);
|
|
1473
|
+
should.exist(res.body.data.embedding);
|
|
1474
|
+
expect(res.body.data.embedding.api_key).to.equal("fakegptkey");
|
|
1370
1475
|
|
|
1371
1476
|
done();
|
|
1372
|
-
|
|
1373
1477
|
})
|
|
1478
|
+
|
|
1479
|
+
|
|
1374
1480
|
})
|
|
1375
|
-
})
|
|
1376
|
-
})
|
|
1377
|
-
})
|
|
1481
|
+
})
|
|
1482
|
+
})
|
|
1483
|
+
}).timeout(10000)
|
|
1378
1484
|
|
|
1379
|
-
|
|
1380
|
-
* Delete default namespace - Forbidden
|
|
1381
|
-
*/
|
|
1382
|
-
it('fail-to-delete-default-namespace', (done) => {
|
|
1485
|
+
it('webhook', (done) => {
|
|
1383
1486
|
|
|
1384
1487
|
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1385
1488
|
var pwd = "pwd";
|
|
1386
1489
|
|
|
1387
1490
|
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
1388
|
-
projectService.create("test-
|
|
1491
|
+
projectService.create("test-kb-webhook", savedUser._id).then(function (savedProject) {
|
|
1389
1492
|
|
|
1390
|
-
// Get all namespaces. Create default namespace and return.
|
|
1391
1493
|
chai.request(server)
|
|
1392
1494
|
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1393
1495
|
.auth(email, pwd)
|
|
1394
1496
|
.end((err, res) => {
|
|
1395
1497
|
|
|
1396
|
-
if (err) { console.
|
|
1397
|
-
if (log) { console.log("
|
|
1498
|
+
if (err) { console.log("error: ", err) };
|
|
1499
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1398
1500
|
|
|
1399
1501
|
res.should.have.status(200);
|
|
1400
1502
|
res.body.should.be.a('array');
|
|
1401
|
-
expect(res.body.length).to.equal(1);
|
|
1402
|
-
expect(res.body[0].id).to.equal(savedProject._id.toString());
|
|
1403
|
-
expect(res.body[0].name).to.equal("Default");
|
|
1404
1503
|
|
|
1405
1504
|
let namespace_id = res.body[0].id;
|
|
1406
1505
|
|
|
1407
|
-
|
|
1506
|
+
let kb = {
|
|
1507
|
+
name: "example_name6",
|
|
1508
|
+
type: "url",
|
|
1509
|
+
source: "https://www.exampleurl6.com",
|
|
1510
|
+
content: "",
|
|
1511
|
+
namespace: namespace_id
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1408
1514
|
chai.request(server)
|
|
1409
|
-
.
|
|
1515
|
+
.post('/' + savedProject._id + '/kb/')
|
|
1410
1516
|
.auth(email, pwd)
|
|
1517
|
+
.send(kb)
|
|
1411
1518
|
.end((err, res) => {
|
|
1412
1519
|
|
|
1413
|
-
if (err) { console.
|
|
1414
|
-
if (log) { console.log("
|
|
1520
|
+
if (err) { console.log("error: ", err) };
|
|
1521
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1415
1522
|
|
|
1416
|
-
res.should.have.status(
|
|
1523
|
+
res.should.have.status(200);
|
|
1417
1524
|
res.body.should.be.a('object');
|
|
1418
|
-
expect(res.body.success).to.equal(false);
|
|
1419
|
-
expect(res.body.error).to.equal('Default namespace cannot be deleted');
|
|
1420
|
-
|
|
1421
|
-
done();
|
|
1422
|
-
|
|
1423
|
-
})
|
|
1424
|
-
})
|
|
1425
|
-
});
|
|
1426
|
-
});
|
|
1427
|
-
})
|
|
1428
1525
|
|
|
1526
|
+
let realResponse = res.body.data;
|
|
1527
|
+
let kb_id = realResponse.value._id;
|
|
1429
1528
|
|
|
1430
|
-
|
|
1529
|
+
chai.request(server)
|
|
1530
|
+
.post('/webhook/kb/status')
|
|
1531
|
+
.set("x-auth-token", "testtoken")
|
|
1532
|
+
.send({ id: kb_id, status: 300 })
|
|
1533
|
+
.end((err, res) => {
|
|
1431
1534
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1535
|
+
if (err) { console.error("err: ", err) };
|
|
1536
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1434
1537
|
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
faqService.create(savedProject._id, savedUser._id, { name: "testbot2" }).then((savedBot2) => {
|
|
1538
|
+
res.should.have.status(200);
|
|
1539
|
+
res.body.should.be.a('object');
|
|
1540
|
+
expect(res.body.status).to.equal(300);
|
|
1439
1541
|
|
|
1440
|
-
|
|
1441
|
-
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1442
|
-
.auth(email, pwd)
|
|
1443
|
-
.end((err, res) => {
|
|
1542
|
+
done();
|
|
1444
1543
|
|
|
1445
|
-
|
|
1446
|
-
if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1544
|
+
})
|
|
1447
1545
|
|
|
1448
|
-
res.should.have.status(200);
|
|
1449
1546
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1547
|
+
})
|
|
1548
|
+
})
|
|
1452
1549
|
|
|
1453
|
-
let newFaq1 = new faq({
|
|
1454
|
-
id_faq_kb: savedBot1._id,
|
|
1455
|
-
id_project: savedProject._id,
|
|
1456
|
-
intent_id: "new-faq-1",
|
|
1457
|
-
createdBy: savedUser._id,
|
|
1458
|
-
updatedBy: savedUser._id,
|
|
1459
|
-
actions: [{ "_tdActionType": "askgptv2", "_tdActionId": "f58212f9-1a8c-4623-b6fa-0f34e57d9999", "namespace": namespace_id }]
|
|
1460
|
-
})
|
|
1461
1550
|
|
|
1462
|
-
newFaq1.save((err, saved1) => {
|
|
1463
|
-
if (err) { console.error("err1: ", err) };
|
|
1464
|
-
if (log) { console.log("faq1 saved: ", saved1) };
|
|
1465
1551
|
|
|
1466
|
-
let newFaq2 = new faq({
|
|
1467
|
-
id_faq_kb: savedBot2._id,
|
|
1468
|
-
id_project: savedProject._id,
|
|
1469
|
-
intent_id: "new-faq-2",
|
|
1470
|
-
createdBy: savedUser._id,
|
|
1471
|
-
updatedBy: savedUser._id,
|
|
1472
|
-
actions: [{ "_tdActionType": "reply", "_tdActionId": "f58212f9-1a8c-4623-b6fa-0f34e57d9998" }]
|
|
1473
|
-
})
|
|
1474
1552
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
}).timeout(10000)
|
|
1478
1556
|
|
|
1479
|
-
|
|
1480
|
-
.get('/' + savedProject._id + '/kb/namespace/' + namespace_id + '/chatbots')
|
|
1481
|
-
.auth(email, pwd)
|
|
1482
|
-
.end((err, res) => {
|
|
1557
|
+
it('webhook-reindex', (done) => {
|
|
1483
1558
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
res.should.have.status(200);
|
|
1488
|
-
res.body.should.be.a('array');
|
|
1489
|
-
expect(res.body.length).to.equal(1);
|
|
1490
|
-
expect(res.body[0]._id).to.equal((savedBot1._id).toString());
|
|
1491
|
-
expect(res.body[0].name).to.equal('testbot1');
|
|
1559
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
|
1560
|
+
var pwd = "pwd";
|
|
1492
1561
|
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
})
|
|
1496
|
-
})
|
|
1497
|
-
})
|
|
1562
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
|
1563
|
+
projectService.create("test-kb-webhook", savedUser._id).then(function (savedProject) {
|
|
1498
1564
|
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
}).timeout(10000)
|
|
1565
|
+
chai.request(server)
|
|
1566
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
|
1567
|
+
.auth(email, pwd)
|
|
1568
|
+
.end((err, res) => {
|
|
1504
1569
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
* !! Unable to test it due to external request
|
|
1508
|
-
*/
|
|
1509
|
-
// it('delete-namespace', (done) => {
|
|
1570
|
+
if (err) { console.log("error: ", err) };
|
|
1571
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1510
1572
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1573
|
+
res.should.have.status(200);
|
|
1574
|
+
res.body.should.be.a('array');
|
|
1513
1575
|
|
|
1514
|
-
|
|
1515
|
-
// .post('/v1/namespaces/delete')
|
|
1516
|
-
// .reply(200, { success: true });
|
|
1576
|
+
let namespace_id = res.body[0].id;
|
|
1517
1577
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1578
|
+
let kb = {
|
|
1579
|
+
name: "example_name6",
|
|
1580
|
+
type: "url",
|
|
1581
|
+
source: "https://www.exampleurl6.com",
|
|
1582
|
+
content: "",
|
|
1583
|
+
namespace: namespace_id
|
|
1584
|
+
}
|
|
1520
1585
|
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1586
|
+
chai.request(server)
|
|
1587
|
+
.post('/' + savedProject._id + '/kb/')
|
|
1588
|
+
.auth(email, pwd)
|
|
1589
|
+
.send(kb)
|
|
1590
|
+
.end((err, res) => {
|
|
1526
1591
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1592
|
+
if (err) { console.log("error: ", err) };
|
|
1593
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1529
1594
|
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
// expect(res.body.length).to.equal(1);
|
|
1533
|
-
// expect(res.body[0].namespace_id).to.equal(savedProject._id.toString());
|
|
1534
|
-
// expect(res.body[0].name).to.equal("Default");
|
|
1595
|
+
res.should.have.status(200);
|
|
1596
|
+
res.body.should.be.a('object');
|
|
1535
1597
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
// .post('/' + savedProject._id + '/kb/namespace')
|
|
1539
|
-
// .auth(email, pwd)
|
|
1540
|
-
// .send({ name: "MyCustomNamespace" })
|
|
1541
|
-
// .end((err, res) => {
|
|
1598
|
+
let realResponse = res.body.data;
|
|
1599
|
+
let kb_id = realResponse.value._id;
|
|
1542
1600
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1601
|
+
chai.request(server)
|
|
1602
|
+
.post('/webhook/kb/reindex')
|
|
1603
|
+
.set("x-auth-token", "testtoken")
|
|
1604
|
+
.send({ content_id: kb_id })
|
|
1605
|
+
.end((err, res) => {
|
|
1545
1606
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
// expect(res.body.name).to.equal('MyCustomNamespace');
|
|
1607
|
+
if (err) { console.error("err: ", err) };
|
|
1608
|
+
if (log) { console.log("res.body: ", res.body) };
|
|
1549
1609
|
|
|
1550
|
-
|
|
1551
|
-
|
|
1610
|
+
res.should.have.status(200);
|
|
1611
|
+
res.body.should.be.a('object');
|
|
1612
|
+
expect(res.body.success).to.equal(true);
|
|
1613
|
+
expect(res.body.message).to.equal("Content queued for reindexing");
|
|
1552
1614
|
|
|
1553
|
-
|
|
1554
|
-
// chai.request(server)
|
|
1555
|
-
// .get('/' + savedProject._id + '/kb/namespace/all')
|
|
1556
|
-
// .auth(email, pwd)
|
|
1557
|
-
// .end((err, res) => {
|
|
1615
|
+
done();
|
|
1558
1616
|
|
|
1559
|
-
|
|
1560
|
-
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
|
1617
|
+
})
|
|
1561
1618
|
|
|
1562
|
-
// res.should.have.status(200);
|
|
1563
|
-
// res.body.should.be.a('array');
|
|
1564
|
-
// expect(res.body.length).to.equal(2);
|
|
1565
1619
|
|
|
1566
|
-
|
|
1620
|
+
})
|
|
1621
|
+
})
|
|
1567
1622
|
|
|
1568
|
-
// chai.request(server)
|
|
1569
|
-
// .delete('/' + savedProject._id + '/kb/namespace/' + namespace_to_delete)
|
|
1570
|
-
// .auth(email, pwd)
|
|
1571
|
-
// .end((err, res) => {
|
|
1572
1623
|
|
|
1573
|
-
// if (err) { console.error("err: ", err); }
|
|
1574
|
-
// if (log) { console.log("delete namespaces res.body: ", res.body); }
|
|
1575
1624
|
|
|
1576
|
-
// res.should.have.status(200);
|
|
1577
1625
|
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
// })
|
|
1582
|
-
// })
|
|
1583
|
-
// });
|
|
1584
|
-
// });
|
|
1585
|
-
// })
|
|
1626
|
+
});
|
|
1627
|
+
});
|
|
1628
|
+
}).timeout(10000)
|
|
1586
1629
|
|
|
1587
1630
|
})
|
|
1588
1631
|
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
|
|
1589
1635
|
describe('Unanswered Questions', () => {
|
|
1590
1636
|
|
|
1591
1637
|
it('add-unanswered-question', (done) => {
|