import { Then , When } from "@cucumber/cucumber" ; import DataTable from "@cucumber/cucumber/lib/models/data_table" ; import { parseList , ScopedLabel } from "../../../config/Parameters" ; import { tx } from "../../../connection/ConnectionStepsBase" ; import { assertThrows } from "../../../util/Util" ; import assert = require ( "assert" ) ; When ( "relation\\({type_label}) set relates role: {type_label}" , async ( relationLabel , roleLabel ) => { await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . setRelates ( roleLabel ) ; } ) ; When ( "relation\\({type_label}) set relates role: {type_label}; throws exception" , async ( relationLabel , roleLabel ) => { await assertThrows ( async ( ) => await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . setRelates ( roleLabel ) ) ; } ) ; When ( "relation\\({type_label}) unset related role: {type_label}" , async ( relationLabel , roleLabel ) => { await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . unsetRelates ( roleLabel ) ; } ) ; When ( "relation\\({type_label}) unset related role: {type_label}; throws exception" , async ( relationLabel , roleLabel ) => { await assertThrows ( async ( ) => await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . unsetRelates ( roleLabel ) ) ; } ) ; When ( "relation\\({type_label}) set relates role: {type_label} as {type_label}" , async ( relationLabel , roleLabel , superRole ) => { await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . setRelates ( roleLabel , superRole ) ; } ) ; When ( "relation\\({type_label}) set relates role: {type_label} as {type_label}; throws exception" , async ( relationLabel , roleLabel , superRole ) => { await assertThrows ( async ( ) => await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . setRelates ( roleLabel , superRole ) ) ; } ) ; When ( "relation\\({type_label}) remove related role: {type_label}" , async ( relationLabel , roleLabel ) => { const relatedRole = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; await relatedRole . asRemote ( tx ( ) ) . delete ( ) ; } ) ; Then ( "relation\\({type_label}) get role\\({type_label}) is null: {bool}" , async ( relationLabel , roleLabel , isNull ) => { assert . strictEqual ( ! ( await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ) , isNull ) ; } ) ; When ( "relation\\({type_label}) get role\\({type_label}) set label: {type_label}" , async ( relationLabel , roleLabel , newLabel ) => { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; await roleType . asRemote ( tx ( ) ) . setLabel ( newLabel ) ; } ) ; When ( "relation\\({type_label}) get role\\({type_label}) get label: {type_label}" , async ( relationLabel , roleLabel , getLabel ) => { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; assert . strictEqual ( roleType . label . name , getLabel ) ; } ) ; When ( "relation\\({type_label}) get role\\({type_label}) is abstract: {bool}" , async ( relationLabel , roleLabel , isAbstract ) => { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; assert . strictEqual ( await roleType . asRemote ( tx ( ) ) . isAbstract ( ) , isAbstract ) ; } ) ; async function getActualRelatedRoles ( relationLabel ) { return ( ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( ) ) . map ( role => role . label . scopedName ) . collect ( ) ; } Then ( "relation\\({type_label}) get related roles contain:" , async ( relationLabel , roleLabelsTable ) => { const roleLabels = parseList ( roleLabelsTable ) ; const actuals = await getActualRelatedRoles ( relationLabel ) ; await actuals . every ( rl => assert ( roleLabels . includes ( rl ) ) ) ; } ) ; Then ( "relation\\({type_label}) get related roles do not contain:" , async ( relationLabel , roleLabelsTable ) => { const roleLabels = parseList ( roleLabelsTable ) ; const actuals = await getActualRelatedRoles ( relationLabel ) ; await actuals . every ( rl => assert ( ! roleLabels . includes ( rl ) ) ) ; } ) ; Then ( "relation\\({type_label}) get role\\({type_label}) get supertype: {scoped_label}" , async ( relationLabel , roleLabel , superLabel ) => { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; const superType = await ( await tx ( ) . concepts . getRelationType ( superLabel . scope ) ) . asRemote ( tx ( ) ) . getRelates ( superLabel . role ) ; assert ( ( await roleType . asRemote ( tx ( ) ) . getSupertype ( ) ) . equals ( superType ) ) ; } ) ; async function getActualSupertypesForRelatedRole ( relationLabel , roleLabel ) { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; return roleType . asRemote ( tx ( ) ) . getSupertypes ( ) . map ( role => role . label . scopedName ) . collect ( ) ; } Then ( "relation\\({type_label}) get role\\({type_label}) get supertypes contain:" , async ( relationLabel , roleLabel , superLabelsTable ) => { const superLabels = parseList ( superLabelsTable ) ; const actuals = await getActualSupertypesForRelatedRole ( relationLabel , roleLabel ) ; await actuals . every ( rl => assert ( superLabels . includes ( rl ) ) ) ; } ) ; Then ( "relation\\({type_label}) get role\\({type_label}) get supertypes do not contain:" , async ( relationLabel , roleLabel , superLabelsTable ) => { const superLabels = parseList ( superLabelsTable ) ; const actuals = await getActualSupertypesForRelatedRole ( relationLabel , roleLabel ) ; await actuals . every ( rl => assert ( ! superLabels . includes ( rl ) ) ) ; } ) ; async function getActualPlayersForRelatedRole ( relationLabel , roleLabel ) { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; return await roleType . asRemote ( tx ( ) ) . getPlayers ( ) . map ( tt => tt . label . scopedName ) . collect ( ) ; } Then ( "relation\\({type_label}) get role\\({type_label}) get players contain:" , async ( relationLabel , roleLabel , playerLabelsTable ) => { const playerLabels = parseList ( playerLabelsTable ) ; const actuals = await getActualPlayersForRelatedRole ( relationLabel , roleLabel ) ; await actuals . every ( pl => assert ( playerLabels . includes ( pl ) ) ) ; } ) ; Then ( "relation\\({type_label}) get role\\({type_label}) get players do not contain:" , async ( relationLabel , roleLabel , playerLabelsTable ) => { const playerLabels = parseList ( playerLabelsTable ) ; const actuals = await getActualPlayersForRelatedRole ( relationLabel , roleLabel ) ; await actuals . every ( pl => assert ( ! playerLabels . includes ( pl ) ) ) ; } ) ; async function getActualSubtypesForRelatedRole ( relationLabel , roleLabel ) { const roleType = await ( await tx ( ) . concepts . getRelationType ( relationLabel ) ) . asRemote ( tx ( ) ) . getRelates ( roleLabel ) ; return roleType . asRemote ( tx ( ) ) . getSubtypes ( ) . map ( role => role . label . scopedName ) . collect ( ) ; } Then ( "relation\\({type_label}) get role\\({type_label}) get subtypes contain:" , async ( relationLabel , roleLabel , subLabelsTable ) => { const subLabels = parseList ( subLabelsTable ) ; const actuals = await getActualSubtypesForRelatedRole ( relationLabel , roleLabel ) ; await actuals . every ( rl => assert ( subLabels . includes ( rl ) ) ) ; } ) ; Then ( "relation\\({type_label}) get role\\({type_label}) get subtypes do not contain:" , async ( relationLabel , roleLabel , subLabelsTable ) => { const subLabels = parseList ( subLabelsTable ) ; const actuals = await getActualSubtypesForRelatedRole ( relationLabel , roleLabel ) ; await actuals . every ( rl => assert ( ! subLabels . includes ( rl ) ) ) ; } ) ;