UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

143 lines 7.9 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 Properties_1 = require("../../../grouping-and-mapping/interfaces/Properties"); describe("Properties Client", () => { let mappingOne; let groupOne; let propertyOne; let propertyTwo; let propertyThree; let propertyFour; before(async () => { mappingOne = 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, mappingOne.id, { groupName: "GroupOne", description: "Group number one", query: "SELECT * FROM bis.Element limit 10", }); propertyOne = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "propertyOne", dataType: Properties_1.DataType.Integer, }); propertyTwo = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "propertyTwo", dataType: Properties_1.DataType.String, }); propertyThree = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "propertyThree", dataType: Properties_1.DataType.Boolean, }); propertyFour = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "propertyFour", dataType: Properties_1.DataType.Double, }); }); after(async () => { await GlobalSetup_1.mappingsClient.deleteMapping(GlobalSetup_1.accessToken, mappingOne.id); }); it("Properties - Get property", async () => { const retrievedProperty = await GlobalSetup_1.propertiesClient.getProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, propertyOne.id); (0, chai_1.expect)(retrievedProperty.id).to.deep.equal(propertyOne.id); (0, chai_1.expect)(retrievedProperty.propertyName).to.deep.equal(propertyOne.propertyName); }); it("Properties - Get all properties", async () => { const properties = await GlobalSetup_1.propertiesClient.getProperties(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id); let flag = false; for (const property of properties.properties) { flag = true; (0, chai_1.expect)([ propertyOne.propertyName, propertyTwo.propertyName, propertyThree.propertyName, propertyFour.propertyName, ]).to.include(property.propertyName); } (0, chai_1.expect)(flag).to.be.true; }); it("Properties - Get top properties", async () => { const topProperties = await GlobalSetup_1.propertiesClient.getProperties(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, 3); (0, chai_1.expect)(topProperties.properties.length).to.be.equal(3); (0, chai_1.expect)(topProperties._links.next).not.be.undefined; }); it("Properties - Get pages of properties using iterator", async () => { const propertiesIterator = GlobalSetup_1.propertiesClient.getPropertiesIterator(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, 2); for await (const propertiesPage of propertiesIterator.byPage()) { (0, chai_1.expect)(propertiesPage.length).to.be.equal(2); for (const property of propertiesPage) { (0, chai_1.expect)([ propertyOne.propertyName, propertyTwo.propertyName, propertyThree.propertyName, propertyFour.propertyName, ]).to.include(property.propertyName); } } }); it("Properties - Create and Delete", async () => { const newProperty = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "newProperty", dataType: Properties_1.DataType.String, }); (0, chai_1.expect)(newProperty).not.be.undefined; (0, chai_1.expect)(newProperty.propertyName).to.deep.equal("newProperty"); const response = await GlobalSetup_1.propertiesClient.deleteProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, newProperty.id); (0, chai_1.expect)(response.status).to.be.deep.equal(204); }); it("Properties - Create property with all parameters in a single request", async () => { const calculatedProperty = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "BeamVolume", dataType: Properties_1.DataType.Double, quantityType: Properties_1.QuantityType.Volume, ecProperties: [{ ecSchemaName: "*", ecClassName: "*", ecPropertyName: "Volume", }], calculatedPropertyType: Properties_1.CalculatedPropertyType.Volume, }); (0, chai_1.expect)(calculatedProperty).not.be.undefined; (0, chai_1.expect)(calculatedProperty.propertyName).to.be.equal("BeamVolume"); (0, chai_1.expect)(calculatedProperty.calculatedPropertyType).to.be.equal(Properties_1.CalculatedPropertyType.Volume); }); it("Properties - Create a custom calculation property", async () => { const customCalculationProperty = await GlobalSetup_1.propertiesClient.createProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, { propertyName: "CustomPrice", dataType: Properties_1.DataType.Double, quantityType: Properties_1.QuantityType.Monetary, formula: "100 * 3.123", }); (0, chai_1.expect)(customCalculationProperty).not.be.undefined; (0, chai_1.expect)(customCalculationProperty.propertyName).to.be.equal("CustomPrice"); (0, chai_1.expect)(customCalculationProperty.formula).to.be.equal("100 * 3.123"); }); it("Properties - Update", async () => { const ecProperty = { ecClassName: "class", ecPropertyName: "property", ecSchemaName: "schema", }; const updatedProperty = await GlobalSetup_1.propertiesClient.updateProperty(GlobalSetup_1.accessToken, mappingOne.id, groupOne.id, propertyFour.id, { propertyName: "updatedPropertyFour", dataType: Properties_1.DataType.Integer, quantityType: Properties_1.QuantityType.Volume, ecProperties: [ecProperty], }); (0, chai_1.expect)(updatedProperty.id).to.not.be.undefined; (0, chai_1.expect)(updatedProperty.id).to.deep.equal(propertyFour.id); (0, chai_1.expect)(updatedProperty.dataType).to.deep.equal(Properties_1.DataType.Integer); (0, chai_1.expect)(updatedProperty.quantityType).to.deep.equal(Properties_1.QuantityType.Volume); (0, chai_1.expect)(updatedProperty.propertyName).to.deep.equal("updatedPropertyFour"); }); }); //# sourceMappingURL=PropertiesClient.test.js.map