@@ -9,15 +9,17 @@ import { ITwin } from "@itwin/itwins-client";
99import { runCommand } from "@oclif/test" ;
1010
1111import { ResultResponse } from "../../src/services/general-models/result-response" ;
12+ import { UserContext } from "../../src/services/general-models/user-context" ;
1213import { createITwin } from "../utils/helpers" ;
1314import runSuiteIfMainModule from "../utils/run-suite-if-main-module" ;
1415
1516const tests = ( ) =>
1617 describe ( "delete" , ( ) => {
18+ const testITwinName = `cli-itwin-integration-test-${ new Date ( ) . toISOString ( ) } ` ;
1719 let testITwin : ITwin ;
1820
1921 before ( async ( ) => {
20- testITwin = await createITwin ( `cli-itwin-integration-test- ${ new Date ( ) . toISOString ( ) } ` , "Thing" , "Asset" ) ;
22+ testITwin = await createITwin ( testITwinName , "Thing" , "Asset" ) ;
2123 } ) ;
2224
2325 it ( "should delete the iTwin" , async ( ) => {
@@ -29,6 +31,58 @@ const tests = () =>
2931 expect ( errorResult ! . message ) . to . include ( "iTwinNotFound" ) ;
3032 } ) ;
3133
34+ it ( "should clear context, when saved iTwin is deleted" , async ( ) => {
35+ const iTwinName = `${ testITwinName } -context-test1` ;
36+
37+ const { result : createdITwin } = await runCommand < ITwin > ( `itwin create --name "${ iTwinName } " --class Thing --sub-class Asset --save` ) ;
38+
39+ await runCommand < UserContext > ( `context set -i ${ createdITwin ! . id } ` ) ;
40+ const { result : contextBefore } = await runCommand < UserContext > ( `context info` ) ;
41+
42+ const { result : deleteResult } = await runCommand < ResultResponse > ( `itwin delete -i ${ createdITwin ?. id } ` ) ;
43+ const { result : contextAfter } = await runCommand < UserContext > ( `context info` ) ;
44+
45+ expect ( createdITwin ) . to . not . be . undefined ;
46+
47+ expect ( contextBefore ) . to . not . be . undefined ;
48+ expect ( contextBefore ?. iTwinId ) . to . be . equal ( createdITwin ?. id ) ;
49+ expect ( contextBefore ?. iModelId ) . to . be . undefined ;
50+
51+ expect ( deleteResult ) . to . not . be . undefined ;
52+ expect ( deleteResult ) . to . have . property ( "result" , "deleted" ) ;
53+ expect ( contextAfter ) . to . be . undefined ;
54+ } ) ;
55+
56+ it ( "should not clear context, when a different iTwin is deleted" , async ( ) => {
57+ const iTwinName1 = `${ testITwinName } -context-test1` ;
58+ const iTwinName2 = `${ testITwinName } -context-test2` ;
59+
60+ const { result : createdITwin1 } = await runCommand < ITwin > ( `itwin create --name "${ iTwinName1 } " --class Thing --sub-class Asset --save` ) ;
61+ const { result : createdITwin2 } = await runCommand < ITwin > ( `itwin create --name "${ iTwinName2 } " --class Thing --sub-class Asset --save` ) ;
62+
63+ await runCommand < UserContext > ( `context set -i ${ createdITwin1 ! . id } ` ) ;
64+ const { result : contextBefore } = await runCommand < UserContext > ( `context info` ) ;
65+
66+ const { result : deleteResult2 } = await runCommand < ResultResponse > ( `itwin delete -i ${ createdITwin2 ?. id } ` ) ;
67+ const { result : contextAfter } = await runCommand < UserContext > ( `context info` ) ;
68+ const { result : deleteResult1 } = await runCommand < ResultResponse > ( `itwin delete -i ${ createdITwin1 ?. id } ` ) ;
69+
70+ expect ( createdITwin1 ) . to . not . be . undefined ;
71+ expect ( createdITwin2 ) . to . not . be . undefined ;
72+
73+ expect ( contextBefore ) . to . not . be . undefined ;
74+ expect ( contextBefore ?. iTwinId ) . to . be . equal ( createdITwin1 ?. id ) ;
75+ expect ( contextBefore ?. iModelId ) . to . be . undefined ;
76+
77+ expect ( deleteResult2 ) . to . not . be . undefined ;
78+ expect ( deleteResult2 ) . to . have . property ( "result" , "deleted" ) ;
79+ expect ( contextAfter ) . to . not . be . undefined ;
80+ expect ( contextAfter ?. iTwinId ) . to . be . equal ( createdITwin1 ?. id ) ;
81+ expect ( contextAfter ?. iModelId ) . to . be . undefined ;
82+ expect ( deleteResult1 ) . to . not . be . undefined ;
83+ expect ( deleteResult1 ) . to . have . property ( "result" , "deleted" ) ;
84+ } ) ;
85+
3286 it ( "should return an error when invalid uuid is provided as --itwin-id" , async ( ) => {
3387 const { error } = await runCommand < ITwin > ( `itwin delete --itwin-id an-invalid-uuid` ) ;
3488 expect ( error ?. message ) . to . contain ( "'an-invalid-uuid' is not a valid UUID." ) ;
0 commit comments