@@ -454,6 +454,20 @@ describe('TypegooseQueryService', () => {
454454 'Id cannot be specified when updating or creating' ,
455455 ) ;
456456 } ) ;
457+
458+ it ( 'should not reject if the entity contains an undefined id' , async ( ) => {
459+ const entity = testEntityToCreate ( TEST_ENTITIES [ 0 ] ) ;
460+ const queryService = moduleRef . get ( TestEntityService ) ;
461+ const created = await queryService . createOne ( { ...entity , id : undefined } ) ;
462+ expect ( convertDocument ( created ) ) . toEqual ( expect . objectContaining ( entity ) ) ;
463+ } ) ;
464+
465+ it ( 'should not reject if the entity contains an undefined _id' , async ( ) => {
466+ const entity = testEntityToCreate ( TEST_ENTITIES [ 0 ] ) ;
467+ const queryService = moduleRef . get ( TestEntityService ) ;
468+ const created = await queryService . createOne ( { ...entity , _id : undefined } ) ;
469+ expect ( convertDocument ( created ) ) . toEqual ( expect . objectContaining ( entity ) ) ;
470+ } ) ;
457471 } ) ;
458472
459473 describe ( '#deleteMany' , ( ) => {
@@ -521,6 +535,18 @@ describe('TypegooseQueryService', () => {
521535 'Id cannot be specified when updating' ,
522536 ) ;
523537 } ) ;
538+
539+ it ( 'should not reject if the update contains an undefined id' , async ( ) => {
540+ const queryService = moduleRef . get ( TestEntityService ) ;
541+ const entitiesToUpdate = TEST_ENTITIES . slice ( 0 , 5 ) ;
542+ const filter = {
543+ stringType : { in : entitiesToUpdate . map ( ( e ) => e . stringType ) } ,
544+ } ;
545+ await queryService . updateMany ( { stringType : 'updated' , id : undefined } , filter ) ;
546+ const entities = await queryService . query ( { filter : { stringType : { eq : 'updated' } } } ) ;
547+ expect ( entities ) . toHaveLength ( entitiesToUpdate . length ) ;
548+ expect ( new Set ( entities . map ( ( e ) => e . id ) ) ) . toEqual ( new Set ( entitiesToUpdate . map ( ( e ) => e . id ) ) ) ;
549+ } ) ;
524550 } ) ;
525551
526552 describe ( '#updateOne' , ( ) => {
0 commit comments