@itwin/rpcinterface-full-stack-tests 3.8.0-dev.1 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/lib/backend/BackendInit.d.ts +1 -1
  2. package/lib/backend/BackendInit.js +28 -28
  3. package/lib/backend/BackendInit.js.map +1 -1
  4. package/lib/common/Settings.d.ts +51 -51
  5. package/lib/common/Settings.js +155 -155
  6. package/lib/common/Settings.js.map +1 -1
  7. package/lib/common/SideChannels.d.ts +5 -5
  8. package/lib/common/SideChannels.js +26 -26
  9. package/lib/common/SideChannels.js.map +1 -1
  10. package/lib/dist/bundled-tests.js +95776 -95776
  11. package/lib/dist/bundled-tests.js.map +1 -1
  12. package/lib/dist/core_frontend_lib_esm_ApproximateTerrainHeightsProps_js.bundled-tests.js +9 -9
  13. package/lib/frontend/CodeSpecs.test.d.ts +1 -1
  14. package/lib/frontend/CodeSpecs.test.js +46 -46
  15. package/lib/frontend/CodeSpecs.test.js.map +1 -1
  16. package/lib/frontend/DevToolsRpc.test.d.ts +1 -1
  17. package/lib/frontend/DevToolsRpc.test.js +49 -49
  18. package/lib/frontend/DevToolsRpc.test.js.map +1 -1
  19. package/lib/frontend/Elements.test.d.ts +1 -1
  20. package/lib/frontend/Elements.test.js +68 -68
  21. package/lib/frontend/Elements.test.js.map +1 -1
  22. package/lib/frontend/IModel.test.d.ts +1 -1
  23. package/lib/frontend/IModel.test.js +30 -30
  24. package/lib/frontend/IModel.test.js.map +1 -1
  25. package/lib/frontend/IModelConnection.test.d.ts +1 -1
  26. package/lib/frontend/IModelConnection.test.js +331 -331
  27. package/lib/frontend/IModelConnection.test.js.map +1 -1
  28. package/lib/frontend/Models.test.d.ts +1 -1
  29. package/lib/frontend/Models.test.js +29 -29
  30. package/lib/frontend/Models.test.js.map +1 -1
  31. package/lib/frontend/PresentationRpc.test.d.ts +1 -1
  32. package/lib/frontend/PresentationRpc.test.js +185 -185
  33. package/lib/frontend/PresentationRpc.test.js.map +1 -1
  34. package/lib/frontend/Views.test.d.ts +1 -1
  35. package/lib/frontend/Views.test.js +37 -37
  36. package/lib/frontend/Views.test.js.map +1 -1
  37. package/lib/frontend/setup/IModelSession.d.ts +14 -14
  38. package/lib/frontend/setup/IModelSession.js +100 -100
  39. package/lib/frontend/setup/IModelSession.js.map +1 -1
  40. package/lib/frontend/setup/TestContext.d.ts +17 -17
  41. package/lib/frontend/setup/TestContext.js +75 -75
  42. package/lib/frontend/setup/TestContext.js.map +1 -1
  43. package/lib/frontend/workflows/BasicScenarios.test.d.ts +1 -1
  44. package/lib/frontend/workflows/BasicScenarios.test.js +63 -63
  45. package/lib/frontend/workflows/BasicScenarios.test.js.map +1 -1
  46. package/package.json +14 -14
@@ -1,332 +1,332 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*---------------------------------------------------------------------------------------------
4
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
- * See LICENSE.md in the project root for license terms and full copyright notice.
6
- *--------------------------------------------------------------------------------------------*/
7
- const buffer_1 = require("buffer");
8
- const chai = require("chai");
9
- const core_bentley_1 = require("@itwin/core-bentley");
10
- const core_geometry_1 = require("@itwin/core-geometry");
11
- const core_common_1 = require("@itwin/core-common");
12
- const core_frontend_1 = require("@itwin/core-frontend");
13
- const frontend_1 = require("@itwin/oidc-signin-tool/lib/cjs/frontend");
14
- const TestContext_1 = require("./setup/TestContext");
15
- /* eslint-disable deprecation/deprecation */
16
- const expect = chai.expect;
17
- // eslint-disable-next-line @typescript-eslint/no-var-requires
18
- global.btoa = (str) => {
19
- const buffer = buffer_1.Buffer.from(str, "binary");
20
- return buffer.toString("base64");
21
- };
22
- describe("IModel Connection", () => {
23
- let accessToken;
24
- let testContext;
25
- before(async function () {
26
- testContext = await TestContext_1.TestContext.instance();
27
- if (!testContext.settings.runiModelReadRpcTests)
28
- this.skip();
29
- accessToken = testContext.adminUserAccessToken;
30
- core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
31
- });
32
- it("should successfully open an IModelConnection for read", async () => {
33
- const iTwinId = testContext.iModelWithChangesets.iTwinId;
34
- const iModelId = testContext.iModelWithChangesets.iModelId;
35
- const iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
36
- expect(iModel).to.exist.and.be.not.empty;
37
- const iModelRpcProps = iModel.getRpcProps();
38
- expect(iModelRpcProps).to.exist.and.be.not.empty;
39
- });
40
- it("should successfully close an open an IModelConnection", async () => {
41
- const iModelId = testContext.iModelWithChangesets.iModelId;
42
- const iTwinId = testContext.iModelWithChangesets.iTwinId;
43
- const iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
44
- expect(iModel).to.exist;
45
- return expect(iModel.close()).to.eventually.be.fulfilled;
46
- });
47
- });
48
- describe.skip("IModel Connection with client credentials", () => {
49
- let accessToken;
50
- let testContext;
51
- before(async function () {
52
- testContext = await TestContext_1.TestContext.instance();
53
- // If client credentials are not supplied or imodel read rpc tests are disabled skip test suite
54
- if (!testContext.settings.clientConfiguration || !testContext.settings.runiModelReadRpcTests)
55
- this.skip();
56
- accessToken = testContext.clientAccessToken;
57
- core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
58
- });
59
- it("should successfully open an IModelConnection for read", async () => {
60
- const iTwinId = testContext.iModelWithChangesets.iTwinId;
61
- const iModelId = testContext.iModelWithChangesets.iModelId;
62
- const changeSetId = (await testContext.iModelWithChangesets.getConnection()).changeset.id;
63
- const iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId, undefined === changeSetId ? core_common_1.IModelVersion.latest() : core_common_1.IModelVersion.asOfChangeSet(changeSetId));
64
- expect(iModel).to.exist.and.be.not.empty;
65
- const iModelRpcProps = iModel.getRpcProps();
66
- expect(iModelRpcProps).to.exist.and.be.not.empty;
67
- });
68
- });
69
- describe("IModelReadRpcInterface Methods from an IModelConnection", () => {
70
- let iModel;
71
- let iTwinId;
72
- let accessToken;
73
- let testContext;
74
- before(async function () {
75
- testContext = await TestContext_1.TestContext.instance();
76
- if (!testContext.settings.runiModelReadRpcTests) {
77
- this.skip();
78
- }
79
- const iModelId = testContext.iModelWithChangesets.iModelId;
80
- iTwinId = testContext.iModelWithChangesets.iTwinId;
81
- accessToken = testContext.adminUserAccessToken;
82
- core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
83
- iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
84
- });
85
- it("queryEntityIds should work as expected", async () => {
86
- const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:Subject" });
87
- expect(ids).to.exist;
88
- });
89
- it("getToolTipMessage should work as expected", async () => {
90
- const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:Subject" });
91
- const id = ids.values().next().value;
92
- const tooltip = await iModel.getToolTipMessage(id); // "0x338"
93
- expect(tooltip).to.not.be.undefined;
94
- });
95
- it("getDefaultViewId should work as expected", async () => {
96
- const result = await iModel.views.queryDefaultViewId();
97
- expect(result).to.not.be.undefined;
98
- });
99
- it("getGeometrySummary should work as expected", async () => {
100
- const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:Subject" });
101
- const id = ids.values().next().value;
102
- const result = await core_common_1.IModelReadRpcInterface.getClient().getGeometrySummary(iModel.getRpcProps(), { elementIds: [id], options: {} });
103
- expect(result).to.not.be.undefined;
104
- });
105
- it("requestSnap should work as expected", async () => {
106
- const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:PhysicalElement" });
107
- const id = ids.values().next().value;
108
- const worldToView = core_geometry_1.Matrix4d.createIdentity();
109
- const snap = await iModel.requestSnap({
110
- id,
111
- testPoint: { x: 1, y: 2, z: 3 },
112
- closePoint: { x: 1, y: 2, z: 3 },
113
- worldToView: worldToView.toJSON(),
114
- });
115
- expect(snap.status).to.not.be.undefined;
116
- });
117
- it("queryModelProps should work as expected", async () => {
118
- const modelQueryParams = { limit: 10, from: core_frontend_1.SpatialModelState.classFullName, wantPrivate: false };
119
- const curModelProps = await iModel.models.queryProps(modelQueryParams);
120
- expect(curModelProps).to.not.be.undefined;
121
- expect(curModelProps.length).gt(0);
122
- });
123
- it("getModelProps should work as expected", async () => {
124
- const modelQueryParams = { limit: 10, from: core_frontend_1.SpatialModelState.classFullName, wantPrivate: false };
125
- const curModelProps = await iModel.models.queryProps(modelQueryParams);
126
- const modelId = curModelProps[0].id.toString();
127
- await iModel.models.load(modelId); // "0x1c"
128
- expect(iModel.models.loaded.size).to.equal(1);
129
- expect(iModel.models.loaded.get(modelId)).to.not.be.undefined;
130
- });
131
- it("getClassHierarchy should work as expected", async () => {
132
- const result = await iModel.findClassFor("BisCore:LineStyle", undefined);
133
- expect(result).undefined;
134
- });
135
- it("getViewThumbnail should work as expected", async () => {
136
- const modelQueryParams = { limit: 10, from: core_frontend_1.ViewState.classFullName };
137
- const modelProps = await iModel.views.queryProps(modelQueryParams);
138
- const viewId = modelProps[0].id.toString();
139
- const result = await iModel.views.getThumbnail(viewId);
140
- expect(result).to.not.be.undefined;
141
- });
142
- it("getIModelCoordinatesFromGeoCoordinates should work as expected", async () => {
143
- const wgs84Converter = iModel.geoServices.getConverter("WGS84");
144
- const nad27Converter = iModel.geoServices.getConverter("NAD27");
145
- const geoPointList = [];
146
- for (let iLatitude = 0; iLatitude < 10; iLatitude++) {
147
- for (let iLongitude = 0; iLongitude < 10; iLongitude++) {
148
- geoPointList.push({ x: (132.600 + 0.02 * iLongitude), y: (34.350 + 0.02 * iLatitude), z: 0.0 });
149
- }
150
- }
151
- const testPoints = [];
152
- for (let iGeoPoint = 1; iGeoPoint < geoPointList.length; iGeoPoint += 2)
153
- testPoints.push(geoPointList[iGeoPoint]);
154
- const wgs84Response = await wgs84Converter.getIModelCoordinatesFromGeoCoordinates(testPoints);
155
- // shouldn't have any from the cache.
156
- expect(wgs84Response.fromCache === 0).to.be.true;
157
- // shouldn't have any failures.
158
- for (const result of wgs84Response.iModelCoords) {
159
- expect(core_common_1.GeoCoordStatus.Success === result.s);
160
- }
161
- const nad27Response = await nad27Converter.getIModelCoordinatesFromGeoCoordinates(testPoints);
162
- // shouldn't have any from the cache.
163
- expect(nad27Response.fromCache).eq(0);
164
- });
165
- it("getGeoCoordinatesFromIModelCoordinates should work as expected", async () => {
166
- const ecefProps = new core_common_1.EcefLocation({ orientation: core_geometry_1.YawPitchRollAngles.createDegrees(0, 0, 0), origin: core_geometry_1.Point3d.create(0, 0, 0) });
167
- iModel.setEcefLocation(ecefProps);
168
- await iModel.spatialToCartographic({ x: 6378.137, y: 0, z: 0 });
169
- });
170
- /* NEEDSWORK queryPage no longer exists; you cannot specify a specific rows-per-page to query for (only a maximum via LIMIT).
171
- it("queryRowCount should work as expected", async () => {
172
- const getRowPerPage = (nPageSize: number, nRowCount: number) => {
173
- const nRowPerPage = nRowCount / nPageSize;
174
- const nPages = Math.ceil(nRowPerPage);
175
- const nRowOnLastPage = nRowCount - (Math.floor(nRowPerPage) * pageSize);
176
- const pages = new Array(nPages).fill(pageSize);
177
- if (nRowPerPage) {
178
- pages[nPages - 1] = nRowOnLastPage;
179
- }
180
- return pages;
181
- };
182
-
183
- const pageSize = 5;
184
- const query = "SELECT ECInstanceId as Id, Parent.Id as ParentId FROM BisCore.Element";
185
- const rowCount = await iModel.queryRowCount(query);
186
-
187
- // verify row per page
188
- const rowPerPage = getRowPerPage(pageSize, rowCount);
189
- for (let k = 0; k < rowPerPage.length; k++) {
190
- const row = await iModel.queryPage(query, undefined, { size: pageSize, start: k });
191
- expect(row.length).to.be.equal(rowPerPage[k]);
192
- }
193
-
194
- // verify with async iterator
195
- const resultSet = [];
196
- for await (const row of iModel.query(query, undefined, { size: pageSize })) {
197
- resultSet.push(row);
198
- expect(Reflect.has(row, "id")).to.be.true;
199
- if (Reflect.ownKeys(row).length > 1) {
200
- expect(Reflect.has(row, "parentId")).to.be.true;
201
- const parentId: string = row.parentId;
202
- expect(parentId.startsWith("0x")).to.be.true;
203
- }
204
- const id: string = row.id;
205
- expect(id.startsWith("0x"));
206
- }
207
- expect(rowCount).to.be.equal(resultSet.length);
208
- });
209
- */
210
- it("queryModelRanges should work as expected", async () => {
211
- const modelProps = await iModel.models.queryProps({ limit: 10, from: "BisCore.SpatialModel" });
212
- const modelId = modelProps[0].id.toString();
213
- let idSet = core_bentley_1.Id64.toIdSet(modelId);
214
- let ranges = await iModel.models.queryModelRanges(idSet);
215
- expect(ranges).to.not.be.undefined;
216
- expect(ranges.length).to.be.equal(1);
217
- idSet = new Set();
218
- for (const modelProp of modelProps) {
219
- idSet.add(modelProp.id.toString());
220
- }
221
- ranges = await iModel.models.queryModelRanges(idSet);
222
- expect(ranges).to.not.be.undefined;
223
- expect(ranges.length).to.be.gte(1);
224
- });
225
- it("queryModelRanges should properly handle models that aren't geometric", async () => {
226
- // the below clause is created specifically for the test iModel, if that iModel were to be changed and it contained models that were geometricModels
227
- // but not PhysicalModels then the test may fail.
228
- let ranges;
229
- let modelProps = await iModel.models.queryProps({ limit: 10, from: "BisCore.Model", where: "ec_classname(ECClassId) <> 'BisCore:PhysicalModel'" });
230
- let idSet = new Set();
231
- for (const modelProp of modelProps) {
232
- idSet.add(modelProp.id.toString());
233
- }
234
- if (idSet.size === 1) { // queryModelRanges throws error if idSet size is 1 AND the id in the set returns some error for querying its extents
235
- await expect(iModel.models.queryModelRanges(idSet)).to.be.rejectedWith(Error);
236
- }
237
- else {
238
- ranges = await iModel.models.queryModelRanges(idSet);
239
- expect(ranges).to.not.be.undefined;
240
- expect(ranges.length).to.be.equal(0);
241
- }
242
- const dictModelId = await iModel.models.getDictionaryModel();
243
- idSet = core_bentley_1.Id64.toIdSet(dictModelId);
244
- await expect(iModel.models.queryModelRanges(idSet)).to.be.rejectedWith(Error);
245
- modelProps = await iModel.models.queryProps({ limit: 10, from: "BisCore.SpatialModel" });
246
- idSet.add(modelProps[0].id.toString());
247
- ranges = await iModel.models.queryModelRanges(idSet);
248
- expect(ranges).to.not.be.undefined;
249
- expect(ranges.length).to.be.equal(1);
250
- });
251
- it("getMassProperties should work as expected", async () => {
252
- const requestProps = {
253
- operation: core_common_1.MassPropertiesOperation.AccumulateVolumes,
254
- };
255
- const result = await core_common_1.IModelReadRpcInterface.getClient().getMassProperties(iModel.getRpcProps(), requestProps);
256
- expect(result).to.not.be.null;
257
- });
258
- it("getMassPropertiesPerCandidate should be able to process multiple elements", async () => {
259
- const candidates = [...await iModel.elements.queryIds({ from: "BisCore.GeometricElement3d", limit: 2, where: "GeometryStream IS NOT NULL" })];
260
- expect(candidates.length).to.be.equal(2);
261
- const requestProps = {
262
- operations: [core_common_1.MassPropertiesOperation.AccumulateVolumes],
263
- candidates: core_bentley_1.CompressedId64Set.compressIds(candidates),
264
- };
265
- const result = await core_common_1.IModelReadRpcInterface.getClient().getMassPropertiesPerCandidate(iModel.getRpcProps(), requestProps);
266
- expect(result).to.not.be.null;
267
- expect(result.length).to.be.equal(2);
268
- const candidate1Result = result.find((r) => r.candidate === candidates[0]);
269
- const candidate2Result = result.find((r) => r.candidate === candidates[1]);
270
- expect(candidate1Result).to.not.be.undefined;
271
- expect(candidate2Result).to.not.be.undefined;
272
- expect(candidate1Result === null || candidate1Result === void 0 ? void 0 : candidate1Result.status).to.be.equal(core_bentley_1.BentleyStatus.SUCCESS);
273
- expect(candidate2Result === null || candidate2Result === void 0 ? void 0 : candidate2Result.status).to.be.equal(core_bentley_1.BentleyStatus.SUCCESS);
274
- const expectedCandidate1Result = await core_common_1.IModelReadRpcInterface.getClient().getMassProperties(iModel.getRpcProps(), { operation: core_common_1.MassPropertiesOperation.AccumulateVolumes, candidates: [candidates[0]] });
275
- const expectedCandidate2Result = await core_common_1.IModelReadRpcInterface.getClient().getMassProperties(iModel.getRpcProps(), { operation: core_common_1.MassPropertiesOperation.AccumulateVolumes, candidates: [candidates[1]] });
276
- expect(candidate1Result).to.deep.eq(Object.assign(Object.assign({}, expectedCandidate1Result), { candidate: candidates[0] }));
277
- expect(candidate2Result).to.deep.eq(Object.assign(Object.assign({}, expectedCandidate2Result), { candidate: candidates[1] }));
278
- });
279
- });
280
- describe("Snapping", () => {
281
- let iModel;
282
- let iTwinId;
283
- let accessToken;
284
- let testContext;
285
- before(async function () {
286
- testContext = await TestContext_1.TestContext.instance();
287
- if (!testContext.settings.runiModelReadRpcTests)
288
- this.skip();
289
- const iModelId = testContext.iModelWithChangesets.iModelId;
290
- iTwinId = testContext.iModelWithChangesets.iTwinId;
291
- accessToken = testContext.adminUserAccessToken;
292
- core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
293
- iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
294
- });
295
- it("should be able to request a snap", async () => {
296
- const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:PhysicalElement" });
297
- const id = ids.values().next().value;
298
- const worldToView = core_geometry_1.Matrix4d.createIdentity();
299
- const snapProps = {
300
- id,
301
- testPoint: { x: 1, y: 2, z: 3 },
302
- closePoint: { x: 1, y: 2, z: 3 },
303
- worldToView: worldToView.toJSON(),
304
- };
305
- const snap = await core_common_1.IModelReadRpcInterface.getClient().requestSnap(iModel.getRpcProps(), id, snapProps);
306
- expect(snap.status).to.not.be.undefined;
307
- });
308
- it("should be able to cancel a snap", async () => {
309
- const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:PhysicalElement" });
310
- const id = ids.values().next().value;
311
- const worldToView = core_geometry_1.Matrix4d.createIdentity();
312
- const snapProps = {
313
- id,
314
- testPoint: { x: 1, y: 2, z: 3 },
315
- closePoint: { x: 1, y: 2, z: 3 },
316
- worldToView: worldToView.toJSON(),
317
- };
318
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
319
- const promise = core_common_1.IModelReadRpcInterface.getClient().requestSnap(iModel.getRpcProps(), id, snapProps);
320
- try {
321
- await core_common_1.IModelReadRpcInterface.getClient().cancelSnap(iModel.getRpcProps(), id);
322
- const snap = await promise;
323
- // This is what we expect if the snap is completed before the cancellation is processed.
324
- expect(snap.status).not.to.be.undefined;
325
- }
326
- catch (err) {
327
- // This is what we expect if the cancellation occurs in time to really cancel the snap.
328
- expect(err.message).to.equal("aborted");
329
- }
330
- });
331
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*---------------------------------------------------------------------------------------------
4
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
+ * See LICENSE.md in the project root for license terms and full copyright notice.
6
+ *--------------------------------------------------------------------------------------------*/
7
+ const buffer_1 = require("buffer");
8
+ const chai = require("chai");
9
+ const core_bentley_1 = require("@itwin/core-bentley");
10
+ const core_geometry_1 = require("@itwin/core-geometry");
11
+ const core_common_1 = require("@itwin/core-common");
12
+ const core_frontend_1 = require("@itwin/core-frontend");
13
+ const frontend_1 = require("@itwin/oidc-signin-tool/lib/cjs/frontend");
14
+ const TestContext_1 = require("./setup/TestContext");
15
+ /* eslint-disable deprecation/deprecation */
16
+ const expect = chai.expect;
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
18
+ global.btoa = (str) => {
19
+ const buffer = buffer_1.Buffer.from(str, "binary");
20
+ return buffer.toString("base64");
21
+ };
22
+ describe("IModel Connection", () => {
23
+ let accessToken;
24
+ let testContext;
25
+ before(async function () {
26
+ testContext = await TestContext_1.TestContext.instance();
27
+ if (!testContext.settings.runiModelReadRpcTests)
28
+ this.skip();
29
+ accessToken = testContext.adminUserAccessToken;
30
+ core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
31
+ });
32
+ it("should successfully open an IModelConnection for read", async () => {
33
+ const iTwinId = testContext.iModelWithChangesets.iTwinId;
34
+ const iModelId = testContext.iModelWithChangesets.iModelId;
35
+ const iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
36
+ expect(iModel).to.exist.and.be.not.empty;
37
+ const iModelRpcProps = iModel.getRpcProps();
38
+ expect(iModelRpcProps).to.exist.and.be.not.empty;
39
+ });
40
+ it("should successfully close an open an IModelConnection", async () => {
41
+ const iModelId = testContext.iModelWithChangesets.iModelId;
42
+ const iTwinId = testContext.iModelWithChangesets.iTwinId;
43
+ const iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
44
+ expect(iModel).to.exist;
45
+ return expect(iModel.close()).to.eventually.be.fulfilled;
46
+ });
47
+ });
48
+ describe.skip("IModel Connection with client credentials", () => {
49
+ let accessToken;
50
+ let testContext;
51
+ before(async function () {
52
+ testContext = await TestContext_1.TestContext.instance();
53
+ // If client credentials are not supplied or imodel read rpc tests are disabled skip test suite
54
+ if (!testContext.settings.clientConfiguration || !testContext.settings.runiModelReadRpcTests)
55
+ this.skip();
56
+ accessToken = testContext.clientAccessToken;
57
+ core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
58
+ });
59
+ it("should successfully open an IModelConnection for read", async () => {
60
+ const iTwinId = testContext.iModelWithChangesets.iTwinId;
61
+ const iModelId = testContext.iModelWithChangesets.iModelId;
62
+ const changeSetId = (await testContext.iModelWithChangesets.getConnection()).changeset.id;
63
+ const iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId, undefined === changeSetId ? core_common_1.IModelVersion.latest() : core_common_1.IModelVersion.asOfChangeSet(changeSetId));
64
+ expect(iModel).to.exist.and.be.not.empty;
65
+ const iModelRpcProps = iModel.getRpcProps();
66
+ expect(iModelRpcProps).to.exist.and.be.not.empty;
67
+ });
68
+ });
69
+ describe("IModelReadRpcInterface Methods from an IModelConnection", () => {
70
+ let iModel;
71
+ let iTwinId;
72
+ let accessToken;
73
+ let testContext;
74
+ before(async function () {
75
+ testContext = await TestContext_1.TestContext.instance();
76
+ if (!testContext.settings.runiModelReadRpcTests) {
77
+ this.skip();
78
+ }
79
+ const iModelId = testContext.iModelWithChangesets.iModelId;
80
+ iTwinId = testContext.iModelWithChangesets.iTwinId;
81
+ accessToken = testContext.adminUserAccessToken;
82
+ core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
83
+ iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
84
+ });
85
+ it("queryEntityIds should work as expected", async () => {
86
+ const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:Subject" });
87
+ expect(ids).to.exist;
88
+ });
89
+ it("getToolTipMessage should work as expected", async () => {
90
+ const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:Subject" });
91
+ const id = ids.values().next().value;
92
+ const tooltip = await iModel.getToolTipMessage(id); // "0x338"
93
+ expect(tooltip).to.not.be.undefined;
94
+ });
95
+ it("getDefaultViewId should work as expected", async () => {
96
+ const result = await iModel.views.queryDefaultViewId();
97
+ expect(result).to.not.be.undefined;
98
+ });
99
+ it("getGeometrySummary should work as expected", async () => {
100
+ const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:Subject" });
101
+ const id = ids.values().next().value;
102
+ const result = await core_common_1.IModelReadRpcInterface.getClient().getGeometrySummary(iModel.getRpcProps(), { elementIds: [id], options: {} });
103
+ expect(result).to.not.be.undefined;
104
+ });
105
+ it("requestSnap should work as expected", async () => {
106
+ const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:PhysicalElement" });
107
+ const id = ids.values().next().value;
108
+ const worldToView = core_geometry_1.Matrix4d.createIdentity();
109
+ const snap = await iModel.requestSnap({
110
+ id,
111
+ testPoint: { x: 1, y: 2, z: 3 },
112
+ closePoint: { x: 1, y: 2, z: 3 },
113
+ worldToView: worldToView.toJSON(),
114
+ });
115
+ expect(snap.status).to.not.be.undefined;
116
+ });
117
+ it("queryModelProps should work as expected", async () => {
118
+ const modelQueryParams = { limit: 10, from: core_frontend_1.SpatialModelState.classFullName, wantPrivate: false };
119
+ const curModelProps = await iModel.models.queryProps(modelQueryParams);
120
+ expect(curModelProps).to.not.be.undefined;
121
+ expect(curModelProps.length).gt(0);
122
+ });
123
+ it("getModelProps should work as expected", async () => {
124
+ const modelQueryParams = { limit: 10, from: core_frontend_1.SpatialModelState.classFullName, wantPrivate: false };
125
+ const curModelProps = await iModel.models.queryProps(modelQueryParams);
126
+ const modelId = curModelProps[0].id.toString();
127
+ await iModel.models.load(modelId); // "0x1c"
128
+ expect(iModel.models.loaded.size).to.equal(1);
129
+ expect(iModel.models.loaded.get(modelId)).to.not.be.undefined;
130
+ });
131
+ it("getClassHierarchy should work as expected", async () => {
132
+ const result = await iModel.findClassFor("BisCore:LineStyle", undefined);
133
+ expect(result).undefined;
134
+ });
135
+ it("getViewThumbnail should work as expected", async () => {
136
+ const modelQueryParams = { limit: 10, from: core_frontend_1.ViewState.classFullName };
137
+ const modelProps = await iModel.views.queryProps(modelQueryParams);
138
+ const viewId = modelProps[0].id.toString();
139
+ const result = await iModel.views.getThumbnail(viewId);
140
+ expect(result).to.not.be.undefined;
141
+ });
142
+ it("getIModelCoordinatesFromGeoCoordinates should work as expected", async () => {
143
+ const wgs84Converter = iModel.geoServices.getConverter("WGS84");
144
+ const nad27Converter = iModel.geoServices.getConverter("NAD27");
145
+ const geoPointList = [];
146
+ for (let iLatitude = 0; iLatitude < 10; iLatitude++) {
147
+ for (let iLongitude = 0; iLongitude < 10; iLongitude++) {
148
+ geoPointList.push({ x: (132.600 + 0.02 * iLongitude), y: (34.350 + 0.02 * iLatitude), z: 0.0 });
149
+ }
150
+ }
151
+ const testPoints = [];
152
+ for (let iGeoPoint = 1; iGeoPoint < geoPointList.length; iGeoPoint += 2)
153
+ testPoints.push(geoPointList[iGeoPoint]);
154
+ const wgs84Response = await wgs84Converter.getIModelCoordinatesFromGeoCoordinates(testPoints);
155
+ // shouldn't have any from the cache.
156
+ expect(wgs84Response.fromCache === 0).to.be.true;
157
+ // shouldn't have any failures.
158
+ for (const result of wgs84Response.iModelCoords) {
159
+ expect(core_common_1.GeoCoordStatus.Success === result.s);
160
+ }
161
+ const nad27Response = await nad27Converter.getIModelCoordinatesFromGeoCoordinates(testPoints);
162
+ // shouldn't have any from the cache.
163
+ expect(nad27Response.fromCache).eq(0);
164
+ });
165
+ it("getGeoCoordinatesFromIModelCoordinates should work as expected", async () => {
166
+ const ecefProps = new core_common_1.EcefLocation({ orientation: core_geometry_1.YawPitchRollAngles.createDegrees(0, 0, 0), origin: core_geometry_1.Point3d.create(0, 0, 0) });
167
+ iModel.setEcefLocation(ecefProps);
168
+ await iModel.spatialToCartographic({ x: 6378.137, y: 0, z: 0 });
169
+ });
170
+ /* NEEDSWORK queryPage no longer exists; you cannot specify a specific rows-per-page to query for (only a maximum via LIMIT).
171
+ it("queryRowCount should work as expected", async () => {
172
+ const getRowPerPage = (nPageSize: number, nRowCount: number) => {
173
+ const nRowPerPage = nRowCount / nPageSize;
174
+ const nPages = Math.ceil(nRowPerPage);
175
+ const nRowOnLastPage = nRowCount - (Math.floor(nRowPerPage) * pageSize);
176
+ const pages = new Array(nPages).fill(pageSize);
177
+ if (nRowPerPage) {
178
+ pages[nPages - 1] = nRowOnLastPage;
179
+ }
180
+ return pages;
181
+ };
182
+
183
+ const pageSize = 5;
184
+ const query = "SELECT ECInstanceId as Id, Parent.Id as ParentId FROM BisCore.Element";
185
+ const rowCount = await iModel.queryRowCount(query);
186
+
187
+ // verify row per page
188
+ const rowPerPage = getRowPerPage(pageSize, rowCount);
189
+ for (let k = 0; k < rowPerPage.length; k++) {
190
+ const row = await iModel.queryPage(query, undefined, { size: pageSize, start: k });
191
+ expect(row.length).to.be.equal(rowPerPage[k]);
192
+ }
193
+
194
+ // verify with async iterator
195
+ const resultSet = [];
196
+ for await (const row of iModel.query(query, undefined, { size: pageSize })) {
197
+ resultSet.push(row);
198
+ expect(Reflect.has(row, "id")).to.be.true;
199
+ if (Reflect.ownKeys(row).length > 1) {
200
+ expect(Reflect.has(row, "parentId")).to.be.true;
201
+ const parentId: string = row.parentId;
202
+ expect(parentId.startsWith("0x")).to.be.true;
203
+ }
204
+ const id: string = row.id;
205
+ expect(id.startsWith("0x"));
206
+ }
207
+ expect(rowCount).to.be.equal(resultSet.length);
208
+ });
209
+ */
210
+ it("queryModelRanges should work as expected", async () => {
211
+ const modelProps = await iModel.models.queryProps({ limit: 10, from: "BisCore.SpatialModel" });
212
+ const modelId = modelProps[0].id.toString();
213
+ let idSet = core_bentley_1.Id64.toIdSet(modelId);
214
+ let ranges = await iModel.models.queryModelRanges(idSet);
215
+ expect(ranges).to.not.be.undefined;
216
+ expect(ranges.length).to.be.equal(1);
217
+ idSet = new Set();
218
+ for (const modelProp of modelProps) {
219
+ idSet.add(modelProp.id.toString());
220
+ }
221
+ ranges = await iModel.models.queryModelRanges(idSet);
222
+ expect(ranges).to.not.be.undefined;
223
+ expect(ranges.length).to.be.gte(1);
224
+ });
225
+ it("queryModelRanges should properly handle models that aren't geometric", async () => {
226
+ // the below clause is created specifically for the test iModel, if that iModel were to be changed and it contained models that were geometricModels
227
+ // but not PhysicalModels then the test may fail.
228
+ let ranges;
229
+ let modelProps = await iModel.models.queryProps({ limit: 10, from: "BisCore.Model", where: "ec_classname(ECClassId) <> 'BisCore:PhysicalModel'" });
230
+ let idSet = new Set();
231
+ for (const modelProp of modelProps) {
232
+ idSet.add(modelProp.id.toString());
233
+ }
234
+ if (idSet.size === 1) { // queryModelRanges throws error if idSet size is 1 AND the id in the set returns some error for querying its extents
235
+ await expect(iModel.models.queryModelRanges(idSet)).to.be.rejectedWith(Error);
236
+ }
237
+ else {
238
+ ranges = await iModel.models.queryModelRanges(idSet);
239
+ expect(ranges).to.not.be.undefined;
240
+ expect(ranges.length).to.be.equal(0);
241
+ }
242
+ const dictModelId = await iModel.models.getDictionaryModel();
243
+ idSet = core_bentley_1.Id64.toIdSet(dictModelId);
244
+ await expect(iModel.models.queryModelRanges(idSet)).to.be.rejectedWith(Error);
245
+ modelProps = await iModel.models.queryProps({ limit: 10, from: "BisCore.SpatialModel" });
246
+ idSet.add(modelProps[0].id.toString());
247
+ ranges = await iModel.models.queryModelRanges(idSet);
248
+ expect(ranges).to.not.be.undefined;
249
+ expect(ranges.length).to.be.equal(1);
250
+ });
251
+ it("getMassProperties should work as expected", async () => {
252
+ const requestProps = {
253
+ operation: core_common_1.MassPropertiesOperation.AccumulateVolumes,
254
+ };
255
+ const result = await core_common_1.IModelReadRpcInterface.getClient().getMassProperties(iModel.getRpcProps(), requestProps);
256
+ expect(result).to.not.be.null;
257
+ });
258
+ it("getMassPropertiesPerCandidate should be able to process multiple elements", async () => {
259
+ const candidates = [...await iModel.elements.queryIds({ from: "BisCore.GeometricElement3d", limit: 2, where: "GeometryStream IS NOT NULL" })];
260
+ expect(candidates.length).to.be.equal(2);
261
+ const requestProps = {
262
+ operations: [core_common_1.MassPropertiesOperation.AccumulateVolumes],
263
+ candidates: core_bentley_1.CompressedId64Set.compressIds(candidates),
264
+ };
265
+ const result = await core_common_1.IModelReadRpcInterface.getClient().getMassPropertiesPerCandidate(iModel.getRpcProps(), requestProps);
266
+ expect(result).to.not.be.null;
267
+ expect(result.length).to.be.equal(2);
268
+ const candidate1Result = result.find((r) => r.candidate === candidates[0]);
269
+ const candidate2Result = result.find((r) => r.candidate === candidates[1]);
270
+ expect(candidate1Result).to.not.be.undefined;
271
+ expect(candidate2Result).to.not.be.undefined;
272
+ expect(candidate1Result === null || candidate1Result === void 0 ? void 0 : candidate1Result.status).to.be.equal(core_bentley_1.BentleyStatus.SUCCESS);
273
+ expect(candidate2Result === null || candidate2Result === void 0 ? void 0 : candidate2Result.status).to.be.equal(core_bentley_1.BentleyStatus.SUCCESS);
274
+ const expectedCandidate1Result = await core_common_1.IModelReadRpcInterface.getClient().getMassProperties(iModel.getRpcProps(), { operation: core_common_1.MassPropertiesOperation.AccumulateVolumes, candidates: [candidates[0]] });
275
+ const expectedCandidate2Result = await core_common_1.IModelReadRpcInterface.getClient().getMassProperties(iModel.getRpcProps(), { operation: core_common_1.MassPropertiesOperation.AccumulateVolumes, candidates: [candidates[1]] });
276
+ expect(candidate1Result).to.deep.eq(Object.assign(Object.assign({}, expectedCandidate1Result), { candidate: candidates[0] }));
277
+ expect(candidate2Result).to.deep.eq(Object.assign(Object.assign({}, expectedCandidate2Result), { candidate: candidates[1] }));
278
+ });
279
+ });
280
+ describe("Snapping", () => {
281
+ let iModel;
282
+ let iTwinId;
283
+ let accessToken;
284
+ let testContext;
285
+ before(async function () {
286
+ testContext = await TestContext_1.TestContext.instance();
287
+ if (!testContext.settings.runiModelReadRpcTests)
288
+ this.skip();
289
+ const iModelId = testContext.iModelWithChangesets.iModelId;
290
+ iTwinId = testContext.iModelWithChangesets.iTwinId;
291
+ accessToken = testContext.adminUserAccessToken;
292
+ core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
293
+ iModel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
294
+ });
295
+ it("should be able to request a snap", async () => {
296
+ const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:PhysicalElement" });
297
+ const id = ids.values().next().value;
298
+ const worldToView = core_geometry_1.Matrix4d.createIdentity();
299
+ const snapProps = {
300
+ id,
301
+ testPoint: { x: 1, y: 2, z: 3 },
302
+ closePoint: { x: 1, y: 2, z: 3 },
303
+ worldToView: worldToView.toJSON(),
304
+ };
305
+ const snap = await core_common_1.IModelReadRpcInterface.getClient().requestSnap(iModel.getRpcProps(), id, snapProps);
306
+ expect(snap.status).to.not.be.undefined;
307
+ });
308
+ it("should be able to cancel a snap", async () => {
309
+ const ids = await iModel.elements.queryIds({ limit: 10, from: "BisCore:PhysicalElement" });
310
+ const id = ids.values().next().value;
311
+ const worldToView = core_geometry_1.Matrix4d.createIdentity();
312
+ const snapProps = {
313
+ id,
314
+ testPoint: { x: 1, y: 2, z: 3 },
315
+ closePoint: { x: 1, y: 2, z: 3 },
316
+ worldToView: worldToView.toJSON(),
317
+ };
318
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
319
+ const promise = core_common_1.IModelReadRpcInterface.getClient().requestSnap(iModel.getRpcProps(), id, snapProps);
320
+ try {
321
+ await core_common_1.IModelReadRpcInterface.getClient().cancelSnap(iModel.getRpcProps(), id);
322
+ const snap = await promise;
323
+ // This is what we expect if the snap is completed before the cancellation is processed.
324
+ expect(snap.status).not.to.be.undefined;
325
+ }
326
+ catch (err) {
327
+ // This is what we expect if the cancellation occurs in time to really cancel the snap.
328
+ expect(err.message).to.equal("aborted");
329
+ }
330
+ });
331
+ });
332
332
  //# sourceMappingURL=IModelConnection.test.js.map