UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

117 lines 6.5 kB
"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("Groups Client", () => { let mappingForGroups; let groupOne; let groupTwo; let groupThree; before(async () => { // Create mappings for testing mappingForGroups = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, { iModelId: GlobalSetup_1.testIModel.id, mappingName: "MappingForGroups", description: "Mapping created for groups testing", extractionEnabled: true, }); groupOne = await GlobalSetup_1.groupsClient.createGroup(GlobalSetup_1.accessToken, mappingForGroups.id, { groupName: "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.groupsClient.createGroup(GlobalSetup_1.accessToken, mappingForGroups.id, { groupName: "GroupTwo", description: "Group number two", query: "SELECT * FROM bis.Element limit 2", metadata: [{ key: "key1", value: "value1" }, { key: "noValue" }], }); groupThree = await GlobalSetup_1.groupsClient.createGroup(GlobalSetup_1.accessToken, mappingForGroups.id, { groupName: "GroupThree", description: "Group number three", query: "SELECT * FROM bis.Element limit 3", metadata: [{ key: "key1", value: "value1" }, { key: "nullValue", value: null }], }); }); after(async () => { await GlobalSetup_1.mappingsClient.deleteMapping(GlobalSetup_1.accessToken, mappingForGroups.id); }); it("Groups - Get group", async () => { const getGroupTwo = await GlobalSetup_1.groupsClient.getGroup(GlobalSetup_1.accessToken, mappingForGroups.id, groupTwo.id); const getGroupThree = await GlobalSetup_1.groupsClient.getGroup(GlobalSetup_1.accessToken, mappingForGroups.id, groupThree.id); (0, chai_1.expect)(getGroupTwo.groupName).to.deep.equal(groupTwo.groupName); (0, chai_1.expect)(getGroupThree.groupName).to.deep.equal(groupThree.groupName); }); it("Groups - Get all groups", async () => { const groups = await GlobalSetup_1.groupsClient.getGroups(GlobalSetup_1.accessToken, mappingForGroups.id); for (const group of groups.groups) { (0, chai_1.expect)(["GroupOne", "GroupTwo", "GroupThree"]).to.include(group.groupName); } }); it("Groups - Get top minimal groups", async () => { const topGroups = await GlobalSetup_1.groupsClient.getGroups(GlobalSetup_1.accessToken, mappingForGroups.id, 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("Groups - Get top representation groups", async () => { const topGroups = await GlobalSetup_1.groupsClient.getGroups(GlobalSetup_1.accessToken, mappingForGroups.id, 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("Groups - Get pages of minimal groups", async () => { const groupsIterator = GlobalSetup_1.groupsClient.getGroupsIterator(GlobalSetup_1.accessToken, mappingForGroups.id, 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.groupName); (0, chai_1.expect)("metadata" in group).to.be.false; } } (0, chai_1.expect)(flag).to.be.true; }); it("Groups - Get pages of representation groups", async () => { const groupsIterator = GlobalSetup_1.groupsClient.getGroupsIterator(GlobalSetup_1.accessToken, mappingForGroups.id, 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.groupName); (0, chai_1.expect)(group).to.have.property("metadata"); } } (0, chai_1.expect)(flag).to.be.true; }); it("Groups - Create and Delete", async () => { const group = await GlobalSetup_1.groupsClient.createGroup(GlobalSetup_1.accessToken, mappingForGroups.id, { groupName: "GroupToDelete", query: "select * from biscore.element limit 10", }); (0, chai_1.expect)(group).not.be.undefined; (0, chai_1.expect)(group.groupName).to.deep.equal("GroupToDelete"); const response = await GlobalSetup_1.groupsClient.deleteGroup(GlobalSetup_1.accessToken, mappingForGroups.id, group.id); (0, chai_1.expect)(response).not.be.undefined; (0, chai_1.expect)(response.status).to.be.equal(204); }); it("Groups - Update", async () => { const updatedGroupOne = { groupName: "UpdatedGroupOne", description: "Updated description for group one", }; const updatedGroup = await GlobalSetup_1.groupsClient.updateGroup(GlobalSetup_1.accessToken, mappingForGroups.id, groupOne.id, updatedGroupOne); (0, chai_1.expect)(updatedGroup.groupName).not.be.undefined; (0, chai_1.expect)(updatedGroup.groupName).to.deep.equal(updatedGroupOne.groupName); (0, chai_1.expect)(updatedGroup.description).to.deep.equal(updatedGroupOne.description); }); }); //# sourceMappingURL=GroupsClient.test.js.map