import { Given , Then , When } from "@cucumber/cucumber" ; import DataTable from "@cucumber/cucumber/lib/models/data_table" ; import { SessionType , TypeDBSession } from "../../../../dist" ; import { client , optionSetters , sessionOptions , sessions } from "../ConnectionStepsBase" ; import assert = require ( "assert" ) ; When ( "connection open(s) schema session for database: {word}" , async ( name ) => { sessions . push ( await client . session ( name , SessionType . SCHEMA ) ) ; } ) ; When ( "connection open(s) (data )session for database: {word}" , async ( name ) => { sessions . push ( await client . session ( name , SessionType . DATA ) ) ; } ) ; When ( "connection open(s) schema session(s) for database(s):" , async ( names ) => { for ( const name of names . raw ( ) ) { sessions . push ( await client . session ( name [ 0 ] , SessionType . SCHEMA ) ) ; } } ) ; When ( "connection open(s) (data )session(s) for database(s):" , async ( names ) => { for ( const name of names . raw ( ) ) { sessions . push ( await client . session ( name [ 0 ] , SessionType . DATA ) ) ; } } ) ; When ( "connection open(s) (data )sessions in parallel for databases:" , async ( names ) => { const openings = [ ] ; for ( const name of names . raw ( ) ) { openings . push ( client . session ( name [ 0 ] , SessionType . DATA ) ) ; } sessions . push ( ... await Promise . all ( openings ) ) ; } ) ; When ( "connection close all sessions" , async ( ) => { for ( const session of sessions ) { try { if ( session . isOpen ( ) ) await session . close ( ) ; } catch ( err ) { } } sessions . length = 0 ; } ) ; Then ( "session(s)( in parallel) is/are null: {bool}" , function ( isNull ) { for ( const session of sessions ) { assert . ok ( ! session === isNull ) ; } } ) ; Then ( 'session(s)( in parallel) is/are open: {bool}' , function ( isOpen ) { for ( const session of sessions ) { assert . ok ( session . isOpen ( ) === isOpen ) ; } } ) ; When ( "session has database: {word}" , ( name ) => { for ( const session of sessions ) { assert . ok ( session . database . name === name ) ; } } ) ; When ( "sessions( in parallel) have/has databases:" , ( names ) => { for ( let i = 0 ; i < sessions . length ; i ++ ) { assert . ok ( sessions [ i ] . database . name === names . raw ( ) [ i ] [ 0 ] ) ; } } ) ; Given ( 'set session option {word} to: {word}' , async function ( option , value ) { if ( ! ( option in optionSetters ) ) { throw ( "Unrecognised option: " + option ) ; } else { optionSetters [ option ] ( sessionOptions , value ) ; } } ) ;