From 1aa6b54e6c5be754237351e217dd4ffd2201dee8 Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 18 Dec 2024 11:28:13 +0100 Subject: [PATCH] chore(test): adds test for engine deletion --- .../modules/engine/engine-deletion.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/scenario/modules/engine/engine-deletion.test.ts diff --git a/tests/scenario/modules/engine/engine-deletion.test.ts b/tests/scenario/modules/engine/engine-deletion.test.ts new file mode 100644 index 00000000..742c8cb3 --- /dev/null +++ b/tests/scenario/modules/engine/engine-deletion.test.ts @@ -0,0 +1,69 @@ +import { beforeAllCreateEngines } from "../../../hooks/engines"; +import { beforeEachLoadFixtures } from "../../../hooks/fixtures"; + +import { useSdk } from "../../../helpers"; + +jest.setTimeout(10000); + +describe("Engine deletion", () => { + const sdk = useSdk(); + + beforeAll(async () => { + await sdk.connect(); + await beforeAllCreateEngines(sdk); + }); + + beforeEach(async () => { + await beforeAllCreateEngines(sdk); + await beforeEachLoadFixtures(sdk); + }); + + afterAll(async () => { + sdk.disconnect(); + }); + const adminIndex = "device-manager"; + const engineId = "engine-ayse"; + + it("Deletes the engine from admin index", async () => { + const engine = await sdk.document.get( + adminIndex, + "config", + `engine-device-manager--${engineId}`, + ); + + expect(engine).toBeTruthy(); + + await sdk.query({ + controller: "device-manager/engine", + action: "delete", + index: engineId, + }); + + const promise = sdk.document.get( + adminIndex, + "config", + `engine-device-manager--${engineId}`, + ); + + await expect(promise).rejects.toThrow(); + }); + it("Detach devices from engine in the admin index on engine deletion", async () => { + const devices = await sdk.document.search(adminIndex, "devices", { + _source: false, + query: { bool: { must: { term: { engineId } } } }, + }); + expect(devices.total).toBeGreaterThan(0); + + await sdk.query({ + controller: "device-manager/engine", + action: "delete", + index: engineId, + }); + + const result = await sdk.document.search(adminIndex, "devices", { + _source: false, + query: { bool: { must: { term: { engineId } } } }, + }); + expect(result.total).toBe(0); + }); +});