UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

103 lines 6.26 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 chaiAsPromised = require("chai-as-promised"); const chai_1 = require("chai"); require("reflect-metadata"); const GlobalSetup_1 = require("../utils/GlobalSetup"); const CommonTestUtils_1 = require("../utils/imodels-client-test-utils/CommonTestUtils"); const Extraction_1 = require("../../grouping-and-mapping/interfaces/Extraction"); (0, chai_1.use)(chaiAsPromised); describe("OData Client", () => { let reportId; let oDataItem; let mappingId; before(async () => { const newMapping = { mappingName: "TestM", iModelId: GlobalSetup_1.testIModel.id, extractionEnabled: true, }; const mapping = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, newMapping); mappingId = mapping.id; const newGroup = { groupName: "TestG", query: "select * from biscore.element limit 10", }; await GlobalSetup_1.groupsClient.createGroup(GlobalSetup_1.accessToken, mapping.id, newGroup); const newReport = { displayName: "TestR", projectId: GlobalSetup_1.iTwinId, }; const report = await GlobalSetup_1.reportsClient.createReport(GlobalSetup_1.accessToken, newReport); reportId = report.id; const newReportMapping = { mappingId: mapping.id, imodelId: GlobalSetup_1.testIModel.id, }; await GlobalSetup_1.reportsClient.createReportMapping(GlobalSetup_1.accessToken, report.id, newReportMapping); const extractionRequestDetails = { iModelId: GlobalSetup_1.testIModel.id, mappings: [ { id: mappingId }, ], }; const extraction = await GlobalSetup_1.extractionClient.runExtraction(GlobalSetup_1.accessToken, extractionRequestDetails); let state = Extraction_1.ExtractionState.Queued; let status; for (const start = performance.now(); performance.now() - start < 6 * 60 * 1000; await (0, CommonTestUtils_1.sleep)(3000)) { status = await GlobalSetup_1.extractionClient.getExtractionStatus(GlobalSetup_1.accessToken, extraction.id); state = status.state; // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison if (state !== Extraction_1.ExtractionState.Queued && state.valueOf() !== Extraction_1.ExtractionState.Running) break; } (0, chai_1.expect)(state).to.be.eq(Extraction_1.ExtractionState.Succeeded); const oDataResponse = await GlobalSetup_1.oDataClient.getODataReport(GlobalSetup_1.accessToken, reportId); oDataItem = oDataResponse.value[0]; }); after(async () => { await GlobalSetup_1.mappingsClient.deleteMapping(GlobalSetup_1.accessToken, mappingId); await GlobalSetup_1.reportsClient.deleteReport(GlobalSetup_1.accessToken, reportId); }); it("get OData report", async () => { const oDataResponse = await GlobalSetup_1.oDataClient.getODataReport(GlobalSetup_1.accessToken, reportId); (0, chai_1.expect)(oDataResponse).to.not.be.undefined; (0, chai_1.expect)(oDataResponse["@odata.context"]).to.not.be.empty; }); it("get OData report metadata", async () => { const oDataResponse = await GlobalSetup_1.oDataClient.getODataReportMetadata(GlobalSetup_1.accessToken, reportId); (0, chai_1.expect)(oDataResponse).to.not.be.undefined; (0, chai_1.expect)(oDataResponse).to.not.be.empty; (0, chai_1.expect)(oDataResponse[0].name).to.be.a("string").and.satisfy((msg) => msg.startsWith("TestM_TestG")); (0, chai_1.expect)(["ECInstanceId", "ECClassId", "UserLabel", "BBoxLow", "BBoxHigh"]).to.include(oDataResponse[0].columns[0].name); (0, chai_1.expect)(["ECInstanceId", "ECClassId", "UserLabel", "BBoxLow", "BBoxHigh"]).to.include(oDataResponse[0].columns[1].name); (0, chai_1.expect)(["ECInstanceId", "ECClassId", "UserLabel", "BBoxLow", "BBoxHigh"]).to.include(oDataResponse[0].columns[2].name); (0, chai_1.expect)(["ECInstanceId", "ECClassId", "UserLabel", "BBoxLow", "BBoxHigh"]).to.include(oDataResponse[0].columns[3].name); (0, chai_1.expect)(["ECInstanceId", "ECClassId", "UserLabel", "BBoxLow", "BBoxHigh"]).to.include(oDataResponse[0].columns[4].name); (0, chai_1.expect)(oDataResponse[0].columns[0].type).to.be.eq("Edm.String"); (0, chai_1.expect)(oDataResponse[0].columns[1].type).to.be.eq("Edm.String"); (0, chai_1.expect)(oDataResponse[0].columns[2].type).to.be.eq("Edm.String"); (0, chai_1.expect)(oDataResponse[0].columns[3].type).to.be.eq("Edm.String"); (0, chai_1.expect)(oDataResponse[0].columns[4].type).to.be.eq("Edm.String"); (0, chai_1.expect)(oDataResponse[0].annotations[0].term).to.be.eq("Bentley.iTwin.Reporting.DisplayName"); (0, chai_1.expect)(oDataResponse[0].annotations[0].stringValue).to.be.eq("TestG"); }); it("throw OData report metadata", async () => { await (0, chai_1.expect)(GlobalSetup_1.oDataClient.getODataReportMetadata(GlobalSetup_1.accessToken, "-")).to.be.rejected; }); it("get OData report entity", async () => { const oDataEntity = await GlobalSetup_1.oDataClient.getODataReportEntities(GlobalSetup_1.accessToken, reportId, oDataItem); (0, chai_1.expect)(oDataEntity).to.not.be.undefined; (0, chai_1.expect)(oDataEntity).to.not.be.empty; }); it("get OData report entity page", async () => { const oDataEntity = await GlobalSetup_1.oDataClient.getODataReportEntityPage(GlobalSetup_1.accessToken, reportId, oDataItem, 0); (0, chai_1.expect)(oDataEntity).to.not.be.undefined; (0, chai_1.expect)(oDataEntity).to.not.be.empty; }); }); //# sourceMappingURL=ODataClient.test.js.map