Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"--forbid-only",
"--timeout",
"999999",
"integration-tests/main-cases/*.test.ts"
"integration-tests/main-cases/*.test.ts",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Debug Active Test",
"name": "Debug Active Test (Service Client)",
"skipFiles": [
"<node_internals>/**"
],
Expand All @@ -59,10 +59,31 @@
"--forbid-only",
"--timeout",
"999999",
"${file}"
"${file}",
"--require",
"integration-tests/utils/mocha-global-setup-service.ts"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
},
{
"name": "Debug Active Test (Native Client)",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha",
"args": [
"--forbid-only",
"--timeout",
"999999",
"${file}",
"--require",
"integration-tests/utils/mocha-global-setup-native.ts"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
]
}
41 changes: 12 additions & 29 deletions integration-tests/imodel/named-version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,35 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { IModel, NamedVersion } from '@itwin/imodels-client-management';
import { ITwin } from '@itwin/itwins-client';
import { NamedVersion } from '@itwin/imodels-client-management';
import { runCommand } from '@oclif/test';
import { expect } from 'chai';

import { changeset } from '../../src/services/changed-elements-client/tracking';
import { createFile, createIModel, createITwin, getRootFolderId } from '../utils/helpers';
import { createIModel, createITwin } from '../utils/helpers';
import { resultResponse } from '../utils/result-response';
import runSuiteIfMainModule from '../utils/run-suite-if-main-module';

const tests = () => describe('named-version', () => {
const testITwinName = 'ITwinCLI_IntegrationTestITwin_iModelNamedVersion';
const testIModelName = 'ITwinCLI_IntegrationTestIModel_iModelNamedVersion';
const testFileName = 'test.zip';
const testFilePath = 'integration-tests/test.zip';
const testFilePath = 'examples/datasets/ExtonCampus.dgn';
let testIModelId: string;
let testITwinId: string;

before(async function() {
this.timeout(30 * 60 * 1000);

const filteredITwins = await runCommand<ITwin[]>(`itwin list --name ${testITwinName}`);
expect(filteredITwins.result).to.not.be.undefined
const testITwin = await createITwin(testITwinName, 'Thing', 'Asset');
testITwinId = testITwin.id as string;
const testIModel = await createIModel(testIModelName, testITwinId);
testIModelId = testIModel.id;

if(filteredITwins.result!.length === 0) {
const testITwin = await createITwin(testITwinName, 'Thing', 'Asset');
testITwinId = testITwin.id as string;
const testIModel = await createIModel(testIModelName, testITwinId);
testIModelId = testIModel.id;
await runCommand<resultResponse>(`changed-elements enable --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);

await runCommand<resultResponse>(`changed-elements enable --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);

const rootFolderId = await getRootFolderId(testITwinId);
await createFile(rootFolderId, testFileName, testFilePath);

const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID`);
expect(result.result).to.have.property('iModelId', testIModelId);
expect(result.result).to.have.property('iTwinId', testITwinId);
}
else {
testITwinId = filteredITwins.result![0].id!;
const iModels = await runCommand<IModel[]>(`imodel list --itwin-id ${testITwinId}`);
expect(iModels.result).to.not.be.undefined;
expect(iModels.result?.length).to.be.equal(1);
testIModelId = iModels.result![0].id;
}
const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type MSTN`);
expect(result.result).to.have.property('iModelId', testIModelId);
expect(result.result).to.have.property('iTwinId', testITwinId);
});

after(async () => {
Expand All @@ -62,7 +45,7 @@ const tests = () => describe('named-version', () => {
it('should create a new named version with specified changeset', async () => {
const { result: changesets} = await runCommand<changeset[]>(`changed-elements changesets --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
expect(changesets).to.not.be.undefined;
expect(changesets!.length).to.be.equal(4);
expect(changesets!.length).to.be.equal(15);
Comment thread
Nadegamra marked this conversation as resolved.

const response = await runCommand<NamedVersion>(`imodel named-version create --imodel-id ${testIModelId} --changeset-id ${changesets![0].id} -n "Version 1.0" -d "Some description of the version"`);
expect(response.result).to.not.be.undefined;
Expand Down
69 changes: 58 additions & 11 deletions integration-tests/imodel/populate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import { runCommand } from '@oclif/test';
import { expect } from 'chai';

import { createFile, createIModel, createITwin, getRootFolderId } from '../utils/helpers';
import { populateResponse} from '../../src/commands/imodel/populate';
import { executionResult } from '../../src/services/synchronizationClient/models/execution-result';
import { executionState } from '../../src/services/synchronizationClient/models/execution-state';
import { storageConnection } from '../../src/services/synchronizationClient/models/storage-connection';
import { storageRun } from '../../src/services/synchronizationClient/models/storage-run';
import { createIModel, createITwin } from '../utils/helpers';
import runSuiteIfMainModule from '../utils/run-suite-if-main-module';

const tests = () => describe('populate', () => {
const testFileName = 'test.zip';
const testFilePath = 'integration-tests/test.zip';
let testFileId: string;
const failingTestFilePath = 'integration-tests/test.zip'
const testFilePath = 'examples/datasets/ExtonCampus.dgn';

let testIModelId: string;
let testITwinId: string;

Expand All @@ -21,24 +26,66 @@ const tests = () => describe('populate', () => {
testITwinId = testITwin.id!;
const testIModel = await createIModel(`cli-imodel-integration-test-${new Date().toISOString()}`, testITwinId);
testIModelId = testIModel.id!;
const rootFolderId = await getRootFolderId(testITwinId);
const testFile = await createFile(rootFolderId, testFileName, testFilePath);
testFileId = testFile.id!;
});

after(async () => {
const { result: fileDeleteResult } = await runCommand(`storage file delete --file-id ${testFileId}`);
const { result: iModelDeleteResult } = await runCommand(`imodel delete --imodel-id ${testIModelId}`);
const { result: iTwinDeleteResult } = await runCommand(`itwin delete --itwin-id ${testITwinId}`);

expect(fileDeleteResult).to.have.property('result', 'deleted');
expect(iModelDeleteResult).to.have.property('result', 'deleted');
expect(iTwinDeleteResult).to.have.property('result', 'deleted');
});

it('should populate the iModel with the uploaded file', async () => {
const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID`);
expect(result.result).to.have.property('iModelId', testIModelId);
const { result: populateResult } = await runCommand<populateResponse>(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type MSTN`);
expect(populateResult).to.not.be.undefined;
expect(populateResult!.iTwinId).to.be.equal(testITwinId);
expect(populateResult!.iModelId).to.be.equal(testIModelId);
expect(populateResult!.summary).to.not.be.undefined;
expect(populateResult!.summary.length).to.be.equal(1);
expect(populateResult!.summary[0].connectionId).to.not.be.undefined;
expect(populateResult!.summary[0].runId).to.not.be.undefined;

const {connectionId, runId} = populateResult!.summary[0];
const { result: infoResult } = await runCommand<storageRun>(`imodel connection run info -c ${connectionId} --connection-run-id ${runId}`);
expect(infoResult?.state).to.be.equal(executionState.COMPLETED);
expect(infoResult?.result).to.be.equal(executionResult.SUCCESS);
}).timeout(30 * 60 * 1000);

it('should populate the iModel with the uploaded file (no-wait flag with polling)', async () => {
const { result: populateResult } = await runCommand<populateResponse>(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID --no-wait`);
expect(populateResult).to.not.be.undefined;
expect(populateResult!.iTwinId).to.be.equal(testITwinId);
expect(populateResult!.iModelId).to.be.equal(testIModelId);
expect(populateResult!.summary).to.not.be.undefined;
expect(populateResult!.summary.length).to.be.equal(1);
expect(populateResult!.summary[0].connectionId).to.not.be.undefined;
expect(populateResult!.summary[0].runId).to.not.be.undefined;

const {connectionId, runId} = populateResult!.summary[0];
let { result: infoResult } = await runCommand<storageRun>(`imodel connection run info -c ${connectionId} --connection-run-id ${runId}`);
while(infoResult?.state !== "Completed") {
// eslint-disable-next-line no-await-in-loop
await new Promise(r => {setTimeout(r, 10_000)});

// eslint-disable-next-line no-await-in-loop
const { result } = await runCommand<storageRun>(`imodel connection run info -c ${connectionId} --connection-run-id ${runId}`);
infoResult = result;
}

expect(infoResult?.state).to.be.equal(executionState.COMPLETED);
expect(infoResult?.result).to.be.equal(executionResult.SUCCESS);
}).timeout(30 * 60 * 1000);

it('should return an error message if synchronization run completes with a non-success state', async () => {
const { error: populateError } = await runCommand<populateResponse>(`imodel populate --imodel-id ${testIModelId} --file ${failingTestFilePath} --connector-type IFC`);
expect(populateError).to.not.be.undefined;
expect(populateError?.message).to.match(/Synchronization run .*? resulted in an error. Run 'itp imodel connection run info --connection-id .*? --connection-run-id .*?' for more info./);

const command = populateError?.message.match(/imodel connection run info --connection-id .*? --connection-run-id .*?'/)![0]?.slice(0,-1);
const { result: infoResult } = await runCommand<storageConnection>(command!);
expect(infoResult).to.not.be.undefined;
expect(infoResult?.error).to.not.be.null;
}).timeout(30 * 60 * 1000);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { runCommand } from '@oclif/test';

import iModelConnectionRunTests from '../../imodel/connection/run.test';
import { nativeLoginToCli } from '../../utils/helpers';

describe('Native Client Tests (imodel connection run)', async () => {
before(async function() {
this.timeout(5 * 60 * 1000);
await nativeLoginToCli();
await runCommand(`imodel connection auth`);
})

iModelConnectionRunTests();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import iModelNamedVersionTests from '../../imodel/named-version.test';

describe('Native Client Tests (imodel named-version)', async () => {
iModelNamedVersionTests();
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import iModelNamedVersionTests from '../../imodel/named-version.test';
import iModelPopulateTests from '../../imodel/populate.test';
import { nativeLoginToCli } from '../../utils/helpers';

describe('Native Client Tests (imodel populate)', async () => {
before(async function() {
this.timeout(5 * 60 * 1000);
await nativeLoginToCli();
})

iModelNamedVersionTests();
iModelPopulateTests();
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
*--------------------------------------------------------------------------------------------*/

import accessControlNativeTests from '../../access-control-native/access-control-native.test'
import { nativeLoginToCli } from '../../utils/helpers';
import sharedQuickUseCasesParallel from '../shared-quick-use-cases-parallel';

describe('Native Client Tests', async () => {
before(async function() {
this.timeout(5 * 60 * 1000);
await nativeLoginToCli();
})

accessControlNativeTests();
sharedQuickUseCasesParallel();

});
4 changes: 0 additions & 4 deletions integration-tests/main-cases/native-client-serial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import iModelConnectionAuthTests from '../imodel-native/connection/auth.test'
import { nativeLoginToCli } from '../utils/helpers';

describe('Native Client Tests (serial)', async () => {
before(async () => {
await nativeLoginToCli();
})

describe('Authentication Integration Tests', async () => {
after(async () => {
await nativeLoginToCli();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import iModelConnectionRunTests from '../../imodel/connection/run.test';
import { logoutFromCLI } from '../../utils/helpers';

describe('Service Client Tests (imodel connection run)', async () => {
before(async function() {
this.timeout(5 * 60 * 1000);
await logoutFromCLI();
})

iModelConnectionRunTests();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import iModelNamedVersionTests from '../../imodel/named-version.test';

describe('Service Client Tests (imodel named-version)', () => {
iModelNamedVersionTests();
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import iModelNamedVersionTests from '../../imodel/named-version.test';
import iModelPopulateTests from '../../imodel/populate.test'
import { logoutFromCLI } from '../../utils/helpers';

describe('Service Client Tests (imodel populate)', () => {
before(async function() {
this.timeout(5 * 60 * 1000);
await logoutFromCLI();
})

iModelNamedVersionTests();
iModelPopulateTests();
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { logoutFromCLI } from '../../utils/helpers'
import sharedQuickUseCasesParallel from '../shared-quick-use-cases-parallel';

describe('Service Client Tests', () => {
before(async function() {
this.timeout(5 * 60 * 1000);
await logoutFromCLI();
})

sharedQuickUseCasesParallel();
});
4 changes: 0 additions & 4 deletions integration-tests/main-cases/service-client-serial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@

import authTests from '../auth/auth.test'
import authTestsService from '../auth-service/auth-service.test'
import { logoutFromCLI } from '../utils/helpers'

describe('Service Client Tests (serial)', () => {
before(async () => {
await logoutFromCLI();
})
describe('Authentication Integration Tests', () => {
authTestsService();
authTests();
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/utils/mocha-global-setup-native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { runCommand } from "@oclif/test";
import { expect } from "chai";

import { authInfo } from '../../src/services/synchronizationClient/models/connection-auth';
import { nativeLoginToCli } from "./helpers";

export async function mochaGlobalSetup() {
await nativeLoginToCli();
const { result } = await runCommand<authInfo>(`imodel connection auth`);
Comment thread
linasburneika marked this conversation as resolved.
expect(result?.isUserAuthorized).to.be.equal(true);
console.log("\n\nRunning tests with native client")
}
7 changes: 7 additions & 0 deletions integration-tests/utils/mocha-global-setup-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { logoutFromCLI, serviceLoginToCli } from "./helpers";

export async function mochaGlobalSetup() {
await logoutFromCLI();
await serviceLoginToCli();
console.log("\n\nRunning tests with service client")
}
Loading