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 { ITwin } from "@itwin/itwins-client" ;
7+ import { runCommand } from '@oclif/test' ;
8+ import { expect } from 'chai' ;
9+
10+ const tests = ( ) => describe ( 'create' , ( ) => {
11+ let testITwinId : string ;
12+ let testITwinId2 : string ;
13+ let testITwinChildId : string ;
14+ const testITwinName1 = `IntegrationTestITwin_${ new Date ( ) . toISOString ( ) } ` ;
15+ const testITwinName2 = `OtherIntegrationTestITwin_${ new Date ( ) . toISOString ( ) } ` ;
16+ const testChildITwinName = `IntegrationTestITwinChild_${ new Date ( ) . toISOString ( ) } ` ;
17+ const testClass = 'Thing' ;
18+ const testSubClass = 'Asset' ;
19+ const testGeographicLocation = 'San Francisco, CA'
20+ const testDataCenterLocation = 'UK South'
21+ const testStatus = 'Inactive'
22+ const testIanaTimeZone = 'America/Los_Angeles'
23+ const testType = 'Type1'
24+ const testNumber = Math . random ( ) . toString ( 36 ) . slice ( 2 )
25+
26+ after ( async ( ) => {
27+ await runCommand ( `itwin delete --itwin-id ${ testITwinChildId } ` ) ;
28+ await runCommand ( `itwin delete --itwin-id ${ testITwinId } ` ) ;
29+ await runCommand ( `itwin delete --itwin-id ${ testITwinId2 } ` ) ;
30+ } )
31+
32+ it ( 'should create a new iTwin' , async ( ) => {
33+ const itwinJson = await runCommand ( `itwin create --name "${ testITwinName1 } " --class ${ testClass } --sub-class ${ testSubClass } --type ${ testType } --number ${ testNumber } ` ) ;
34+ const itwinObj : ITwin = JSON . parse ( itwinJson . stdout ) ;
35+ expect ( itwinObj ) . to . have . property ( 'id' ) ;
36+ expect ( itwinObj . displayName ) . to . be . equal ( testITwinName1 ) ;
37+ expect ( itwinObj . class ) . to . be . equal ( testClass ) ;
38+ expect ( itwinObj . subClass ) . to . be . equal ( testSubClass ) ;
39+ expect ( itwinObj . type ) . to . be . equal ( testType ) ;
40+ expect ( itwinObj . number ) . to . be . equal ( testNumber ) ;
41+ testITwinId = itwinObj . id ! ;
42+ } ) ;
43+
44+ it ( 'should create a new child iTwin' , async ( ) => {
45+ const itwinChildJson = await runCommand ( `itwin create --name "${ testChildITwinName } " --class ${ testClass } --sub-class ${ testSubClass } --parent-id ${ testITwinId } --status ${ testStatus } ` ) ;
46+ const itwinChildObj : ITwin = JSON . parse ( itwinChildJson . stdout ) ;
47+ expect ( itwinChildObj ) . to . have . property ( 'id' ) ;
48+ expect ( itwinChildObj . displayName ) . to . be . equal ( testChildITwinName ) ;
49+ expect ( itwinChildObj . class ) . to . be . equal ( testClass ) ;
50+ expect ( itwinChildObj . subClass ) . to . be . equal ( testSubClass ) ;
51+ expect ( itwinChildObj . parentId ) . to . be . equal ( testITwinId ) ;
52+ expect ( itwinChildObj . status ) . to . be . equal ( testStatus ) ;
53+ testITwinChildId = itwinChildObj . id ! ;
54+ } ) ;
55+
56+ it ( 'should create a new iTwin with location information' , async ( ) => {
57+ const itwinJson = await runCommand ( `itwin create --name "${ testITwinName2 } " --class ${ testClass } --sub-class ${ testSubClass } --data-center-location "${ testDataCenterLocation } " --iana-time-zone ${ testIanaTimeZone } --geographic-location "${ testGeographicLocation } "` ) ;
58+ const itwinObj : ITwin = JSON . parse ( itwinJson . stdout ) ;
59+ expect ( itwinObj ) . to . have . property ( 'id' ) ;
60+ expect ( itwinObj . displayName ) . to . be . equal ( testITwinName2 ) ;
61+ expect ( itwinObj . class ) . to . be . equal ( testClass ) ;
62+ expect ( itwinObj . subClass ) . to . be . equal ( testSubClass ) ;
63+ expect ( itwinObj . dataCenterLocation ) . to . be . equal ( testDataCenterLocation ) ;
64+ expect ( itwinObj . ianaTimeZone ) . to . be . equal ( testIanaTimeZone ) ;
65+ expect ( itwinObj . geographicLocation ) . to . be . equal ( testGeographicLocation ) ;
66+ testITwinId2 = itwinObj . id ! ;
67+ } ) ;
68+ } ) ;
69+
70+ export default tests ;
0 commit comments