@@ -320,4 +320,127 @@ describe('custom scalar generation using faker', () => {
320
320
321
321
expect ( result ) . toMatchSnapshot ( ) ;
322
322
} ) ;
323
+
324
+ describe ( 'with different input/output configurations' , ( ) => {
325
+ it ( 'should generate distinct custom scalars for native and custom input/output types' , async ( ) => {
326
+ const result = await plugin ( testSchema , [ ] , {
327
+ generateLibrary : 'faker' ,
328
+ scalars : {
329
+ String : 'lorem.sentence' ,
330
+ Float : {
331
+ generator : 'number.float' ,
332
+ arguments : [ { min : - 100 , max : 0 , fractionDigits : 2 } ] ,
333
+ } ,
334
+ ID : {
335
+ generator : 'number.int' ,
336
+ arguments : [ { min : 1 , max : 100 } ] ,
337
+ } ,
338
+ Boolean : 'false' ,
339
+ Int : {
340
+ generator : 'number.int' ,
341
+ arguments : [ { min : - 100 , max : 0 } ] ,
342
+ } ,
343
+ AnyObject : {
344
+ input : 'lorem.word' ,
345
+ output : 'internet.email' ,
346
+ } ,
347
+ } ,
348
+ } ) ;
349
+
350
+ expect ( result ) . toBeDefined ( ) ;
351
+
352
+ // String
353
+ expect ( result ) . toContain (
354
+ "str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.'," ,
355
+ ) ;
356
+
357
+ // Float
358
+ expect ( result ) . toContain ( "flt: overrides && overrides.hasOwnProperty('flt') ? overrides.flt! : -24.51," ) ;
359
+
360
+ // ID
361
+ expect ( result ) . toContain ( "id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83," ) ;
362
+
363
+ // Boolean
364
+ expect ( result ) . toContain ( "bool: overrides && overrides.hasOwnProperty('bool') ? overrides.bool! : false" ) ;
365
+
366
+ // Int
367
+ expect ( result ) . toContain ( "int: overrides && overrides.hasOwnProperty('int') ? overrides.int! : -93," ) ;
368
+
369
+ // AnyObject in type A (an email)
370
+ expect ( result ) . toContain (
371
+ "anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : '[email protected] '," ,
372
+ ) ;
373
+
374
+ // AnyObject in input C (a string)
375
+ expect ( result ) . toContain (
376
+ "anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'vilicus'," ,
377
+ ) ;
378
+
379
+ expect ( result ) . toMatchSnapshot ( ) ;
380
+ } ) ;
381
+
382
+ it ( 'should generate distinct dynamic custom scalars for native and custom types' , async ( ) => {
383
+ const result = await plugin ( testSchema , [ ] , {
384
+ generateLibrary : 'faker' ,
385
+ dynamicValues : true ,
386
+ scalars : {
387
+ String : 'lorem.sentence' ,
388
+ Float : {
389
+ generator : 'number.float' ,
390
+ arguments : [ { min : - 100 , max : 0 } ] ,
391
+ } ,
392
+ ID : {
393
+ generator : 'number.int' ,
394
+ arguments : [ { min : 1 , max : 100 } ] ,
395
+ } ,
396
+ Boolean : 'false' ,
397
+ Int : {
398
+ generator : 'number.int' ,
399
+ arguments : [ { min : - 100 , max : 0 } ] ,
400
+ } ,
401
+ AnyObject : {
402
+ input : 'lorem.word' ,
403
+ output : 'internet.email' ,
404
+ } ,
405
+ } ,
406
+ } ) ;
407
+
408
+ expect ( result ) . toBeDefined ( ) ;
409
+
410
+ // String
411
+ expect ( result ) . toContain (
412
+ "str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : faker['lorem']['sentence']()," ,
413
+ ) ;
414
+
415
+ // Float
416
+ expect ( result ) . toContain (
417
+ "flt: overrides && overrides.hasOwnProperty('flt') ? overrides.flt! : faker['number']['float'](...[{\"min\":-100,\"max\":0}])," ,
418
+ ) ;
419
+
420
+ // ID
421
+ expect ( result ) . toContain (
422
+ "id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : faker['number']['int'](...[{\"min\":1,\"max\":100}])," ,
423
+ ) ;
424
+
425
+ // Boolean
426
+ expect ( result ) . toContain ( "bool: overrides && overrides.hasOwnProperty('bool') ? overrides.bool! : false" ) ;
427
+
428
+ // Int
429
+ expect ( result ) . toContain (
430
+ "int: overrides && overrides.hasOwnProperty('int') ? overrides.int! : faker['number']['int'](...[{\"min\":-100,\"max\":0}])," ,
431
+ ) ;
432
+
433
+ // AnyObject in type A (an email)
434
+ expect ( result ) . toContain (
435
+ "anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : faker['internet']['email']()," ,
436
+ ) ;
437
+
438
+ // AnyObject in input C (a string)
439
+ expect ( result ) . toContain (
440
+ "anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : faker['lorem']['word']()," ,
441
+ ) ;
442
+
443
+ expect ( result ) . toMatchSnapshot ( ) ;
444
+ } ) ;
445
+ } ) ;
323
446
} ) ;
0 commit comments