Skip to content

Commit fbcf033

Browse files
authored
Added missing integration tests for itwin, storage and auth commands. (#88)
* Added missing integration tests for itwin, storage and auth commands.
1 parent c3d086a commit fbcf033

28 files changed

Lines changed: 367 additions & 155 deletions

integration-tests/auth/auth.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66
import { runCommand } from '@oclif/test';
77
import { expect } from 'chai';
88

9+
import { authorizationInformation } from "../../src/services/authorization-client/authorization-type";
910
import { loginToCli } from '../utils/helpers';
1011

1112
describe('Authentication Integration Tests', () => {
1213
it('should log in successfully using service authentication', async () => {
1314
await loginToCli();
1415
});
1516

17+
it('should return auth info', async () => {
18+
const result = await runCommand<authorizationInformation>('auth info');
19+
expect(result.result).to.be.not.undefined;
20+
expect(result.result!.apiUrl).to.be.equal(process.env.ITP_API_URL);
21+
expect(result.result!.authorizationType).to.be.not.undefined;
22+
expect(result.result!.clientId).to.be.equal(process.env.ITP_SERVICE_CLIENT_ID);
23+
expect(result.result!.issuerUrl).to.be.equal(process.env.ITP_ISSUER_URL);
24+
});
25+
1626
it('should fail with incorrect credentials', async () => {
1727
const result = await runCommand('auth login --client-id invalid-id --client-secret wrong-secret');
1828
expect(result.error).to.be.not.undefined;

integration-tests/changed-elements/enable-disable-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const tests = () => describe('enable + disable + info', () => {
1717

1818
before(async () => {
1919
const testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
20-
testITwinId = testITwin.id;
20+
testITwinId = testITwin.id as string;
2121
const testIModel = await createIModel(testIModelName, testITwinId);
2222
testIModelId = testIModel.id;
2323
});

integration-tests/imodel/connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const tests = () => describe('connection', () => {
2020

2121
before(async () => {
2222
const testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
23-
testITwinId = testITwin.id;
23+
testITwinId = testITwin.id as string;
2424
const testIModel = await createIModel(testIModelName, testITwinId);
2525
testIModelId = testIModel.id;
2626
rootFolderId = await getRootFolderId(testITwinId);
2727
const testFile = await createFile(rootFolderId, testFileName, testFilePath);
28-
testFileId = testFile.id;
28+
testFileId = testFile.id as string;
2929
});
3030

3131
after(async () => {

integration-tests/imodel/create-delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const tests = () => describe('create + delete', () => {
1414

1515
before(async () => {
1616
const testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
17-
testITwinId = testITwin.id;
17+
testITwinId = testITwin.id as string;
1818
});
1919

2020
after(async () => {

integration-tests/imodel/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const tests = () => describe('info', () => {
1515

1616
before(async () => {
1717
const testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
18-
testITwinId = testITwin.id;
18+
testITwinId = testITwin.id as string;
1919
const testIModel = await createIModel(testIModelName, testITwinId);
2020
testIModelId = testIModel.id;
2121
});

integration-tests/imodel/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const tests = () => describe('list', () => {
1515

1616
before(async () => {
1717
const testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
18-
testITwinId = testITwin.id;
18+
testITwinId = testITwin.id as string;
1919
const testIModel = await createIModel(testIModelName, testITwinId);
2020
testIModelId = testIModel.id;
2121
});

integration-tests/imodel/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const tests = () => describe('update', () => {
1414

1515
before(async () => {
1616
const testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
17-
testITwinId = testITwin.id;
17+
testITwinId = testITwin.id as string;
1818
const testIModel = await createIModel('IntegrationTestIModel', testITwinId);
1919
testIModelId = testIModel.id;
2020
});

integration-tests/itwin/create-delete.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

integration-tests/itwin/create.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 { ITwin } from "@itwin/itwins-client";
7+
import { runCommand } from '@oclif/test';
8+
import { expect } from 'chai';
9+
10+
const tests = () => describe('create', () => {
11+
let testITwinId: string;
12+
let testITwinId2: string;
13+
let testITwinChildId: string;
14+
const testITwinName1 = `IntegrationTestITwin_${new Date().toISOString()}`;
15+
const testITwinName2 = `OtherIntegrationTestITwin_${new Date().toISOString()}`;
16+
const testChildITwinName = `IntegrationTestITwinChild_${new Date().toISOString()}`;
17+
const testClass = 'Thing';
18+
const testSubClass = 'Asset';
19+
const testGeographicLocation= 'San Francisco, CA'
20+
const testDataCenterLocation = 'UK South'
21+
const testStatus = 'Inactive'
22+
const testIanaTimeZone = 'America/Los_Angeles'
23+
const testType = 'Type1'
24+
const testNumber = Math.random().toString(36).slice(2)
25+
26+
after(async () => {
27+
await runCommand(`itwin delete --itwin-id ${testITwinChildId}`);
28+
await runCommand(`itwin delete --itwin-id ${testITwinId}`);
29+
await runCommand(`itwin delete --itwin-id ${testITwinId2}`);
30+
})
31+
32+
it('should create a new iTwin', async () => {
33+
const itwinJson = await runCommand(`itwin create --name "${testITwinName1}" --class ${testClass} --sub-class ${testSubClass} --type ${testType} --number ${testNumber}`);
34+
const itwinObj: ITwin = JSON.parse(itwinJson.stdout);
35+
expect(itwinObj).to.have.property('id');
36+
expect(itwinObj.displayName).to.be.equal(testITwinName1);
37+
expect(itwinObj.class).to.be.equal(testClass);
38+
expect(itwinObj.subClass).to.be.equal(testSubClass);
39+
expect(itwinObj.type).to.be.equal(testType);
40+
expect(itwinObj.number).to.be.equal(testNumber);
41+
testITwinId = itwinObj.id!;
42+
});
43+
44+
it('should create a new child iTwin', async () => {
45+
const itwinChildJson = await runCommand(`itwin create --name "${testChildITwinName}" --class ${testClass} --sub-class ${testSubClass} --parent-id ${testITwinId} --status ${testStatus}`);
46+
const itwinChildObj: ITwin = JSON.parse(itwinChildJson.stdout);
47+
expect(itwinChildObj).to.have.property('id');
48+
expect(itwinChildObj.displayName).to.be.equal(testChildITwinName);
49+
expect(itwinChildObj.class).to.be.equal(testClass);
50+
expect(itwinChildObj.subClass).to.be.equal(testSubClass);
51+
expect(itwinChildObj.parentId).to.be.equal(testITwinId);
52+
expect(itwinChildObj.status).to.be.equal(testStatus);
53+
testITwinChildId = itwinChildObj.id!;
54+
});
55+
56+
it('should create a new iTwin with location information', async () => {
57+
const itwinJson = await runCommand(`itwin create --name "${testITwinName2}" --class ${testClass} --sub-class ${testSubClass} --data-center-location "${testDataCenterLocation}" --iana-time-zone ${testIanaTimeZone} --geographic-location "${testGeographicLocation}"`);
58+
const itwinObj: ITwin = JSON.parse(itwinJson.stdout);
59+
expect(itwinObj).to.have.property('id');
60+
expect(itwinObj.displayName).to.be.equal(testITwinName2);
61+
expect(itwinObj.class).to.be.equal(testClass);
62+
expect(itwinObj.subClass).to.be.equal(testSubClass);
63+
expect(itwinObj.dataCenterLocation).to.be.equal(testDataCenterLocation);
64+
expect(itwinObj.ianaTimeZone).to.be.equal(testIanaTimeZone);
65+
expect(itwinObj.geographicLocation).to.be.equal(testGeographicLocation);
66+
testITwinId2 = itwinObj.id!;
67+
});
68+
});
69+
70+
export default tests;

integration-tests/itwin/delete.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 { ITwin } from "@itwin/itwins-client";
7+
import { runCommand } from '@oclif/test';
8+
import { expect } from 'chai';
9+
10+
import { createITwin } from "../utils/helpers";
11+
12+
const tests = () => describe('delete', () => {
13+
let testITwin: ITwin;
14+
15+
before(async () => {
16+
testITwin = await createITwin('IntegrationTestITwin', 'Thing', 'Asset');
17+
});
18+
19+
it('should delete the iTwin', async () => {
20+
const result = await runCommand(`itwin delete --itwin-id ${testITwin.id}`);
21+
const deleteResult = JSON.parse(result.stdout);
22+
expect(deleteResult).to.have.property('result', 'deleted');
23+
24+
const itwinChildResult = await runCommand(`itwin info --itwin-id ${testITwin.id}`);
25+
expect(itwinChildResult.error).to.be.not.undefined;
26+
expect(itwinChildResult.error!.message).to.include('iTwinNotFound');
27+
});
28+
});
29+
30+
export default tests;

0 commit comments

Comments
 (0)