import type { CRUDEngine } from '../engine' ; const TABLE_NAME = 'the-simpsons' ; export const deleteSpec = { 'deletes a record.' : async ( engine ) => { const homer = { entity : { firstName : 'Homer' , lastName : 'Simpson' , } , primaryKey : 'homer-simpson' , } ; const lisa = { entity : { firstName : 'Lisa' , lastName : 'Simpson' , } , primaryKey : 'lisa-simpson' , } ; const marge = { entity : { firstName : 'Marge' , lastName : 'Simpson' , } , primaryKey : 'marge-simpson' , } ; const expectedRemainingEntities = 2 ; await Promise . all ( [ engine . create ( TABLE_NAME , homer . primaryKey , homer . entity ) , engine . create ( TABLE_NAME , lisa . primaryKey , lisa . entity ) , engine . create ( TABLE_NAME , marge . primaryKey , marge . entity ) , ] ) ; await engine . delete ( TABLE_NAME , lisa . primaryKey ) ; const primaryKeys = await engine . readAllPrimaryKeys ( TABLE_NAME ) ; expect ( primaryKeys . length ) . toBe ( expectedRemainingEntities ) ; expect ( primaryKeys . includes ( homer . primaryKey ) ) ; expect ( primaryKeys . includes ( marge . primaryKey ) ) ; } , 'returns the primary key of a deleted record.' : async ( engine ) => { const PRIMARY_KEY = 'primary-key' ; const entity = { some : 'value' , } ; const primaryKey = await engine . create ( TABLE_NAME , PRIMARY_KEY , entity ) ; const deletedKey = await engine . delete ( TABLE_NAME , primaryKey ) ; expect ( deletedKey ) . toBe ( PRIMARY_KEY ) ; } , } ;