Skip to content

Commit ef744c0

Browse files
committedOct 1, 2024··
test(collectioncontroller): add reindexCollection test for collection:update
1 parent 3cbc2b5 commit ef744c0

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Kuzzle, WebSocket } from "kuzzle-sdk";
2+
3+
const kuzzle = new Kuzzle(new WebSocket("localhost"));
4+
const index = "nyc-open-data";
5+
const collection = "green-taxi";
6+
const mappings = {
7+
dynamic: "false" as const,
8+
properties: {
9+
name: {
10+
type: "keyword",
11+
},
12+
},
13+
};
14+
15+
beforeAll(async () => {
16+
await kuzzle.connect();
17+
if (await kuzzle.index.exists(index)) {
18+
await kuzzle.index.delete(index);
19+
}
20+
21+
await kuzzle.index.create(index);
22+
await kuzzle.collection.create(index, collection, {
23+
mappings,
24+
});
25+
});
26+
27+
afterAll(async () => {
28+
await kuzzle.index.delete(index);
29+
kuzzle.disconnect();
30+
});
31+
32+
describe("collection:update", () => {
33+
it("should reindex the collection if asked to", async () => {
34+
await kuzzle.document.create(
35+
index,
36+
collection,
37+
{ age: 42, name: "Bob" },
38+
"document-1",
39+
{ refresh: "wait_for" },
40+
);
41+
42+
let result = await kuzzle.document.search(index, collection, {
43+
query: {
44+
range: {
45+
age: {
46+
gte: 40,
47+
},
48+
},
49+
},
50+
});
51+
52+
expect(result.hits.length).toEqual(0);
53+
54+
await kuzzle.collection.update(index, collection, {
55+
mappings: { properties: { age: { type: "long" } } },
56+
reindexCollection: true,
57+
});
58+
59+
// Wait for the reindexing to complete
60+
await new Promise((r) => setTimeout(r, 2000));
61+
62+
result = await kuzzle.document.search(index, collection, {
63+
query: {
64+
range: {
65+
age: {
66+
gte: 40,
67+
},
68+
},
69+
},
70+
});
71+
72+
expect(result.hits.length).toEqual(1);
73+
});
74+
});

‎package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"koncorde": "4.3.0",
4747
"kuzzle-plugin-auth-passport-local": "6.4.1",
4848
"kuzzle-plugin-logger": "3.0.3",
49-
"kuzzle-sdk": "^7.11.3",
49+
"kuzzle-sdk": "^7.13.0",
5050
"kuzzle-vault": "2.0.4",
5151
"lodash": "4.17.21",
5252
"long": "5.2.3",

0 commit comments

Comments
 (0)
Please sign in to comment.