Skip to content

Commit 8ee4b99

Browse files
authored
Add missing integration tests for changed-elements commands (#105)
* Added missing integration tests for changed-elements commmands. * Added a delay to some access-control tests to fix flakiness. * Updated itwin/imodel name in changesets-comparison.ts. Updated a test in itwin/list.ts to prevent occasional failures.
1 parent d7c4e2b commit 8ee4b99

5 files changed

Lines changed: 80 additions & 2 deletions

File tree

integration-tests/access-control/member/owner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const tests = () => {
3939

4040
await fetch(invitationLink);
4141

42+
await new Promise<void>(resolve => {setTimeout(_ => resolve(), 3 * 1000);});
43+
4244
const usersInfo = await runCommand<groupMember[]>(`access-control member owner list --itwin-id ${iTwinId}`);
4345
expect(usersInfo.result).is.not.undefined;
4446
expect(usersInfo.result!.length).to.be.equal(2);

integration-tests/access-control/member/user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const tests = () => {
4646

4747
await fetch(invitationLink);
4848

49+
await new Promise<void>(resolve => {setTimeout(_ => resolve(), 3 * 1000);});
50+
4951
const usersInfo = await runCommand<member[]>(`access-control member user list --itwin-id ${iTwinId}`);
5052
expect(usersInfo.result).is.not.undefined;
5153
expect(usersInfo.result!.length).to.be.equal(2);

integration-tests/changed-elements/changed-elements.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { loginToCli } from "../utils/helpers";
7+
import changesetsComparisonTests from "./changesets-comparison";
78
import enableDisableInfoTests from "./enable-disable-info";
89

910
describe('Changed Elements Integration Tests', () => {
@@ -12,5 +13,5 @@ describe('Changed Elements Integration Tests', () => {
1213
});
1314

1415
enableDisableInfoTests();
15-
16+
changesetsComparisonTests();
1617
});
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IModel } from '@itwin/imodels-client-management';
7+
import { ITwin } from '@itwin/itwins-client';
8+
import { runCommand } from '@oclif/test';
9+
import { expect } from 'chai';
10+
11+
import { changeset, changesetComparison } from '../../src/services/changed-elements-client/tracking';
12+
import { createFile, createIModel, createITwin, getRootFolderId } from '../utils/helpers';
13+
import { resultResponse } from '../utils/result-response';
14+
15+
const tests = () => describe('changesets + comparison', () => {
16+
const testITwinName = 'ITwinCLI_IntegrationTestITwin_ChangedElements';
17+
const testIModelName = 'ITwinCLI_IntegrationTestIModel_ChangedElements';
18+
const testFileName = 'test.zip';
19+
const testFilePath = 'integration-tests/test.zip';
20+
let testIModelId: string;
21+
let testITwinId: string;
22+
23+
before(async () => {
24+
const filteredITwins = await runCommand<ITwin[]>(`itwin list --name ${testITwinName}`);
25+
expect(filteredITwins.result).to.not.be.undefined
26+
27+
if(filteredITwins.result!.length === 0) {
28+
const testITwin = await createITwin(testITwinName, 'Thing', 'Asset');
29+
testITwinId = testITwin.id as string;
30+
const testIModel = await createIModel(testIModelName, testITwinId);
31+
testIModelId = testIModel.id;
32+
33+
await runCommand<resultResponse>(`changed-elements enable --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
34+
35+
const rootFolderId = await getRootFolderId(testITwinId);
36+
await createFile(rootFolderId, testFileName, testFilePath);
37+
const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID`);
38+
expect(result.result).to.have.property('iModelId', testIModelId);
39+
expect(result.result).to.have.property('iTwinId', testITwinId);
40+
}
41+
else {
42+
testITwinId = filteredITwins.result![0].id!;
43+
const iModels = await runCommand<IModel[]>(`imodel list --itwin-id ${testITwinId}`);
44+
expect(iModels.result).to.not.be.undefined;
45+
expect(iModels.result?.length).to.be.equal(1);
46+
testIModelId = iModels.result![0].id;
47+
}
48+
});
49+
50+
it('should get changesets', async () => {
51+
const response = await runCommand<changeset[]>(`changed-elements changesets --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
52+
expect(response.result).to.not.be.undefined;
53+
expect(response.result?.length).to.be.equal(4);
54+
55+
const responseFiltered = await runCommand<changeset[]>(`changed-elements changesets --imodel-id ${testIModelId} --itwin-id ${testITwinId} --skip 2 --top 2`);
56+
expect(responseFiltered.result).to.not.be.undefined;
57+
expect(responseFiltered.result?.length).to.be.equal(2);
58+
expect(responseFiltered.result?.map(x => x.id)).to.be.deep.equal(response.result?.map(x => x.id).slice(2))
59+
});
60+
61+
it('should compare 2 changesets', async () => {
62+
const response = await runCommand<changeset[]>(`changed-elements changesets --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
63+
expect(response.result).to.not.be.undefined;
64+
expect(response.result?.length).to.be.equal(4);
65+
66+
const comparisonResponse = await runCommand<changesetComparison>(`changed-elements comparison --imodel-id ${testIModelId} --itwin-id ${testITwinId} --changeset-id1 ${response.result![0].id} --changeset-id2 ${response.result![3].id}`);
67+
expect(comparisonResponse.result).to.not.be.undefined;
68+
expect(comparisonResponse.result!.opcodes.length).to.be.equal(1);
69+
expect(comparisonResponse.result!.opcodes[0]).to.be.equal(18); // Element was inserted
70+
});
71+
});
72+
73+
export default tests;

integration-tests/itwin/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const tests = () => describe('list', () => {
102102
});
103103

104104
it('should search for itwins by number', async () => {
105-
const result = await runCommand(`itwin list --search ${testITwin1.number!.slice(2, 4)}`);
105+
const result = await runCommand(`itwin list --search ${testITwin1.number}`);
106106
const resultArr: ITwin[] = JSON.parse(result.stdout);
107107

108108
expect(resultArr).to.be.an('array').that.is.not.empty;

0 commit comments

Comments
 (0)