@@ -7,15 +7,16 @@ import { ITwin } from "@itwin/itwins-client";
77import { runCommand } from "@oclif/test" ;
88import { expect } from "chai" ;
99
10- import { member } from "../../../src/services/access-control-client/models/members" ;
10+ import { member , membersResponse } from "../../../src/services/access-control-client/models/members" ;
1111import { Role } from "../../../src/services/access-control-client/models/role" ;
1212import { User } from "../../../src/services/user-client/models/user" ;
13+ import { fetchEmailsAndGetInvitationLink } from "../../utils/helpers" ;
1314
1415const tests = ( ) => {
1516 let iTwinId : string ;
17+ const iTwinName : string = `cli-itwin-integration-test-${ new Date ( ) . toISOString ( ) } ` ;
1618
1719 before ( async ( ) => {
18- const iTwinName = `cli-itwin-integration-test-${ new Date ( ) . toISOString ( ) } ` ;
1920 const iTwin = await runCommand < ITwin > ( `itwin create --class Thing --sub-class Asset --name ${ iTwinName } ` ) ;
2021 expect ( iTwin . result ?. id ) . is . not . undefined ;
2122 iTwinId = iTwin . result ! . id ! ;
@@ -26,7 +27,39 @@ const tests = () => {
2627 expect ( result . stdout ) . to . contain ( 'deleted' ) ;
2728 } ) ;
2829
29- it ( 'Should dispaly owner info of an iTwin in member info' , async ( ) => {
30+ it ( 'Should invite an external member to an iTwin, accept sent invitation and remove user member' , async ( ) => {
31+ const newRole = await runCommand < Role > ( `access-control role create -i ${ iTwinId } -n "Test Role 1" -d "Test Role Description"` ) ;
32+ expect ( newRole . result ) . is . not . undefined ;
33+ expect ( newRole . result ! . id ) . is . not . undefined ;
34+
35+ const emailToAdd = 'iTwin.CLI.QA.IntegrationTest@bentley.m8r.co' ;
36+
37+ const invitedUser = await runCommand < membersResponse > ( `access-control member user add --itwin-id ${ iTwinId } --members "[{"email": "${ emailToAdd } ", "roleIds": ["${ newRole . result ! . id } "]}]"` ) ;
38+
39+ expect ( invitedUser . result ) . to . not . be . undefined ;
40+ expect ( invitedUser . result ! . invitations . length ) . to . be . equal ( 1 ) ;
41+ expect ( invitedUser . result ! . invitations [ 0 ] . email . toLowerCase ( ) ) . to . be . equal ( emailToAdd . toLowerCase ( ) ) ;
42+ expect ( invitedUser . result ! . invitations [ 0 ] . roles . length ) . to . be . equal ( 1 ) ;
43+ expect ( invitedUser . result ! . invitations [ 0 ] . roles [ 0 ] . id ) . to . be . equal ( newRole . result ! . id ) ;
44+
45+ const invitationLink = await fetchEmailsAndGetInvitationLink ( emailToAdd . split ( '@' ) [ 0 ] , iTwinName ) ;
46+
47+ await fetch ( invitationLink ) ;
48+
49+ const usersInfo = await runCommand < member [ ] > ( `access-control member user list --itwin-id ${ iTwinId } ` ) ;
50+ expect ( usersInfo . result ) . is . not . undefined ;
51+ expect ( usersInfo . result ! . length ) . to . be . equal ( 2 ) ;
52+ const joinedUser = usersInfo . result ?. filter ( user => user . email . toLowerCase ( ) === emailToAdd . toLowerCase ( ) ) [ 0 ] ;
53+ expect ( joinedUser ) . to . not . be . undefined ;
54+ expect ( joinedUser ?. roles . length ) . to . be . equal ( 1 ) ;
55+ expect ( joinedUser ?. roles [ 0 ] . id ) . to . be . equal ( newRole . result ! . id ) ;
56+
57+ const deletionResult = await runCommand < { result : string } > ( `access-control member user delete --itwin-id ${ iTwinId } --member-id ${ joinedUser ?. id } ` ) ;
58+ expect ( deletionResult . result ) . to . not . be . undefined ;
59+ expect ( deletionResult . result ! . result ) . to . be . equal ( "deleted" ) ;
60+ } ) ;
61+
62+ it ( 'Should display owner info of an iTwin in member info' , async ( ) => {
3063 const userInfo = await runCommand < User > ( `user me` ) ;
3164 expect ( userInfo . result ) . is . not . undefined ;
3265
@@ -37,7 +70,7 @@ const tests = () => {
3770 } ) ;
3871
3972 it ( 'Should add new member to an iTwin and update the role' , async ( ) => {
40- const newRole = await runCommand < Role > ( `access-control role create -i ${ iTwinId } -n "Test Role" -d "Test Role Description"` ) ;
73+ const newRole = await runCommand < Role > ( `access-control role create -i ${ iTwinId } -n "Test Role 2 " -d "Test Role Description"` ) ;
4174 expect ( newRole . result ) . is . not . undefined ;
4275 expect ( newRole . result ! . id ) . is . not . undefined ;
4376
0 commit comments