import { When } from "@cucumber/cucumber" ; import { AttributeType } from "../../../../../dist" ; import { tx } from "../../../connection/ConnectionStepsBase" ; import { assertThrows } from "../../../util/Util" ; import { get , put } from "../ThingSteps" ; import assert = require ( "assert" ) ; When ( "{var} = entity\\({type_label}) create new instance" , async ( var0 , typeLabel ) => { put ( var0 , await ( await tx ( ) . concepts . getEntityType ( typeLabel ) ) . asRemote ( tx ( ) ) . create ( ) ) ; } ) ; When ( "entity\\({type_label}) create new instance; throws exception" , async ( typeLabel ) => { await assertThrows ( async ( ) => await ( await tx ( ) . concepts . getEntityType ( typeLabel ) ) . asRemote ( tx ( ) ) . create ( ) ) ; } ) ; When ( "{var} = entity\\({type_label}) create new instance with key\\({type_label}): {bool}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asBoolean ( ) ) . asRemote ( tx ( ) ) . put ( value ) ; const entity = await ( await tx ( ) . concepts . getEntityType ( thingTypeLabel ) ) . asRemote ( tx ( ) ) . create ( ) ; await entity . asRemote ( tx ( ) ) . setHas ( key ) ; put ( thingName , entity ) ; } ) ; When ( "{var} = entity\\({type_label}) create new instance with key\\({type_label}): {int}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asLong ( ) ) . asRemote ( tx ( ) ) . put ( value ) ; const entity = await ( await tx ( ) . concepts . getEntityType ( thingTypeLabel ) ) . asRemote ( tx ( ) ) . create ( ) ; await entity . asRemote ( tx ( ) ) . setHas ( key ) ; put ( thingName , entity ) ; } ) ; When ( "{var} = entity\\({type_label}) create new instance with key\\({type_label}): {word}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asString ( ) ) . asRemote ( tx ( ) ) . put ( value ) ; const entity = await ( await tx ( ) . concepts . getEntityType ( thingTypeLabel ) ) . asRemote ( tx ( ) ) . create ( ) ; await entity . asRemote ( tx ( ) ) . setHas ( key ) ; put ( thingName , entity ) ; } ) ; When ( "{var} = entity\\({type_label}) create new instance with key\\({type_label}): {datetime}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asDateTime ( ) ) . asRemote ( tx ( ) ) . put ( value ) ; const entity = await ( await tx ( ) . concepts . getEntityType ( thingTypeLabel ) ) . asRemote ( tx ( ) ) . create ( ) ; await entity . asRemote ( tx ( ) ) . setHas ( key ) ; put ( thingName , entity ) ; } ) ; When ( "{var} = entity\\({type_label}) get instance with key\\({type_label}): {bool}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asBoolean ( ) ) . asRemote ( tx ( ) ) . get ( value ) ; for await ( const owner of key . asRemote ( tx ( ) ) . getOwners ( ) ) { if ( owner . type . label . scopedName === thingTypeLabel ) { put ( thingName , owner ) ; return ; } } put ( thingName , null ) ; } ) ; When ( "{var} = entity\\({type_label}) get instance with key\\({type_label}): {int}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asLong ( ) ) . asRemote ( tx ( ) ) . get ( value ) ; for await ( const owner of key . asRemote ( tx ( ) ) . getOwners ( ) ) { if ( owner . type . label . scopedName === thingTypeLabel ) { put ( thingName , owner ) ; return ; } } put ( thingName , null ) ; } ) ; When ( "{var} = entity\\({type_label}) get instance with key\\({type_label}): {word}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asString ( ) ) . asRemote ( tx ( ) ) . get ( value ) ; for await ( const owner of key . asRemote ( tx ( ) ) . getOwners ( ) ) { if ( owner . type . label . scopedName === thingTypeLabel ) { put ( thingName , owner ) ; return ; } } put ( thingName , null ) ; } ) ; When ( "{var} = entity\\({type_label}) get instance with key\\({type_label}): {datetime}" , async ( thingName , thingTypeLabel , keyTypeLabel , value ) => { const key = await ( ( await tx ( ) . concepts . getAttributeType ( keyTypeLabel ) ) . asDateTime ( ) ) . asRemote ( tx ( ) ) . get ( value ) ; for await ( const owner of key . asRemote ( tx ( ) ) . getOwners ( ) ) { if ( ( await owner . asRemote ( tx ( ) ) . type ) . equals ( await tx ( ) . concepts . getEntityType ( thingTypeLabel ) ) ) { put ( thingName , owner ) ; return ; } } put ( thingName , null ) ; } ) ; When ( "entity\\({type_label}) get instances contain: {var}" , async ( typeLabel , variableName ) => { for await ( const instance of ( await tx ( ) . concepts . getEntityType ( typeLabel ) ) . asRemote ( tx ( ) ) . getInstances ( ) ) { if ( instance . equals ( get ( variableName ) ) ) return ; } assert . fail ( ) ; } ) ; When ( "entity\\({type_label}) get instances is empty" , async ( typeLabel ) => { assert . strictEqual ( ( await ( await tx ( ) . concepts . getEntityType ( typeLabel ) ) . asRemote ( tx ( ) ) . getInstances ( ) . collect ( ) ) . length , 0 ) ; } ) ;