UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

100 lines 5.33 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"); describe("Mappings Client", () => { let mappingIds = []; before(async () => { // Create mappings for testing const mappingZero = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, { iModelId: GlobalSetup_1.testIModel.id, mappingName: "mappingZero", description: "Mapping created for testing", extractionEnabled: true, }); mappingIds.push(mappingZero.id); const mappingOne = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, { iModelId: GlobalSetup_1.testIModel.id, mappingName: "mappingOne", }); mappingIds.push(mappingOne.id); const mappingTwo = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, { iModelId: GlobalSetup_1.testIModel.id, mappingName: "mappingTwo", }); mappingIds.push(mappingTwo.id); }); after(async () => { for (const id of mappingIds) { await GlobalSetup_1.mappingsClient.deleteMapping(GlobalSetup_1.accessToken, id); } mappingIds = []; }); it("Mappings - Get mappings with iterator", async () => { const mappingsIt = GlobalSetup_1.mappingsClient.getMappingsIterator(GlobalSetup_1.accessToken, GlobalSetup_1.testIModel.id, 2); let flag = false; for await (const mapping of mappingsIt) { flag = true; (0, chai_1.expect)(mapping).to.not.be.undefined; (0, chai_1.expect)(["mappingZero", "mappingOne", "mappingTwo"]).to.include(mapping.mappingName); } (0, chai_1.expect)(flag).to.be.true; }); it("Mappings - Get all mappings", async () => { const mappings = (await GlobalSetup_1.mappingsClient.getMappings(GlobalSetup_1.accessToken, GlobalSetup_1.testIModel.id)); (0, chai_1.expect)(mappings).to.not.be.undefined; for (const mapping of mappings.mappings) { (0, chai_1.expect)(["mappingZero", "mappingOne", "mappingTwo"]).to.include(mapping.mappingName); } }); it("Mappings - Get top mappings", async () => { const mappings = (await GlobalSetup_1.mappingsClient.getMappings(GlobalSetup_1.accessToken, GlobalSetup_1.testIModel.id, 2)); (0, chai_1.expect)(mappings.mappings.length).to.be.equal(2); }); it("Mappings - Get mapping", async () => { const retrievedMapping = await GlobalSetup_1.mappingsClient.getMapping(GlobalSetup_1.accessToken, mappingIds[1]); (0, chai_1.expect)(retrievedMapping.id).to.deep.equal(mappingIds[1]); (0, chai_1.expect)(retrievedMapping.mappingName).to.deep.equal("mappingOne"); }); it("Mappings - Create and Delete", async () => { const newMapping = { iModelId: GlobalSetup_1.testIModel.id, mappingName: "MappingToDelete", }; const mapping = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, newMapping); (0, chai_1.expect)(mapping).not.be.undefined; (0, chai_1.expect)(mapping.mappingName).to.deep.equal("MappingToDelete"); const response = await GlobalSetup_1.mappingsClient.deleteMapping(GlobalSetup_1.accessToken, mapping.id); (0, chai_1.expect)(response.status).to.be.eq(204); }); it("Mappings - Create from a source mapping", async () => { const mappingCopy = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, { iModelId: GlobalSetup_1.testIModel.id, mappingName: "MappingCopy", sourceMappingId: mappingIds[0], }); mappingIds.push(mappingCopy.id); (0, chai_1.expect)(mappingCopy.mappingName).to.deep.equal("MappingCopy"); (0, chai_1.expect)(mappingCopy.description).to.deep.equal("Mapping created for testing"); }); it("Mappings - Update mapping", async () => { const mappingUpdate = { mappingName: "UpdatedMapping", description: "Updated mapping test", extractionEnabled: true, }; const updatedMapping = await GlobalSetup_1.mappingsClient.updateMapping(GlobalSetup_1.accessToken, mappingIds[2], mappingUpdate); (0, chai_1.expect)(updatedMapping.id).to.deep.equal(mappingIds[2]); (0, chai_1.expect)(updatedMapping.mappingName).to.deep.equal("UpdatedMapping"); (0, chai_1.expect)(updatedMapping.description).to.deep.equal("Updated mapping test"); }); it("Mappings - Get mapping extractions", async () => { const extractions = await GlobalSetup_1.mappingsClient.getMappingExtractions(GlobalSetup_1.accessToken, mappingIds[0], 2); (0, chai_1.expect)(extractions).not.be.undefined; }); }); //# sourceMappingURL=MappingsClient.test.js.map