Skip to content

Commit 99e7e9c

Browse files
authored
Added setup for native client tests and added a few tests, utilizing it. (#115)
* Added setup for native client tests and added a few tests, utilizing it. A few minor adjustments to member invitation tests helper.
1 parent 2cf725a commit 99e7e9c

18 files changed

Lines changed: 1194 additions & 25 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ jobs:
5050
ITP_SERVICE_CLIENT_ID: ${{ vars.ITP_SERVICE_CLIENT_ID }}
5151
ITP_SERVICE_CLIENT_SECRET: ${{ secrets.ITP_SERVICE_CLIENT_SECRET }}
5252
ITP_MAILINATOR_API_KEY: ${{ secrets.ITP_MAILINATOR_API_KEY }}
53+
ITP_NATIVE_TEST_CLIENT_ID: ${{ vars.ITP_NATIVE_TEST_CLIENT_ID }}
54+
ITP_TEST_USER_EMAIL: ${{ vars.ITP_TEST_USER_EMAIL }}
55+
ITP_TEST_USER_PASSWORD: ${{ secrets.ITP_TEST_USER_PASSWORD }}
5356
run: npm run test

integration-tests/auth/auth.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { runCommand } from '@oclif/test';
77
import { expect } from 'chai';
88

99
import { authorizationInformation } from "../../src/services/authorization-client/authorization-type";
10-
import { loginToCli } from '../utils/helpers';
10+
import { serviceLoginToCli } from '../utils/helpers';
1111

1212
describe('Authentication Integration Tests', () => {
1313
it('should log in successfully using service authentication', async () => {
14-
await loginToCli();
14+
await serviceLoginToCli();
1515
});
1616

1717
it('should return auth info', async () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { loginToCli } from "../utils/helpers";
6+
import { serviceLoginToCli } from "../utils/helpers";
77
import changesetsComparisonTests from "./changesets-comparison";
88
import enableDisableInfoTests from "./enable-disable-info";
99

1010
describe('Changed Elements Integration Tests', () => {
1111
beforeEach(async () => {
12-
await loginToCli();
12+
await serviceLoginToCli();
1313
});
1414

1515
enableDisableInfoTests();

integration-tests/context.ts/context.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { ITwin } from "@itwin/itwins-client";
33
import { runCommand } from "@oclif/test";
44
import { expect } from "chai";
55

6-
import { loginToCli } from "../utils/helpers";
6+
import { serviceLoginToCli } from "../utils/helpers";
77

88
describe('Context Integration Tests', () => {
99
let iTwin: ITwin;
1010
let iModel: IModel;
1111
let anotherITwin: ITwin;
1212

1313
before(async () => {
14-
await loginToCli();
14+
await serviceLoginToCli();
1515
const name = `IntegrationTestITwin_${new Date().toISOString()}`;
1616
const iTwinResult = await runCommand<ITwin>(`itwin create --name "${name}" --class Thing --sub-class Asset`);
1717
expect(iTwinResult.error).to.be.undefined;

integration-tests/imodel/imodel.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { loginToCli } from "../utils/helpers";
6+
import { serviceLoginToCli } from "../utils/helpers";
77
import connectionTests from './connection';
88
import createDeleteTests from "./create-delete";
99
import infoTests from "./info";
@@ -12,7 +12,7 @@ import updateTests from "./update";
1212

1313
describe('iModel Integration Tests', () => {
1414
beforeEach(async () => {
15-
await loginToCli();
15+
await serviceLoginToCli();
1616
});
1717

1818
createDeleteTests();

integration-tests/itwin/itwin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { loginToCli } from "../utils/helpers";
6+
import { serviceLoginToCli } from "../utils/helpers";
77
import createTests from "./create";
88
import deleteTests from './delete';
99
import infoTests from "./info";
@@ -13,7 +13,7 @@ import updateTests from "./update";
1313

1414
describe('iTwin Integration Tests', () => {
1515
beforeEach(async () => {
16-
await loginToCli();
16+
await serviceLoginToCli();
1717
});
1818

1919
createTests();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 memberTests from './member/member.test'
7+
8+
export default () => describe('access-control', () => {
9+
memberTests();
10+
});
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 ownerTests from './owner.test';
7+
import userTests from './user.test'
8+
9+
export default () => describe('member', () => {
10+
userTests();
11+
ownerTests();
12+
});
13+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 { groupMember } from "../../../../src/services/access-control-client/models/group-members.js";
11+
import { ownerResponse } from "../../../../src/services/access-control-client/models/owner.js";
12+
import { nativeLoginToCli } from "../../../utils/helpers";
13+
14+
export default () => describe('owner', () => {
15+
let iTwinId: string;
16+
const iTwinName: string = `cli-itwin-integration-test-${new Date().toISOString()}`;
17+
18+
before(async () => {
19+
await nativeLoginToCli();
20+
21+
const iTwin = await runCommand<ITwin>(`itwin create --class Thing --sub-class Asset --name ${iTwinName}`);
22+
expect(iTwin.result?.id).is.not.undefined;
23+
iTwinId = iTwin.result!.id!;
24+
});
25+
26+
after(async () => {
27+
const result = await runCommand(`itwin delete --itwin-id ${iTwinId}`);
28+
expect(result.stdout).to.contain('deleted');
29+
});
30+
31+
it('Should add an internal member to an iTwin and remove owner member', async () => {
32+
const emailToAdd = '[email protected]';
33+
34+
const invitedUser = await runCommand<ownerResponse>(`access-control member owner add --itwin-id ${iTwinId} --email ${emailToAdd}`);
35+
36+
expect(invitedUser.result).to.not.be.undefined;
37+
expect(invitedUser.result!.member).to.not.be.undefined;
38+
expect(invitedUser.result!.member.email.toLowerCase()).to.be.equal(emailToAdd.toLowerCase());
39+
40+
const usersInfo = await runCommand<groupMember[]>(`access-control member owner list --itwin-id ${iTwinId}`);
41+
expect(usersInfo.result).is.not.undefined;
42+
expect(usersInfo.result!.length).to.be.equal(2);
43+
const joinedUser = usersInfo.result?.filter(user => user.email.toLowerCase() === emailToAdd.toLowerCase())[0];
44+
expect(joinedUser).to.not.be.undefined;
45+
46+
const deletionResult = await runCommand<{result: string}>(`access-control member owner delete --itwin-id ${iTwinId} --member-id ${joinedUser?.id}`);
47+
expect(deletionResult.result).to.not.be.undefined;
48+
expect(deletionResult.result!.result).to.be.equal("deleted");
49+
});
50+
});
51+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 { member, membersResponse } from "../../../../src/services/access-control-client/models/members";
11+
import { Role } from "../../../../src/services/access-control-client/models/role";
12+
import { nativeLoginToCli } from "../../../utils/helpers";
13+
14+
const tests = () => describe('user', () => {
15+
let iTwinId: string;
16+
const iTwinName: string = `cli-itwin-integration-test-${new Date().toISOString()}`;
17+
18+
before(async () => {
19+
await nativeLoginToCli();
20+
21+
const iTwin = await runCommand<ITwin>(`itwin create --class Thing --sub-class Asset --name ${iTwinName}`);
22+
expect(iTwin.result?.id, "itwin create result").is.not.undefined;
23+
iTwinId = iTwin.result!.id!;
24+
});
25+
26+
after(async () => {
27+
const result = await runCommand(`itwin delete --itwin-id ${iTwinId}`);
28+
expect(result.stdout).to.contain('deleted');
29+
});
30+
31+
it('Should add an internal member to an iTwin and remove user member', async () => {
32+
const newRole = await runCommand<Role>(`access-control role create -i ${iTwinId} -n "Test Role 1" -d "Test Role Description"`);
33+
expect(newRole.result).is.not.undefined;
34+
expect(newRole.result!.id).is.not.undefined;
35+
36+
const emailToAdd = '[email protected]';
37+
38+
const invitedUser = await runCommand<membersResponse>(`access-control member user add --itwin-id ${iTwinId} --members "[{"email": "${emailToAdd}", "roleIds": ["${newRole.result!.id}"]}]"`);
39+
40+
expect(invitedUser.result).to.not.be.undefined;
41+
expect(invitedUser.result!.members.length).to.be.equal(1);
42+
expect(invitedUser.result!.members[0].email.toLowerCase()).to.be.equal(emailToAdd.toLowerCase());
43+
expect(invitedUser.result!.members[0].roles.length).to.be.equal(1);
44+
expect(invitedUser.result!.members[0].roles[0].id).to.be.equal(newRole.result!.id);
45+
46+
const usersInfo = await runCommand<member[]>(`access-control member user list --itwin-id ${iTwinId}`);
47+
expect(usersInfo.result).is.not.undefined;
48+
expect(usersInfo.result!.length).to.be.equal(2);
49+
const joinedUser = usersInfo.result?.filter(user => user.email.toLowerCase() === emailToAdd.toLowerCase())[0];
50+
expect(joinedUser).to.not.be.undefined;
51+
expect(joinedUser?.roles.length).to.be.equal(1);
52+
expect(joinedUser?.roles[0].id).to.be.equal(newRole.result!.id);
53+
54+
const deletionResult = await runCommand<{result: string}>(`access-control member user delete --itwin-id ${iTwinId} --member-id ${joinedUser?.id}`);
55+
expect(deletionResult.result).to.not.be.undefined;
56+
expect(deletionResult.result!.result).to.be.equal("deleted");
57+
});
58+
});
59+
60+
export default tests;

0 commit comments

Comments
 (0)