@@ -346,4 +346,153 @@ describe('Script Generation', () => {
346346 }
347347 } ) ;
348348 } ) ;
349+
350+ describe ( 'Unrecognized Field Defaults' , ( ) => {
351+ it ( 'should use default faker method for unrecognized string fields' , ( ) => {
352+ const schema = {
353+ unknownField : {
354+ mongoType : 'string' ,
355+ fakerMethod : 'unrecognized' ,
356+ fakerArgs : [ ] ,
357+ } ,
358+ } ;
359+
360+ const result = generateScript ( schema , {
361+ databaseName : 'testdb' ,
362+ collectionName : 'test' ,
363+ documentCount : 1 ,
364+ } ) ;
365+
366+ expect ( result . success ) . to . equal ( true ) ;
367+ if ( result . success ) {
368+ expect ( result . script ) . to . contain ( 'faker.lorem.word()' ) ;
369+ }
370+ } ) ;
371+
372+ it ( 'should use default faker method for unrecognized number fields' , ( ) => {
373+ const schema = {
374+ unknownNumber : {
375+ mongoType : 'number' ,
376+ fakerMethod : 'unrecognized' ,
377+ fakerArgs : [ ] ,
378+ } ,
379+ } ;
380+
381+ const result = generateScript ( schema , {
382+ databaseName : 'testdb' ,
383+ collectionName : 'test' ,
384+ documentCount : 1 ,
385+ } ) ;
386+
387+ expect ( result . success ) . to . equal ( true ) ;
388+ if ( result . success ) {
389+ expect ( result . script ) . to . contain ( 'faker.number.int()' ) ;
390+ }
391+ } ) ;
392+
393+ it ( 'should use default faker method for unrecognized date fields' , ( ) => {
394+ const schema = {
395+ unknownDate : {
396+ mongoType : 'date' ,
397+ fakerMethod : 'unrecognized' ,
398+ fakerArgs : [ ] ,
399+ } ,
400+ } ;
401+
402+ const result = generateScript ( schema , {
403+ databaseName : 'testdb' ,
404+ collectionName : 'test' ,
405+ documentCount : 1 ,
406+ } ) ;
407+
408+ expect ( result . success ) . to . equal ( true ) ;
409+ if ( result . success ) {
410+ expect ( result . script ) . to . contain ( 'faker.date.recent()' ) ;
411+ }
412+ } ) ;
413+
414+ it ( 'should use default faker method for unrecognized boolean fields' , ( ) => {
415+ const schema = {
416+ unknownBool : {
417+ mongoType : 'boolean' ,
418+ fakerMethod : 'unrecognized' ,
419+ fakerArgs : [ ] ,
420+ } ,
421+ } ;
422+
423+ const result = generateScript ( schema , {
424+ databaseName : 'testdb' ,
425+ collectionName : 'test' ,
426+ documentCount : 1 ,
427+ } ) ;
428+
429+ expect ( result . success ) . to . equal ( true ) ;
430+ if ( result . success ) {
431+ expect ( result . script ) . to . contain ( 'faker.datatype.boolean()' ) ;
432+ }
433+ } ) ;
434+
435+ it ( 'should use default faker method for unrecognized ObjectId fields' , ( ) => {
436+ const schema = {
437+ unknownId : {
438+ mongoType : 'objectid' ,
439+ fakerMethod : 'unrecognized' ,
440+ fakerArgs : [ ] ,
441+ } ,
442+ } ;
443+
444+ const result = generateScript ( schema , {
445+ databaseName : 'testdb' ,
446+ collectionName : 'test' ,
447+ documentCount : 1 ,
448+ } ) ;
449+
450+ expect ( result . success ) . to . equal ( true ) ;
451+ if ( result . success ) {
452+ expect ( result . script ) . to . contain ( 'faker.database.mongodbObjectId()' ) ;
453+ }
454+ } ) ;
455+
456+ it ( 'should use default faker method for unrecognized double fields' , ( ) => {
457+ const schema = {
458+ unknownDouble : {
459+ mongoType : 'double' ,
460+ fakerMethod : 'unrecognized' ,
461+ fakerArgs : [ ] ,
462+ } ,
463+ } ;
464+
465+ const result = generateScript ( schema , {
466+ databaseName : 'testdb' ,
467+ collectionName : 'test' ,
468+ documentCount : 1 ,
469+ } ) ;
470+
471+ expect ( result . success ) . to . equal ( true ) ;
472+ if ( result . success ) {
473+ expect ( result . script ) . to . contain ( 'faker.number.float()' ) ;
474+ }
475+ } ) ;
476+
477+ it ( 'should fall back to lorem.word for unknown MongoDB types' , ( ) => {
478+ const schema = {
479+ unknownType : {
480+ mongoType : 'unknownType' ,
481+ fakerMethod : 'unrecognized' ,
482+ fakerArgs : [ ] ,
483+ } ,
484+ } ;
485+
486+ const result = generateScript ( schema , {
487+ databaseName : 'testdb' ,
488+ collectionName : 'test' ,
489+ documentCount : 1 ,
490+ } ) ;
491+
492+ expect ( result . success ) . to . equal ( true ) ;
493+ if ( result . success ) {
494+ expect ( result . script ) . to . contain ( 'faker.lorem.word()' ) ;
495+ }
496+ } ) ;
497+ } ) ;
349498} ) ;
0 commit comments