import { AutoGeneratedAttributeMetadata } from '../auto-generated-attribute-metadata' ; import { AUTO_GENERATE_ATTRIBUTE_STRATEGY } from '@typedorm/common' ; jest . mock ( 'uuid' , ( ) => ( { v4 : ( ) => 'c0ac5395-ba7c-41bf-bbc3-09a6087bcca2' , } ) ) ; jest . mock ( 'ksuid' , ( ) => ( { randomSync : ( ) => ( { string : '1irj9jenZH4PfTWp3NrDgpSF7lg' , } ) , } ) ) ; test ( 'creates attribute metadata with uuid strategy' , ( ) => { const metadata = new AutoGeneratedAttributeMetadata ( { name : 'id' , strategy : AUTO_GENERATE_ATTRIBUTE_STRATEGY . UUID4 , type : 'String' , } ) ; expect ( metadata ) . toEqual ( expect . objectContaining ( { name : 'id' , strategy : 'UUID4' , value : 'c0ac5395-ba7c-41bf-bbc3-09a6087bcca2' , } ) ) ; } ) ; test ( 'creates attribute metadata with ksuid strategy' , ( ) => { const metadata = new AutoGeneratedAttributeMetadata ( { name : 'id' , strategy : AUTO_GENERATE_ATTRIBUTE_STRATEGY . KSUID , type : 'String' , } ) ; expect ( metadata ) . toEqual ( expect . objectContaining ( { name : 'id' , strategy : 'KSUID' , value : '1irj9jenZH4PfTWp3NrDgpSF7lg' , } ) ) ; } ) ; test ( 'creates attribute metadata with epoch strategy' , ( ) => { jest . useFakeTimers ( 'modern' ) . setSystemTime ( new Date ( '2020-01-01' ) ) ; const metadata = new AutoGeneratedAttributeMetadata ( { name : 'date' , strategy : AUTO_GENERATE_ATTRIBUTE_STRATEGY . EPOCH_DATE , type : 'String' , } ) ; expect ( metadata ) . toEqual ( expect . objectContaining ( { name : 'date' , strategy : 'EPOCH_DATE' , value : 1577836800 , } ) ) ; } ) ; test ( 'creates attribute metadata with iso strategy' , ( ) => { jest . useFakeTimers ( 'modern' ) . setSystemTime ( new Date ( '2020-01-01' ) ) ; const metadata = new AutoGeneratedAttributeMetadata ( { name : 'date' , strategy : AUTO_GENERATE_ATTRIBUTE_STRATEGY . ISO_DATE , type : 'String' , } ) ; expect ( metadata ) . toEqual ( expect . objectContaining ( { name : 'date' , strategy : 'ISO_DATE' , value : '2020-01-01T00:00:00.000Z' , } ) ) ; } ) ;