@itwin/insights-client
Version:
Insights client for the iTwin platform
270 lines • 15.2 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 chaiAsPromised = require("chai-as-promised");
const chai_1 = require("chai");
require("reflect-metadata");
const GlobalSetup_1 = require("../utils/GlobalSetup");
(0, chai_1.use)(chaiAsPromised);
describe("Aggregations Client", () => {
let mappingId;
let tablesetId;
let tableId;
let propertyId;
let groupname;
before(async () => {
// create mappings for tests
const newMapping = {
mappingName: "Test1",
iModelId: GlobalSetup_1.testIModel.id,
};
const mapping = await GlobalSetup_1.mappingsClient.createMapping(GlobalSetup_1.accessToken, newMapping);
mappingId = mapping.id;
const newGroup = {
groupName: "Test1",
query: "select * from biscore.element limit 10",
};
const group = await GlobalSetup_1.groupsClient.createGroup(GlobalSetup_1.accessToken, mappingId, newGroup);
groupname = group.groupName;
// create table sets for tests
const newAggregationTableSet = {
tableSetName: "TableSet1",
description: "AggregationTableSet for a mapping",
datasourceId: mappingId,
datasourceType: "IModelMapping",
};
let tableSet = await GlobalSetup_1.aggregationsClient.createAggregationTableSet(GlobalSetup_1.accessToken, newAggregationTableSet);
tablesetId = tableSet.id;
newAggregationTableSet.tableSetName = "TableSet2";
tableSet = await GlobalSetup_1.aggregationsClient.createAggregationTableSet(GlobalSetup_1.accessToken, newAggregationTableSet);
newAggregationTableSet.tableSetName = "TableSet3";
tableSet = await GlobalSetup_1.aggregationsClient.createAggregationTableSet(GlobalSetup_1.accessToken, newAggregationTableSet);
// create tables for tests
const newAggregationTable = {
tableName: "Table1",
description: "Aggregation of Group table.",
sourceTableName: groupname,
};
let table = await GlobalSetup_1.aggregationsClient.createAggregationTable(GlobalSetup_1.accessToken, tablesetId, newAggregationTable);
tableId = table.id;
newAggregationTable.tableName = "Table2";
table = await GlobalSetup_1.aggregationsClient.createAggregationTable(GlobalSetup_1.accessToken, tablesetId, newAggregationTable);
newAggregationTable.tableName = "Table3";
table = await GlobalSetup_1.aggregationsClient.createAggregationTable(GlobalSetup_1.accessToken, tablesetId, newAggregationTable);
// create properties for tests
const newAggregationProperty = {
propertyName: "Test",
sourcePropertyName: "ECClassId",
type: "Count",
};
let property = await GlobalSetup_1.aggregationsClient.createAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, newAggregationProperty);
propertyId = property.id;
newAggregationProperty.propertyName = "Property2";
property = await GlobalSetup_1.aggregationsClient.createAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, newAggregationProperty);
newAggregationProperty.propertyName = "Property3";
property = await GlobalSetup_1.aggregationsClient.createAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, newAggregationProperty);
});
after(async () => {
await GlobalSetup_1.mappingsClient.deleteMapping(GlobalSetup_1.accessToken, mappingId);
});
// aggregation table sets tests
it("Aggregation Table Sets - Create and delete", async () => {
const newAggregationTableSet = {
tableSetName: "TableSet4",
description: "AggregationTableSet for a mapping",
datasourceId: mappingId,
datasourceType: "IModelMapping",
};
const aggregationTableSet = await GlobalSetup_1.aggregationsClient.createAggregationTableSet(GlobalSetup_1.accessToken, newAggregationTableSet);
(0, chai_1.expect)(aggregationTableSet).to.not.be.undefined;
(0, chai_1.expect)(aggregationTableSet.tableSetName).to.be.eq("TableSet4");
const response = await GlobalSetup_1.aggregationsClient.deleteAggregationTableSet(GlobalSetup_1.accessToken, aggregationTableSet.id);
(0, chai_1.expect)(response.status).to.be.eq(204);
});
it("Aggregation Table Sets - Get", async () => {
const aggregationTableSet = await GlobalSetup_1.aggregationsClient.getAggregationTableSet(GlobalSetup_1.accessToken, tablesetId);
(0, chai_1.expect)(aggregationTableSet).to.not.be.undefined;
(0, chai_1.expect)(aggregationTableSet.tableSetName).to.be.eq("TableSet1");
});
it("Aggregation Table Sets - Update", async () => {
const newAggregationTableSet = {
description: "Updated",
};
const aggregationTableSet = await GlobalSetup_1.aggregationsClient.updateAggregationTableSet(GlobalSetup_1.accessToken, tablesetId, newAggregationTableSet);
(0, chai_1.expect)(aggregationTableSet).to.not.be.undefined;
(0, chai_1.expect)(aggregationTableSet.description).to.be.eq("Updated");
});
it("Aggregation Table Sets - Get all", async () => {
const aggregationTableSets = await GlobalSetup_1.aggregationsClient.getAggregationTableSets(GlobalSetup_1.accessToken, mappingId, "IModelMapping");
(0, chai_1.expect)(aggregationTableSets).to.not.be.undefined;
(0, chai_1.expect)(aggregationTableSets.length).to.be.above(2);
for (const tableset of aggregationTableSets) {
(0, chai_1.expect)(["TableSet1", "TableSet2", "TableSet3"]).to.include(tableset.tableSetName);
}
});
it("Aggregation Table Sets - Get with iterator", async () => {
const aggregationTableSetsIt = GlobalSetup_1.aggregationsClient.getAggregationTableSetsIterator(GlobalSetup_1.accessToken, mappingId, "IModelMapping", 2);
let flag = false;
for await (const tableset of aggregationTableSetsIt) {
flag = true;
(0, chai_1.expect)(tableset).to.not.be.undefined;
(0, chai_1.expect)(["TableSet1", "TableSet2", "TableSet3"]).to.include(tableset.tableSetName);
}
(0, chai_1.expect)(flag).to.be.true;
});
it("Aggregation Table Sets - Get pages", async () => {
const aggregationTableSetsIt = GlobalSetup_1.aggregationsClient.getAggregationTableSetsIterator(GlobalSetup_1.accessToken, mappingId, "IModelMapping", 2);
let elementCount = 0;
let flag = false;
for await (const tablesets of aggregationTableSetsIt.byPage()) {
flag = true;
(0, chai_1.expect)(tablesets).to.not.be.undefined;
if (tablesets.length) {
for (const tableset of tablesets) {
(0, chai_1.expect)(["TableSet1", "TableSet2", "TableSet3"]).to.include(tableset.tableSetName);
}
elementCount += tablesets.length;
}
}
(0, chai_1.expect)(flag).to.be.true;
(0, chai_1.expect)(elementCount).to.not.be.eq(0);
});
// aggregation tables tests
it("Aggregation Tables - Create and delete", async () => {
const newGroup = {
groupName: "Test1",
query: "select * from biscore.element limit 10",
};
const group = await GlobalSetup_1.groupsClient.createGroup(GlobalSetup_1.accessToken, mappingId, newGroup);
const newAggregationTableSet = {
tableSetName: "TableSet1",
description: "AggregationTableSet for a mapping",
datasourceId: mappingId,
datasourceType: "IModelMapping",
};
const tableSet = await GlobalSetup_1.aggregationsClient.createAggregationTableSet(GlobalSetup_1.accessToken, newAggregationTableSet);
const newAggregationTable = {
tableName: "Table5",
description: "Aggregation of Group table.",
sourceTableName: group.groupName,
};
const table = await GlobalSetup_1.aggregationsClient.createAggregationTable(GlobalSetup_1.accessToken, tableSet.id, newAggregationTable);
(0, chai_1.expect)(table).to.not.be.undefined;
(0, chai_1.expect)(table.tableName).to.be.eq("Table5");
const response = await GlobalSetup_1.aggregationsClient.deleteAggregationTable(GlobalSetup_1.accessToken, tableSet.id, table.id);
(0, chai_1.expect)(response.status).to.be.eq(204);
});
it("Aggregation Tables - Get", async () => {
const aggregationTable = await GlobalSetup_1.aggregationsClient.getAggregationTable(GlobalSetup_1.accessToken, tablesetId, tableId);
(0, chai_1.expect)(aggregationTable).to.not.be.undefined;
(0, chai_1.expect)(aggregationTable.tableName).to.be.eq("Table1");
});
it("Aggregation Tables - Update", async () => {
const newAggregationTable = {
description: "Updated",
};
const aggregationTable = await GlobalSetup_1.aggregationsClient.updateAggregationTable(GlobalSetup_1.accessToken, tablesetId, tableId, newAggregationTable);
(0, chai_1.expect)(aggregationTable).to.not.be.undefined;
(0, chai_1.expect)(aggregationTable.description).to.be.eq("Updated");
});
it("Aggregation Tables - Get all", async () => {
const aggregationTables = await GlobalSetup_1.aggregationsClient.getAggregationTables(GlobalSetup_1.accessToken, tablesetId);
(0, chai_1.expect)(aggregationTables).to.not.be.undefined;
(0, chai_1.expect)(aggregationTables.length).to.be.above(2);
for (const table of aggregationTables) {
(0, chai_1.expect)(["Table1", "Table2", "Table3"]).to.include(table.tableName);
}
});
it("Aggregation Tables - Get with iterator", async () => {
const aggregationTablesIt = GlobalSetup_1.aggregationsClient.getAggregationTablesIterator(GlobalSetup_1.accessToken, tablesetId, 2);
let flag = false;
for await (const table of aggregationTablesIt) {
flag = true;
(0, chai_1.expect)(table).to.not.be.undefined;
(0, chai_1.expect)(["Table1", "Table2", "Table3"]).to.include(table.tableName);
}
(0, chai_1.expect)(flag).to.be.true;
});
it("Aggregation Tables - Get pages", async () => {
const aggregationTablesIt = GlobalSetup_1.aggregationsClient.getAggregationTablesIterator(GlobalSetup_1.accessToken, tablesetId, 2);
let elementCount = 0;
let flag = false;
for await (const tables of aggregationTablesIt.byPage()) {
flag = true;
(0, chai_1.expect)(tables).to.not.be.undefined;
if (tables.length) {
for (const table of tables) {
(0, chai_1.expect)(["Table1", "Table2", "Table3"]).to.include(table.tableName);
}
elementCount += tables.length;
}
}
(0, chai_1.expect)(flag).to.be.true;
(0, chai_1.expect)(elementCount).to.not.be.eq(0);
});
// aggregation properties tests
it("Aggregation Properties - Create and delete", async () => {
const newAggregationProperty = {
propertyName: "Property5",
sourcePropertyName: "ECClassId",
type: "Count",
};
const property = await GlobalSetup_1.aggregationsClient.createAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, newAggregationProperty);
(0, chai_1.expect)(property).to.not.be.undefined;
(0, chai_1.expect)(property.propertyName).to.be.eq("Property5");
const response = await GlobalSetup_1.aggregationsClient.deleteAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, property.id);
(0, chai_1.expect)(response.status).to.be.eq(204);
});
it("Aggregation Properties - Get", async () => {
const aggregationProperty = await GlobalSetup_1.aggregationsClient.getAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, propertyId);
(0, chai_1.expect)(aggregationProperty).to.not.be.undefined;
(0, chai_1.expect)(aggregationProperty.propertyName).to.be.eq("Test");
});
it("Aggregation Properties - Update", async () => {
const newAggregationProperty = {
propertyName: "Property1",
};
const aggregationProperty = await GlobalSetup_1.aggregationsClient.updateAggregationProperty(GlobalSetup_1.accessToken, tablesetId, tableId, propertyId, newAggregationProperty);
(0, chai_1.expect)(aggregationProperty).to.not.be.undefined;
(0, chai_1.expect)(aggregationProperty.propertyName).to.be.eq("Property1");
});
it("Aggregation Properties - Get all", async () => {
const aggregationProperties = await GlobalSetup_1.aggregationsClient.getAggregationProperties(GlobalSetup_1.accessToken, tablesetId, tableId);
(0, chai_1.expect)(aggregationProperties).to.not.be.undefined;
(0, chai_1.expect)(aggregationProperties.length).to.be.above(2);
for (const report of aggregationProperties) {
(0, chai_1.expect)(["Property1", "Property2", "Property3"]).to.include(report.propertyName);
}
});
it("Aggregation Properties - Get with iterator", async () => {
const aggregationPropertiesIt = GlobalSetup_1.aggregationsClient.getAggregationPropertiesIterator(GlobalSetup_1.accessToken, tablesetId, tableId, 2);
let flag = false;
for await (const property of aggregationPropertiesIt) {
flag = true;
(0, chai_1.expect)(property).to.not.be.undefined;
(0, chai_1.expect)(["Property1", "Property2", "Property3"]).to.include(property.propertyName);
}
(0, chai_1.expect)(flag).to.be.true;
});
it("Aggregation Properties - Get pages", async () => {
const aggregationPropertiesIt = GlobalSetup_1.aggregationsClient.getAggregationPropertiesIterator(GlobalSetup_1.accessToken, tablesetId, tableId, 2);
let elementCount = 0;
let flag = false;
for await (const properties of aggregationPropertiesIt.byPage()) {
flag = true;
(0, chai_1.expect)(properties).to.not.be.undefined;
if (properties.length) {
for (const property of properties) {
(0, chai_1.expect)(["Property1", "Property2", "Property3"]).to.include(property.propertyName);
}
elementCount += properties.length;
}
}
(0, chai_1.expect)(flag).to.be.true;
(0, chai_1.expect)(elementCount).to.not.be.eq(0);
});
});
//# sourceMappingURL=AggregationsClient.test.js.map