import type { CRUDEngine } from '../engine' ; import { RecordNotFoundError } from '../engine/error' ; const TABLE_NAME = 'the-simpsons' ; interface DomainEntity { age : number ; name : string ; size : { height : number ; width : number ; } ; } export const updateSpec = { 'fails if the record does not exist.' : async ( engine ) => { const PRIMARY_KEY = 'primary-key' ; const updates = { age : 177 , size : { height : 1080 , width : 1920 , } , } ; try { await engine . update ( TABLE_NAME , PRIMARY_KEY , updates ) ; fail ( ) ; } catch ( error ) { expect ( error ) . toEqual ( jasmine . any ( RecordNotFoundError ) ) ; } } , 'updates an existing database record.' : async ( engine ) => { const PRIMARY_KEY = 'primary-key' ; const entity = { name : 'Old monitor' , } ; const updates = { age : 177 , size : { height : 1080 , width : 1920 , } , } ; const expectedAmountOfProperties = 2 ; await engine . create ( TABLE_NAME , PRIMARY_KEY , entity ) ; const primaryKey = await engine . update ( TABLE_NAME , PRIMARY_KEY , updates ) ; const updatedRecord = await engine . read < DomainEntity > ( TABLE_NAME , primaryKey ) ; expect ( updatedRecord . name ) . toBe ( entity . name ) ; expect ( updatedRecord . age ) . toBe ( updates . age ) ; expect ( Object . keys ( updatedRecord . size ) . length ) . toBe ( expectedAmountOfProperties ) ; expect ( updatedRecord . size . height ) . toBe ( updates . size . height ) ; expect ( updatedRecord . size . width ) . toBe ( updates . size . width ) ; } , } ;