Skip to content

Commit

Permalink
chore(test): adds test for engine deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinRousselet committed Dec 18, 2024
1 parent 9d68644 commit 1aa6b54
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/scenario/modules/engine/engine-deletion.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 1aa6b54

Please sign in to comment.