import { Then , When } from "@cucumber/cucumber" ; import DataTable from "@cucumber/cucumber/lib/models/data_table" ; import assert from "assert" ; import { AttributeType , ErrorMessage , TypeDBClientError } from "../../../../../dist" ; import { parseList } from "../../../config/Parameters" ; import { tx } from "../../../connection/ConnectionStepsBase" ; import ValueType = AttributeType . ValueType ; When ( "put attribute type: {type_label}, with value type: {value_type}" , async ( typeLabel , valueType ) => { await tx ( ) . concepts . putAttributeType ( typeLabel , valueType ) ; } ) ; Then ( "attribute\\({type_label}) get value type: {value_type}" , async ( typeLabel , valueType ) => { assert . strictEqual ( ( await tx ( ) . concepts . getAttributeType ( typeLabel ) ) . valueType , valueType ) ; } ) ; Then ( "attribute\\({type_label}) get supertype value type: {value_type}" , async ( typeLabel , valueType ) => { const supertype = await ( await tx ( ) . concepts . getAttributeType ( typeLabel ) ) . asRemote ( tx ( ) ) . getSupertype ( ) ; assert . strictEqual ( supertype . asAttributeType ( ) . valueType , valueType ) ; } ) ; async function attributeTypeAsValueType ( typeLabel , valueType ) { const attributeType = await tx ( ) . concepts . getAttributeType ( typeLabel ) ; switch ( valueType ) { case ValueType . OBJECT : return attributeType ; case ValueType . BOOLEAN : return attributeType . asBoolean ( ) ; case ValueType . LONG : return attributeType . asLong ( ) ; case ValueType . DOUBLE : return attributeType . asDouble ( ) ; case ValueType . STRING : return attributeType . asString ( ) ; case ValueType . DATETIME : return attributeType . asDateTime ( ) ; default : throw new TypeDBClientError ( ErrorMessage . Concept . BAD_VALUE_TYPE . message ( valueType ) ) ; } } Then ( "attribute\\({type_label}) as\\({value_type}) get subtypes contain:" , async ( typeLabel , valueType , subLabelsTable ) => { const subLabels = parseList ( subLabelsTable ) ; const attributeType = await attributeTypeAsValueType ( typeLabel , valueType ) ; const actuals = await attributeType . asRemote ( tx ( ) ) . getSubtypes ( ) . map ( tt => tt . label . scopedName ) . collect ( ) ; await subLabels . every ( sl => assert ( actuals . includes ( sl ) ) ) ; } ) ; Then ( "attribute\\({type_label}) as\\({value_type}) get subtypes do not contain:" , async ( typeLabel , valueType , subLabelsTable ) => { const subLabels = parseList ( subLabelsTable ) ; const attributeType = await attributeTypeAsValueType ( typeLabel , valueType ) ; const actuals = await attributeType . asRemote ( tx ( ) ) . getSubtypes ( ) . map ( tt => tt . label . scopedName ) . collect ( ) ; await subLabels . every ( sl => assert ( ! actuals . includes ( sl ) ) ) ; } ) ; Then ( "attribute\\({type_label}) as\\({value_type}) set regex: {}" , async ( typeLabel , valueType , regex ) => { assert ( valueType == ValueType . STRING ) ; const attributeType = await attributeTypeAsValueType ( typeLabel , valueType ) ; await attributeType . asString ( ) . asRemote ( tx ( ) ) . setRegex ( regex ) ; } ) ; Then ( "attribute\\({type_label}) as\\({value_type}) unset regex" , async ( typeLabel , valueType ) => { assert ( valueType == ValueType . STRING ) ; const attributeType = await attributeTypeAsValueType ( typeLabel , valueType ) ; await attributeType . asString ( ) . asRemote ( tx ( ) ) . setRegex ( null ) ; } ) ; Then ( "attribute\\({type_label}) as\\({value_type}) get regex: {}" , async ( typeLabel , valueType , regex ) => { assert ( valueType == ValueType . STRING ) ; const attributeType = await attributeTypeAsValueType ( typeLabel , valueType ) ; assert . strictEqual ( await attributeType . asString ( ) . asRemote ( tx ( ) ) . getRegex ( ) , regex ) ; } ) ; Then ( "attribute\\({type_label}) as\\({value_type}) does not have any regex" , async ( typeLabel , valueType ) => { assert ( valueType == ValueType . STRING ) ; const attributeType = await attributeTypeAsValueType ( typeLabel , valueType ) ; assert ( ! ( await attributeType . asString ( ) . asRemote ( tx ( ) ) . getRegex ( ) ) ) ; } ) ; Then ( "attribute\\({type_label}) get key owners contain:" , async ( typeLabel , ownerLabelsTable ) => { const ownerLabels = parseList ( ownerLabelsTable ) ; const attributeType = await tx ( ) . concepts . getAttributeType ( typeLabel ) ; const actuals = await attributeType . asRemote ( tx ( ) ) . getOwners ( true ) . map ( tt => tt . label . scopedName ) . collect ( ) ; await ownerLabels . every ( ol => assert ( actuals . includes ( ol ) ) ) ; } ) ; Then ( "attribute\\({type_label}) get key owners do not contain:" , async ( typeLabel , ownerLabelsTable ) => { const ownerLabels = parseList ( ownerLabelsTable ) ; const attributeType = await tx ( ) . concepts . getAttributeType ( typeLabel ) ; const actuals = await attributeType . asRemote ( tx ( ) ) . getOwners ( true ) . map ( tt => tt . label . scopedName ) . collect ( ) ; await ownerLabels . every ( ol => assert ( ! actuals . includes ( ol ) ) ) ; } ) ; Then ( "attribute\\({type_label}) get attribute owners contain:" , async ( typeLabel , ownerLabelsTable ) => { const ownerLabels = parseList ( ownerLabelsTable ) ; const attributeType = await tx ( ) . concepts . getAttributeType ( typeLabel ) ; const actuals = await attributeType . asRemote ( tx ( ) ) . getOwners ( false ) . map ( tt => tt . label . scopedName ) . collect ( ) ; await ownerLabels . every ( ol => assert ( actuals . includes ( ol ) ) ) ; } ) ; Then ( "attribute\\({type_label}) get attribute owners do not contain:" , async ( typeLabel , ownerLabelsTable ) => { const ownerLabels = parseList ( ownerLabelsTable ) ; const attributeType = await tx ( ) . concepts . getAttributeType ( typeLabel ) ; const actuals = await attributeType . asRemote ( tx ( ) ) . getOwners ( false ) . map ( tt => tt . label . scopedName ) . collect ( ) ; await ownerLabels . every ( ol => assert ( ! actuals . includes ( ol ) ) ) ; } ) ;