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 { IModel } from '@itwin/imodels-client-management' ;
7+ import { ITwin } from '@itwin/itwins-client' ;
8+ import { runCommand } from '@oclif/test' ;
9+ import { expect } from 'chai' ;
10+
11+ import { changeset , changesetComparison } from '../../src/services/changed-elements-client/tracking' ;
12+ import { createFile , createIModel , createITwin , getRootFolderId } from '../utils/helpers' ;
13+ import { resultResponse } from '../utils/result-response' ;
14+
15+ const tests = ( ) => describe ( 'changesets + comparison' , ( ) => {
16+ const testITwinName = 'ITwinCLI_IntegrationTestITwin_ChangedElements' ;
17+ const testIModelName = 'ITwinCLI_IntegrationTestIModel_ChangedElements' ;
18+ const testFileName = 'test.zip' ;
19+ const testFilePath = 'integration-tests/test.zip' ;
20+ let testIModelId : string ;
21+ let testITwinId : string ;
22+
23+ before ( async ( ) => {
24+ const filteredITwins = await runCommand < ITwin [ ] > ( `itwin list --name ${ testITwinName } ` ) ;
25+ expect ( filteredITwins . result ) . to . not . be . undefined
26+
27+ if ( filteredITwins . result ! . length === 0 ) {
28+ const testITwin = await createITwin ( testITwinName , 'Thing' , 'Asset' ) ;
29+ testITwinId = testITwin . id as string ;
30+ const testIModel = await createIModel ( testIModelName , testITwinId ) ;
31+ testIModelId = testIModel . id ;
32+
33+ await runCommand < resultResponse > ( `changed-elements enable --imodel-id ${ testIModelId } --itwin-id ${ testITwinId } ` ) ;
34+
35+ const rootFolderId = await getRootFolderId ( testITwinId ) ;
36+ await createFile ( rootFolderId , testFileName , testFilePath ) ;
37+ const result = await runCommand ( `imodel populate --imodel-id ${ testIModelId } --file ${ testFilePath } --connector-type SPPID` ) ;
38+ expect ( result . result ) . to . have . property ( 'iModelId' , testIModelId ) ;
39+ expect ( result . result ) . to . have . property ( 'iTwinId' , testITwinId ) ;
40+ }
41+ else {
42+ testITwinId = filteredITwins . result ! [ 0 ] . id ! ;
43+ const iModels = await runCommand < IModel [ ] > ( `imodel list --itwin-id ${ testITwinId } ` ) ;
44+ expect ( iModels . result ) . to . not . be . undefined ;
45+ expect ( iModels . result ?. length ) . to . be . equal ( 1 ) ;
46+ testIModelId = iModels . result ! [ 0 ] . id ;
47+ }
48+ } ) ;
49+
50+ it ( 'should get changesets' , async ( ) => {
51+ const response = await runCommand < changeset [ ] > ( `changed-elements changesets --imodel-id ${ testIModelId } --itwin-id ${ testITwinId } ` ) ;
52+ expect ( response . result ) . to . not . be . undefined ;
53+ expect ( response . result ?. length ) . to . be . equal ( 4 ) ;
54+
55+ const responseFiltered = await runCommand < changeset [ ] > ( `changed-elements changesets --imodel-id ${ testIModelId } --itwin-id ${ testITwinId } --skip 2 --top 2` ) ;
56+ expect ( responseFiltered . result ) . to . not . be . undefined ;
57+ expect ( responseFiltered . result ?. length ) . to . be . equal ( 2 ) ;
58+ expect ( responseFiltered . result ?. map ( x => x . id ) ) . to . be . deep . equal ( response . result ?. map ( x => x . id ) . slice ( 2 ) )
59+ } ) ;
60+
61+ it ( 'should compare 2 changesets' , async ( ) => {
62+ const response = await runCommand < changeset [ ] > ( `changed-elements changesets --imodel-id ${ testIModelId } --itwin-id ${ testITwinId } ` ) ;
63+ expect ( response . result ) . to . not . be . undefined ;
64+ expect ( response . result ?. length ) . to . be . equal ( 4 ) ;
65+
66+ const comparisonResponse = await runCommand < changesetComparison > ( `changed-elements comparison --imodel-id ${ testIModelId } --itwin-id ${ testITwinId } --changeset-id1 ${ response . result ! [ 0 ] . id } --changeset-id2 ${ response . result ! [ 3 ] . id } ` ) ;
67+ expect ( comparisonResponse . result ) . to . not . be . undefined ;
68+ expect ( comparisonResponse . result ! . opcodes . length ) . to . be . equal ( 1 ) ;
69+ expect ( comparisonResponse . result ! . opcodes [ 0 ] ) . to . be . equal ( 18 ) ; // Element was inserted
70+ } ) ;
71+ } ) ;
72+
73+ export default tests ;
0 commit comments