import { Given , Then , When } from "@cucumber/cucumber" ; import DataTable from "@cucumber/cucumber/lib/models/data_table" ; import { assertThrows } from "../../util/Util" ; import { client , THREAD_POOL_SIZE } from "../ConnectionStepsBase" ; import * as assert from "assert" ; When ( "connection create database: {word}" , async ( name ) => { await client . databases . create ( name ) ; } ) ; When ( "connection create database(s):" , async ( names ) => { for ( const name of names . raw ( ) ) { await client . databases . create ( name [ 0 ] ) ; } } ) ; When ( "connection create databases in parallel:" , async ( names ) => { assert . ok ( THREAD_POOL_SIZE >= names . raw ( ) . length ) ; const creations = [ ] ; for ( const name of names . raw ( ) ) { creations . push ( client . databases . create ( name [ 0 ] ) ) ; } await Promise . all ( creations ) ; } ) ; When ( "connection delete database: {word}" , async ( name ) => { const db = await client . databases . get ( name ) ; await db . delete ( ) ; } ) ; When ( "connection delete database(s):" , async ( names ) => { for ( const name of names . raw ( ) ) { const db = await client . databases . get ( name [ 0 ] ) ; await db . delete ( ) ; } } ) ; Then ( "connection delete database; throws exception: {word}" , async ( name ) => { await assertThrows ( async ( ) => { const db = await client . databases . get ( name ) ; await db . delete ( ) ; } ) ; } ) ; Then ( "connection delete database(s); throws exception" , async ( names ) => { for ( const name of names . raw ( ) ) { await assertThrows ( async ( ) => { const db = await client . databases . get ( name [ 0 ] ) ; await db . delete ( ) ; } ) ; } } ) ; When ( "connection delete databases in parallel:" , async ( names ) => { assert . ok ( THREAD_POOL_SIZE >= names . raw ( ) . length ) ; const deletions = [ ] ; for ( const name of names . raw ( ) ) { deletions . push ( ( await client . databases . get ( name [ 0 ] ) ) . delete ( ) ) ; } await Promise . all ( deletions ) ; } ) ; When ( "connection delete all databases" , async ( ) => { const databases = await client . databases . all ( ) ; for ( const db of databases ) { await db . delete ( ) ; } } ) ; Then ( "connection has database: {word}" , async ( name ) => { const databases = await client . databases . all ( ) ; assert . ok ( databases . some ( x => x . name === name ) ) ; } ) ; Then ( "connection has database(s):" , async ( names ) => { const databases = await client . databases . all ( ) ; names . raw ( ) . forEach ( name => { assert . ok ( databases . some ( x => x . name === name [ 0 ] ) ) ; } ) ; } ) ; Then ( "connection does not have database: {word}" , async ( name ) => { assert . ok ( ! ( await client . databases . contains ( name ) ) ) ; } ) ; Then ( "connection does not have database(s):" , async ( names ) => { const databases = await client . databases . all ( ) ; names . raw ( ) . forEach ( name => { assert . ok ( ! databases . some ( x => x . name === name [ 0 ] ) ) ; } ) ; } ) ; Given ( "connection does not have any database" , async ( ) => { const databases = await client . databases . all ( ) ; assert . ok ( databases . length === 0 ) ; } ) ;