@itwin/insights-client
Version:
Insights client for the iTwin platform
121 lines • 6.74 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const chai_1 = require("chai");
const GlobalSetup_1 = require("../../utils/GlobalSetup");
const Common_1 = require("../../../common/Common");
describe("NamedGroups Client", () => {
let groupOne;
let groupTwo;
let groupThree;
before(async () => {
// Cleanup all of the groups, so we have a clean iTwin.
await cleanup();
groupOne = await GlobalSetup_1.namedGroupsClient.createNamedGroup(GlobalSetup_1.accessToken, {
iTwinId: GlobalSetup_1.iTwinId,
displayName: "GroupOne 🚀",
description: "Group number one",
query: "SELECT * FROM bis.Element limit 1",
metadata: [{ key: "key1", value: "value1" }, { key: "key2", value: "value2" }],
});
groupTwo = await GlobalSetup_1.namedGroupsClient.createNamedGroup(GlobalSetup_1.accessToken, {
iTwinId: GlobalSetup_1.iTwinId,
displayName: "GroupTwo 👻",
description: "Group number two",
query: "SELECT * FROM bis.Element limit 2",
metadata: [{ key: "key1", value: "value1" }, { key: "noValue" }],
});
groupThree = await GlobalSetup_1.namedGroupsClient.createNamedGroup(GlobalSetup_1.accessToken, {
iTwinId: GlobalSetup_1.iTwinId,
displayName: "GroupThree",
description: "Group number three",
query: "SELECT * FROM bis.Element limit 3",
metadata: [{ key: "key1", value: "value1" }, { key: "nullValue", value: null }],
});
});
after(async () => {
await cleanup();
});
const cleanup = async () => {
const groups = await GlobalSetup_1.namedGroupsClient.getNamedGroups(GlobalSetup_1.accessToken, GlobalSetup_1.iTwinId, Common_1.PreferReturn.Minimal);
for (const group of groups.groups) {
await GlobalSetup_1.namedGroupsClient.deleteNamedGroup(GlobalSetup_1.accessToken, group.id);
}
};
it("NamedGroups - Get group", async () => {
const getGroupTwo = await GlobalSetup_1.namedGroupsClient.getNamedGroup(GlobalSetup_1.accessToken, groupTwo.id);
const getGroupThree = await GlobalSetup_1.namedGroupsClient.getNamedGroup(GlobalSetup_1.accessToken, groupThree.id);
(0, chai_1.expect)(getGroupTwo.displayName).to.equal(groupTwo.displayName);
(0, chai_1.expect)(getGroupThree.displayName).to.equal(groupThree.displayName);
});
it("NamedGroups - Get all groups", async () => {
const groups = await GlobalSetup_1.namedGroupsClient.getNamedGroups(GlobalSetup_1.accessToken, GlobalSetup_1.iTwinId);
for (const group of groups.groups) {
(0, chai_1.expect)(["GroupOne 🚀", "GroupTwo 👻", "GroupThree"]).to.include(group.displayName);
}
});
it("NamedGroups - Get top minimal groups", async () => {
const topGroups = await GlobalSetup_1.namedGroupsClient.getNamedGroups(GlobalSetup_1.accessToken, GlobalSetup_1.iTwinId, Common_1.PreferReturn.Minimal, 2);
(0, chai_1.expect)(topGroups.groups.length).to.equal(2);
topGroups.groups.forEach((group) => {
(0, chai_1.expect)("metadata" in group).to.be.false;
});
});
it("NamedGroups - Get top representation groups", async () => {
const topGroups = await GlobalSetup_1.namedGroupsClient.getNamedGroups(GlobalSetup_1.accessToken, GlobalSetup_1.iTwinId, Common_1.PreferReturn.Representation, 2);
(0, chai_1.expect)(topGroups.groups.length).to.equal(2);
topGroups.groups.forEach((group) => {
(0, chai_1.expect)(group).to.have.property("metadata");
});
});
it("NamedGroups - Get pages of minimal groups", async () => {
const groupsIterator = GlobalSetup_1.namedGroupsClient.getNamedGroupsIterator(GlobalSetup_1.accessToken, GlobalSetup_1.iTwinId, Common_1.PreferReturn.Minimal, 2);
let flag = false;
for await (const groupsPage of groupsIterator.byPage()) {
flag = true;
for (const group of groupsPage) {
(0, chai_1.expect)(["GroupOne 🚀", "GroupTwo 👻", "GroupThree"]).to.include(group.displayName);
(0, chai_1.expect)("metadata" in group).to.be.false;
}
}
(0, chai_1.expect)(flag).to.be.true;
});
it("NamedGroups - Get pages of representation groups", async () => {
const groupsIterator = GlobalSetup_1.namedGroupsClient.getNamedGroupsIterator(GlobalSetup_1.accessToken, GlobalSetup_1.iTwinId, Common_1.PreferReturn.Representation, 2);
let flag = false;
for await (const groupsPage of groupsIterator.byPage()) {
flag = true;
for (const group of groupsPage) {
(0, chai_1.expect)(["GroupOne 🚀", "GroupTwo 👻", "GroupThree"]).to.include(group.displayName);
(0, chai_1.expect)(group).to.have.property("metadata");
}
}
(0, chai_1.expect)(flag).to.be.true;
});
it("NamedGroups - Create and Delete", async () => {
const group = await GlobalSetup_1.namedGroupsClient.createNamedGroup(GlobalSetup_1.accessToken, {
iTwinId: GlobalSetup_1.iTwinId,
displayName: "GroupToDelete",
query: "select * from biscore.element limit 10",
});
(0, chai_1.expect)(group).not.be.undefined;
(0, chai_1.expect)(group.displayName).to.equal("GroupToDelete");
const response = await GlobalSetup_1.namedGroupsClient.deleteNamedGroup(GlobalSetup_1.accessToken, group.id);
(0, chai_1.expect)(response).not.be.undefined;
(0, chai_1.expect)(response.status).to.be.equal(204);
});
it("NamedGroups - Update", async () => {
const updatedGroupOne = {
displayName: "UpdatedGroupOne",
description: "Updated description for group one",
};
const updatedGroup = await GlobalSetup_1.namedGroupsClient.updateNamedGroup(GlobalSetup_1.accessToken, groupOne.id, updatedGroupOne);
(0, chai_1.expect)(updatedGroup.displayName).not.be.undefined;
(0, chai_1.expect)(updatedGroup.displayName).to.equal(updatedGroupOne.displayName);
(0, chai_1.expect)(updatedGroup.description).to.equal(updatedGroupOne.description);
});
});
//# sourceMappingURL=NamedGroupsClient.test.js.map