-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): adds test for engine deletion
- Loading branch information
1 parent
9d68644
commit 1aa6b54
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |