Skip to content

Commit ca95ca3

Browse files
authored
Restore access-control integration tests (#207)
* npm audit fix * Restored part of access-control integration tests. Removed duplicate tests from mocked integration tests.
1 parent 286b34e commit ca95ca3

12 files changed

Lines changed: 558 additions & 400 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@
66
import runTestSuiteIfMainModule from "../../utils/run-suite-if-main-module";
77
import groupMemberTests from "./group.test";
88
import invitationsMemberTests from "./invitations.test";
9+
import ownerMemberTests from "./owner.test";
10+
import userMemberTests from "./user.test";
911

1012
const tests = () => {
1113
describe("group", () => {
1214
groupMemberTests();
1315
});
1416

17+
describe("user", () => {
18+
userMemberTests();
19+
});
20+
1521
describe("invitations", () => {
1622
invitationsMemberTests();
1723
});
24+
25+
describe("owner", () => {
26+
ownerMemberTests();
27+
});
1828
};
1929

2030
export default tests;
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 { expect } from "chai";
7+
8+
import { ITwin } from "@itwin/itwins-client";
9+
import { runCommand } from "@oclif/test";
10+
11+
import { OwnerMember, OwnerMemberResponse } from "../../../src/services/access-control/models/owner-member";
12+
import { ResultResponse } from "../../../src/services/general-models/result-response.js";
13+
import { User } from "../../../src/services/users/models/user";
14+
import runSuiteIfMainModule from "../../utils/run-suite-if-main-module";
15+
16+
const tests = () => {
17+
let iTwinId: string;
18+
const iTwinName: string = `cli-itwin-integration-test-${new Date().toISOString()}`;
19+
20+
before(async () => {
21+
const { result: iTwin } = await runCommand<ITwin>(`itwin create --class Thing --sub-class Asset --name ${iTwinName}`);
22+
expect(iTwin?.id).to.not.be.undefined;
23+
iTwinId = iTwin!.id!;
24+
});
25+
26+
after(async () => {
27+
const { result: deleteResult } = await runCommand<ResultResponse>(`itwin delete --itwin-id ${iTwinId}`);
28+
expect(deleteResult).to.have.property("result", "deleted");
29+
});
30+
31+
it("Should list owners of an iTwin", async () => {
32+
const { result: owners } = await runCommand<OwnerMember[]>(`access-control member owner list --itwin-id ${iTwinId}`);
33+
expect(owners).to.not.be.undefined;
34+
expect(owners!.length).to.be.greaterThanOrEqual(1);
35+
36+
const { result: userInfo } = await runCommand<User>(`user me`);
37+
expect(userInfo).to.not.be.undefined;
38+
expect(userInfo!.id).to.not.be.undefined;
39+
expect(owners!.some((owner) => owner.id === userInfo!.id)).to.be.true;
40+
});
41+
42+
it("Should return an error when invalid uuid is provided as --itwin-id", async () => {
43+
const { error: addError } = await runCommand<OwnerMember>(`access-control member owner add -i an-invalid-uuid --email [email protected]`);
44+
expect(addError?.message).to.contain("'an-invalid-uuid' is not a valid UUID.");
45+
46+
const { error: listError } = await runCommand<OwnerMember>(`access-control member owner list -i an-invalid-uuid`);
47+
expect(listError?.message).to.contain("'an-invalid-uuid' is not a valid UUID.");
48+
49+
const { error: deleteError } = await runCommand<ResultResponse>(
50+
`access-control member owner delete --itwin-id an-invalid-uuid --member-id ${crypto.randomUUID()}`,
51+
);
52+
expect(deleteError?.message).to.contain("'an-invalid-uuid' is not a valid UUID.");
53+
});
54+
55+
it("Should return an error when invalid uuid is provided as --member-id", async () => {
56+
const { error: deleteError } = await runCommand<ResultResponse>(
57+
`access-control member owner delete --itwin-id ${crypto.randomUUID()} --member-id an-invalid-uuid`,
58+
);
59+
expect(deleteError?.message).to.contain("'an-invalid-uuid' is not a valid UUID.");
60+
});
61+
62+
it("Should return an error when invalid email is provided as --email", async () => {
63+
const { error: updateError } = await runCommand<OwnerMemberResponse>(`access-control member owner add -i ${crypto.randomUUID()} --email not-a-valid-email`);
64+
expect(updateError?.message).to.contain("'not-a-valid-email' is not a valid email.");
65+
});
66+
};
67+
68+
export default tests;
69+
70+
runSuiteIfMainModule(import.meta, () => describe("Access Control Member Owner Tests", () => tests()));

0 commit comments

Comments
 (0)