Skip to content

Commit

Permalink
test(collectioncontroller): add reindexCollection test for collection…
Browse files Browse the repository at this point in the history
…:update
  • Loading branch information
fmauNeko committed Oct 1, 2024
1 parent 3cbc2b5 commit ef744c0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
74 changes: 74 additions & 0 deletions jest/api/controller/collection/update.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Kuzzle, WebSocket } from "kuzzle-sdk";

const kuzzle = new Kuzzle(new WebSocket("localhost"));
const index = "nyc-open-data";
const collection = "green-taxi";
const mappings = {
dynamic: "false" as const,
properties: {
name: {
type: "keyword",
},
},
};

beforeAll(async () => {
await kuzzle.connect();
if (await kuzzle.index.exists(index)) {
await kuzzle.index.delete(index);
}

await kuzzle.index.create(index);
await kuzzle.collection.create(index, collection, {
mappings,
});
});

afterAll(async () => {
await kuzzle.index.delete(index);
kuzzle.disconnect();
});

describe("collection:update", () => {
it("should reindex the collection if asked to", async () => {
await kuzzle.document.create(
index,
collection,
{ age: 42, name: "Bob" },
"document-1",
{ refresh: "wait_for" },
);

let result = await kuzzle.document.search(index, collection, {
query: {
range: {
age: {
gte: 40,
},
},
},
});

expect(result.hits.length).toEqual(0);

await kuzzle.collection.update(index, collection, {
mappings: { properties: { age: { type: "long" } } },
reindexCollection: true,
});

// Wait for the reindexing to complete
await new Promise((r) => setTimeout(r, 2000));

result = await kuzzle.document.search(index, collection, {
query: {
range: {
age: {
gte: 40,
},
},
},
});

expect(result.hits.length).toEqual(1);
});
});
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"koncorde": "4.3.0",
"kuzzle-plugin-auth-passport-local": "6.4.1",
"kuzzle-plugin-logger": "3.0.3",
"kuzzle-sdk": "^7.11.3",
"kuzzle-sdk": "^7.13.0",
"kuzzle-vault": "2.0.4",
"lodash": "4.17.21",
"long": "5.2.3",
Expand Down

0 comments on commit ef744c0

Please sign in to comment.