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 349996e
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions jest/api/controller/collection/update.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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",
);

await kuzzle.collection.refresh(index, collection);

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,
// });
await kuzzle.query({
action: "update",
body: {
mappings: { properties: { age: { type: "long" } } },
reindexCollection: true,
},
collection,
controller: "collection",
index,
});

await kuzzle.collection.refresh(index, collection);

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

expect(result.hits.length).toEqual(1);
});
});

0 comments on commit 349996e

Please sign in to comment.