Skip to content

Commit f940580

Browse files
authored
Add access-control command mocked integration tests (#209)
* Added remaining mocked integration tests for 'access-control' commands. * Added mocked integration tests for 'access-control member group' commands. * Removed all references of ITP_TEST_USER_SAMEORG and ITP_TEST_USER_EXTERNAL from the project. * Added missing copyright notice to a file.
1 parent f5a75ac commit f940580

34 files changed

Lines changed: 1370 additions & 21 deletions

.github/workflows/ci.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ jobs:
9696
ITP_ISSUER_URL: ${{ vars.ITP_ISSUER_URL }}
9797
ITP_SERVICE_CLIENT_ID: ${{ vars.ITP_SERVICE_CLIENT_ID }}
9898
ITP_SERVICE_CLIENT_SECRET: ${{ secrets.ITP_SERVICE_CLIENT_SECRET }}
99-
ITP_TEST_USER_SAMEORG: ${{ vars.ITP_TEST_USER_SAMEORG }}
100-
ITP_TEST_USER_EXTERNAL: ${{ vars.ITP_TEST_USER_EXTERNAL }}
10199

102100
test_native:
103101
name: Tests (Native Client)
@@ -130,8 +128,6 @@ jobs:
130128
ITP_NATIVE_TEST_CLIENT_ID: ${{ vars.ITP_NATIVE_TEST_CLIENT_ID }}
131129
ITP_TEST_USER_EMAIL: ${{ vars.ITP_TEST_USER_EMAIL }}
132130
ITP_TEST_USER_PASSWORD: ${{ secrets.ITP_TEST_USER_PASSWORD }}
133-
ITP_TEST_USER_SAMEORG: ${{ vars.ITP_TEST_USER_SAMEORG }}
134-
ITP_TEST_USER_EXTERNAL: ${{ vars.ITP_TEST_USER_EXTERNAL }}
135131
test_mocked:
136132
name: Tests (Mocked HTTP traffic)
137133
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ ITP_NATIVE_TEST_CLIENT_ID=
5151
# Email and password of a test user. (Belonging to an organization is needed by some of the tests)
5252
ITP_TEST_USER_EMAIL=
5353
ITP_TEST_USER_PASSWORD=
54-
# Mailinator email address, that belongs to the same organization as ITP_TEST_USER_EMAIL
55-
ITP_TEST_USER_SAMEORG=
56-
# Mailinator email address, that does not belong to the same organization as ITP_TEST_USER_EMAIL
57-
ITP_TEST_USER_EXTERNAL=
5854
```
5955

6056
#### **Install Dependencies**

integration-tests/access-control/group.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { runCommand } from "@oclif/test";
1010

1111
import { Group } from "../../src/services/access-control/models/group";
1212
import { ResultResponse } from "../../src/services/general-models/result-response.js";
13-
import { ITP_TEST_USER_SAMEORG } from "../utils/environment";
1413
import runSuiteIfMainModule from "../utils/run-suite-if-main-module";
1514

1615
const tests = () => {
@@ -51,17 +50,15 @@ const tests = () => {
5150

5251
const updatedGroupName = "Updated Group Name";
5352
const updatedGroupDescription = "Updated Group Description";
54-
const memberEmail = ITP_TEST_USER_SAMEORG;
5553

5654
const { result: groupUpdate } = await runCommand<Group>(
57-
`access-control group update --itwin-id ${iTwinId} --group-id ${groupCreate!.id} --name "${updatedGroupName}" --description "${updatedGroupDescription}" --member ${memberEmail}`,
55+
`access-control group update --itwin-id ${iTwinId} --group-id ${groupCreate!.id} --name "${updatedGroupName}" --description "${updatedGroupDescription}"`,
5856
);
5957
expect(groupUpdate).to.not.be.undefined;
6058
expect(groupUpdate!.id).to.not.be.undefined;
6159
expect(groupUpdate!.name).to.be.equal(updatedGroupName);
6260
expect(groupUpdate!.description).to.be.equal(updatedGroupDescription);
6361
expect(groupUpdate!.members).to.not.be.undefined;
64-
expect(groupUpdate!.members!.some((member) => member.email.toLowerCase() === memberEmail!.toLowerCase())).to.be.true;
6562
});
6663

6764
it("Should list groups", async () => {

integration-tests/access-control/member/invitations.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { runCommand } from "@oclif/test";
1111
import { Invitation } from "../../../src/services/access-control/models/invitations";
1212
import { OwnerMemberResponse } from "../../../src/services/access-control/models/owner-member";
1313
import { ResultResponse } from "../../../src/services/general-models/result-response.js";
14-
import { ITP_TEST_USER_EXTERNAL } from "../../utils/environment";
1514
import runSuiteIfMainModule from "../../utils/run-suite-if-main-module";
1615

1716
const tests = () => {
@@ -30,17 +29,17 @@ const tests = () => {
3029
});
3130

3231
it("Should get pending invitations", async () => {
33-
const emailToAdd = ITP_TEST_USER_EXTERNAL;
32+
const emailToAdd = "email@example.com";
3433
const { result: owner } = await runCommand<OwnerMemberResponse>(`access-control member owner add --itwin-id ${iTwinId} --email ${emailToAdd}`);
3534
expect(owner).to.not.be.undefined;
3635
expect(owner!.member).is.null;
3736
expect(owner!.invitation).to.not.be.null;
38-
expect(owner!.invitation!.email.toLowerCase()).to.equal(emailToAdd!.toLowerCase());
37+
expect(owner!.invitation!.email.toLowerCase()).to.equal(emailToAdd.toLowerCase());
3938

4039
const { result: invitationResults } = await runCommand<Invitation[]>(`access-control member invitations --itwin-id ${iTwinId}`);
4140
expect(invitationResults).to.not.be.undefined;
4241
expect(invitationResults!.length).to.be.greaterThanOrEqual(1);
43-
expect(invitationResults!.some((invitation) => invitation.email.toLowerCase() === emailToAdd!.toLowerCase())).to.be.true;
42+
expect(invitationResults!.some((invitation) => invitation.email.toLowerCase() === emailToAdd.toLowerCase())).to.be.true;
4443
});
4544
};
4645

integration-tests/utils/environment.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ export const {
1414
ITP_SERVICE_CLIENT_ID,
1515
ITP_SERVICE_CLIENT_SECRET,
1616
ITP_TEST_USER_EMAIL,
17-
ITP_TEST_USER_EXTERNAL,
1817
ITP_TEST_USER_PASSWORD,
19-
ITP_TEST_USER_SAMEORG,
2018
} = process.env;

mocked-integration-tests/access-control/access-control.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import runSuiteIfMainModule from "../../integration-tests/utils/run-suite-if-main-module";
7+
import groupTests from "./group/group.test";
78
import memberTests from "./member/member.test";
9+
import permissionsTests from "./permissions.test";
810

911
const tests = () =>
1012
describe("access-control", () => {
13+
groupTests();
1114
memberTests();
15+
permissionsTests();
1216
});
1317

1418
export default tests;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 { expect } from "chai";
7+
8+
import { runCommand } from "@oclif/test";
9+
10+
import runSuiteIfMainModule from "../../../integration-tests/utils/run-suite-if-main-module.js";
11+
import { Group } from "../../../src/services/access-control/models/group.js";
12+
import { AccessControlApiMock } from "../../utils/api-mocks/access-control-api/access-control-api-mock.js";
13+
14+
const tests = () =>
15+
describe("add", () => {
16+
const iTwinId = crypto.randomUUID();
17+
18+
it("should create a group", async () => {
19+
const groupName = "Test Group";
20+
const groupDescription = "Test Group Description";
21+
22+
const response = AccessControlApiMock.groups.createiTwinGroup.success(iTwinId, groupName, groupDescription);
23+
24+
const { result: groupCreate } = await runCommand<Group>(
25+
`access-control group create --itwin-id ${iTwinId} --name "${groupName}" --description "${groupDescription}"`,
26+
);
27+
expect(groupCreate).to.not.be.undefined;
28+
expect(groupCreate).to.be.deep.equal(response.group);
29+
});
30+
31+
it("should return an error, when provided iTwin is not found", async () => {
32+
const groupName = "Test Group";
33+
const groupDescription = "Test Group Description";
34+
35+
const response = AccessControlApiMock.groups.createiTwinGroup.iTwinNotFound(iTwinId, groupName, groupDescription);
36+
37+
const { error: createError } = await runCommand<Group>(
38+
`access-control group create --itwin-id ${iTwinId} --name "${groupName}" --description "${groupDescription}"`,
39+
);
40+
expect(createError).to.not.be.undefined;
41+
expect(createError?.message).to.be.equal(`HTTP error! ${JSON.stringify(response)}`);
42+
});
43+
});
44+
45+
export default tests;
46+
47+
runSuiteIfMainModule(import.meta, tests);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 { expect } from "chai";
7+
8+
import { runCommand } from "@oclif/test";
9+
10+
import runSuiteIfMainModule from "../../../integration-tests/utils/run-suite-if-main-module.js";
11+
import { ResultResponse } from "../../../src/services/general-models/result-response.js";
12+
import { AccessControlApiMock } from "../../utils/api-mocks/access-control-api/access-control-api-mock.js";
13+
14+
const tests = () =>
15+
describe("delete", () => {
16+
const iTwinId = crypto.randomUUID();
17+
const groupId = crypto.randomUUID();
18+
19+
it("should delete group", async () => {
20+
AccessControlApiMock.groups.deleteiTwinGroup.success(iTwinId, groupId);
21+
22+
const { result: deleteResult } = await runCommand<ResultResponse>(`access-control group delete --itwin-id ${iTwinId} --group-id ${groupId}`);
23+
expect(deleteResult).to.have.property("result", "deleted");
24+
});
25+
26+
it("should return an error when iTwin is not found", async () => {
27+
const response = AccessControlApiMock.groups.deleteiTwinGroup.iTwinNotFound(iTwinId, groupId);
28+
29+
const { error: deleteError } = await runCommand<ResultResponse>(`access-control group delete --itwin-id ${iTwinId} --group-id ${groupId}`);
30+
expect(deleteError).to.not.be.undefined;
31+
expect(deleteError?.message).to.be.equal(`HTTP error! ${JSON.stringify(response)}`);
32+
});
33+
34+
it("should return an error when group is not found", async () => {
35+
const response = AccessControlApiMock.groups.deleteiTwinGroup.groupNotFound(iTwinId, groupId);
36+
37+
const { error: deleteError } = await runCommand<ResultResponse>(`access-control group delete --itwin-id ${iTwinId} --group-id ${groupId}`);
38+
expect(deleteError).to.not.be.undefined;
39+
expect(deleteError?.message).to.be.equal(`HTTP error! ${JSON.stringify(response)}`);
40+
});
41+
});
42+
43+
export default tests;
44+
45+
runSuiteIfMainModule(import.meta, tests);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 runSuiteIfMainModule from "../../../integration-tests/utils/run-suite-if-main-module";
7+
import addTests from "./add.test";
8+
import deleteTests from "./delete.test";
9+
import infoTests from "./info.test";
10+
import listTests from "./list.test";
11+
import updateTests from "./update.test";
12+
13+
const tests = () =>
14+
describe("group", () => {
15+
addTests();
16+
deleteTests();
17+
infoTests();
18+
listTests();
19+
updateTests();
20+
});
21+
22+
export default tests;
23+
24+
runSuiteIfMainModule(import.meta, tests);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 { expect } from "chai";
7+
8+
import { runCommand } from "@oclif/test";
9+
10+
import runSuiteIfMainModule from "../../../integration-tests/utils/run-suite-if-main-module.js";
11+
import { ResultResponse } from "../../../src/services/general-models/result-response.js";
12+
import { AccessControlApiMock } from "../../utils/api-mocks/access-control-api/access-control-api-mock.js";
13+
14+
const tests = () =>
15+
describe("info", () => {
16+
const iTwinId = crypto.randomUUID();
17+
const groupId = crypto.randomUUID();
18+
19+
it("should get group", async () => {
20+
const response = AccessControlApiMock.groups.getiTwinGroup.success(iTwinId, groupId);
21+
22+
const { result: deleteResult } = await runCommand<ResultResponse>(`access-control group info --itwin-id ${iTwinId} --group-id ${groupId}`);
23+
expect(deleteResult).to.not.be.undefined;
24+
expect(deleteResult).to.be.deep.equal(response.group);
25+
});
26+
27+
it("should return an error when iTwin is not found", async () => {
28+
const response = AccessControlApiMock.groups.getiTwinGroup.iTwinNotFound(iTwinId, groupId);
29+
30+
const { error: deleteError } = await runCommand<ResultResponse>(`access-control group info --itwin-id ${iTwinId} --group-id ${groupId}`);
31+
expect(deleteError).to.not.be.undefined;
32+
expect(deleteError?.message).to.be.equal(`HTTP error! ${JSON.stringify(response)}`);
33+
});
34+
35+
it("should return an error when group is not found", async () => {
36+
const response = AccessControlApiMock.groups.getiTwinGroup.groupNotFound(iTwinId, groupId);
37+
38+
const { error: deleteError } = await runCommand<ResultResponse>(`access-control group info --itwin-id ${iTwinId} --group-id ${groupId}`);
39+
expect(deleteError).to.not.be.undefined;
40+
expect(deleteError?.message).to.be.equal(`HTTP error! ${JSON.stringify(response)}`);
41+
});
42+
});
43+
44+
export default tests;
45+
46+
runSuiteIfMainModule(import.meta, tests);

0 commit comments

Comments
 (0)