From 349996ec5882e9b4f29582424a84e861b21081cf Mon Sep 17 00:00:00 2001 From: Florian Maunier Date: Tue, 1 Oct 2024 11:45:09 +0200 Subject: [PATCH] test(collectioncontroller): add reindexCollection test for collection:update --- jest/api/controller/collection/update.test.ts | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 jest/api/controller/collection/update.test.ts diff --git a/jest/api/controller/collection/update.test.ts b/jest/api/controller/collection/update.test.ts new file mode 100644 index 0000000000..f84aa7f096 --- /dev/null +++ b/jest/api/controller/collection/update.test.ts @@ -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); + }); +});