-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
48 lines (42 loc) · 1.31 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { vectorizeDocument, vectorizeQuery, preprocess } = require("./index");
const timeout = 10000;
test(
"Should vectorize document",
async () => {
const vector1 = await vectorizeDocument("titre", "contenu");
expect(vector1).toBeDefined();
expect(vector1).toMatchSnapshot();
// preprocessing should make those embeddings equal
// FIXME Should return the same result but don't. See with remi and fabien.
// const vector2 = await vectorizeDocument("le titre", "et le contènu");
// expect(vector2).toEqual(vector1);
},
timeout
);
test(
"Should vectorize query",
async () => {
const vector1 = await vectorizeQuery("requete");
expect(vector1).toMatchSnapshot();
const vector2 = await vectorizeQuery("la requête");
expect(vector2).toEqual(vector1);
},
timeout
);
test(
"Should fail when no content passed",
async () => {
await expect(vectorizeQuery()).rejects.toThrow(
new Error("Cannot vectorize empty query.")
);
},
timeout
);
test("Should preprocess text", async () => {
expect(preprocess("à la nôtre")).toEqual("");
expect(preprocess("çode du tràvail")).toEqual("code travail");
// this one should be "aime code travail" when using better tokenization
expect(preprocess("j'aime le code du travail")).toEqual(
"j'aime code travail"
);
});