9
9
defineBookFactory ,
10
10
defineImageFactory ,
11
11
defineUserFactory ,
12
- lazy ,
12
+ dynamic ,
13
13
resetAllSequence ,
14
14
} from './__generated__/fabbrica.js' ;
15
15
import { Author } from './__generated__/types.js' ;
@@ -19,18 +19,18 @@ describe('integration test', () => {
19
19
it ( 'circular dependent type' , async ( ) => {
20
20
const BookFactory = defineBookFactory ( {
21
21
defaultFields : {
22
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
23
- title : lazy ( ( { seq } ) => `ゆゆ式 ${ seq } 巻` ) ,
24
- // NOTE: `lazy (({ seq }) => AuthorFactory.build())` causes a circular dependency between `BookFactory` and `AuthorFactory`.
22
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
23
+ title : dynamic ( ( { seq } ) => `ゆゆ式 ${ seq } 巻` ) ,
24
+ // NOTE: `dynamic (({ seq }) => AuthorFactory.build())` causes a circular dependency between `BookFactory` and `AuthorFactory`.
25
25
// As a result, the types of each other become undecidable and a compile error occurs.
26
26
// So that the type is not undecidable, pass `undefined`.
27
27
author : undefined ,
28
28
} ,
29
29
} ) ;
30
30
const AuthorFactory = defineAuthorFactory ( {
31
31
defaultFields : {
32
- id : lazy ( ( { seq } ) => `Author-${ seq } ` ) ,
33
- name : lazy ( ( { seq } ) => `${ seq } 上小又` ) ,
32
+ id : dynamic ( ( { seq } ) => `Author-${ seq } ` ) ,
33
+ name : dynamic ( ( { seq } ) => `${ seq } 上小又` ) ,
34
34
// NOTE: The type is not undecidable, pass `undefined`.
35
35
books : undefined ,
36
36
} ,
@@ -155,8 +155,8 @@ describe('defineTypeFactory', () => {
155
155
it ( 'accepts functional field resolvers' , async ( ) => {
156
156
const BookFactory = defineBookFactory ( {
157
157
defaultFields : {
158
- id : lazy ( ( ) => 'Book-0' ) ,
159
- title : lazy ( async ( ) => Promise . resolve ( 'ゆゆ式' ) ) ,
158
+ id : dynamic ( ( ) => 'Book-0' ) ,
159
+ title : dynamic ( async ( ) => Promise . resolve ( 'ゆゆ式' ) ) ,
160
160
author : undefined ,
161
161
} ,
162
162
} ) ;
@@ -193,8 +193,8 @@ describe('defineTypeFactory', () => {
193
193
it ( 'creates fields with sequential id' , async ( ) => {
194
194
const BookFactory = defineBookFactory ( {
195
195
defaultFields : {
196
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
197
- title : lazy ( async ( { seq } ) => Promise . resolve ( `ゆゆ式 ${ seq } 巻` ) ) ,
196
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
197
+ title : dynamic ( async ( { seq } ) => Promise . resolve ( `ゆゆ式 ${ seq } 巻` ) ) ,
198
198
author : undefined ,
199
199
} ,
200
200
} ) ;
@@ -216,10 +216,10 @@ describe('defineTypeFactory', () => {
216
216
const lastNameResolver = vi . fn ( ( ) => 'Mikami' ) ;
217
217
const UserFactory = defineUserFactory ( {
218
218
defaultFields : {
219
- id : lazy ( ( { seq } ) => `User-${ seq } ` ) ,
220
- firstName : lazy ( firstNameResolver ) ,
221
- lastName : lazy ( lastNameResolver ) ,
222
- fullName : lazy (
219
+ id : dynamic ( ( { seq } ) => `User-${ seq } ` ) ,
220
+ firstName : dynamic ( firstNameResolver ) ,
221
+ lastName : dynamic ( lastNameResolver ) ,
222
+ fullName : dynamic (
223
223
async ( { get } ) => `${ ( await get ( 'firstName' ) ) ?? 'firstName' } ${ ( await get ( 'lastName' ) ) ?? 'lastName' } ` ,
224
224
) ,
225
225
} ,
@@ -248,7 +248,7 @@ describe('defineTypeFactory', () => {
248
248
it ( 'overrides defaultFields' , async ( ) => {
249
249
const ImageFactory = defineImageFactory ( {
250
250
defaultFields : {
251
- id : lazy ( ( { seq } ) => `Image-${ seq } ` ) ,
251
+ id : dynamic ( ( { seq } ) => `Image-${ seq } ` ) ,
252
252
url : '#' ,
253
253
width : null ,
254
254
height : null ,
@@ -281,7 +281,7 @@ describe('defineTypeFactory', () => {
281
281
it ( 'overrides fields multiple times by chaining the use methods' , async ( ) => {
282
282
const ImageFactory = defineImageFactory ( {
283
283
defaultFields : {
284
- id : lazy ( ( { seq } ) => `Image-${ seq } ` ) ,
284
+ id : dynamic ( ( { seq } ) => `Image-${ seq } ` ) ,
285
285
url : '#' ,
286
286
width : null ,
287
287
height : null ,
@@ -333,16 +333,16 @@ describe('defineTypeFactory', () => {
333
333
334
334
const BookFactory = defineBookFactory ( {
335
335
defaultFields : {
336
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
337
- title : lazy ( ( { seq } ) => `ゆゆ式 ${ seq } 巻` ) ,
336
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
337
+ title : dynamic ( ( { seq } ) => `ゆゆ式 ${ seq } 巻` ) ,
338
338
author : undefined ,
339
339
} ,
340
340
} ) ;
341
341
const AuthorFactory = defineAuthorFactoryWithTransientFields ( {
342
342
defaultFields : {
343
- id : lazy ( ( { seq } ) => `Author-${ seq } ` ) ,
343
+ id : dynamic ( ( { seq } ) => `Author-${ seq } ` ) ,
344
344
name : '三上小又' ,
345
- books : lazy ( async ( { get } ) => {
345
+ books : dynamic ( async ( { get } ) => {
346
346
const bookCount = ( await get ( 'bookCount' ) ) ?? 0 ;
347
347
return BookFactory . buildList ( bookCount ) ;
348
348
} ) ,
@@ -387,7 +387,7 @@ describe('defineTypeFactory', () => {
387
387
it ( 'resets all sequence' , async ( ) => {
388
388
const BookFactory = defineBookFactory ( {
389
389
defaultFields : {
390
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
390
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
391
391
title : 'ゆゆ式' ,
392
392
author : undefined ,
393
393
} ,
@@ -499,8 +499,8 @@ describe('TypeFactoryInterface', () => {
499
499
} ,
500
500
} ) ;
501
501
const book = await BookFactory . build ( {
502
- id : lazy ( ( ) => 'Book-0' ) ,
503
- title : lazy ( async ( ) => Promise . resolve ( 'ゆゆ式' ) ) ,
502
+ id : dynamic ( ( ) => 'Book-0' ) ,
503
+ title : dynamic ( async ( ) => Promise . resolve ( 'ゆゆ式' ) ) ,
504
504
author : undefined ,
505
505
} ) ;
506
506
expect ( book ) . toStrictEqual ( {
@@ -572,7 +572,7 @@ describe('TypeFactoryInterface', () => {
572
572
const BookFactory = defineBookFactory ( {
573
573
defaultFields : {
574
574
id : 'Book-0' ,
575
- title : lazy ( defaultTitleResolver ) ,
575
+ title : dynamic ( defaultTitleResolver ) ,
576
576
author : undefined ,
577
577
} ,
578
578
} ) ;
@@ -601,8 +601,8 @@ describe('TypeFactoryInterface', () => {
601
601
} ,
602
602
} ) ;
603
603
const book = await BookFactory . build ( {
604
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
605
- title : lazy ( async ( { seq } ) => Promise . resolve ( `ゆゆ式 ${ seq } 巻` ) ) ,
604
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
605
+ title : dynamic ( async ( { seq } ) => Promise . resolve ( `ゆゆ式 ${ seq } 巻` ) ) ,
606
606
} ) ;
607
607
expect ( book ) . toStrictEqual ( {
608
608
id : 'Book-0' ,
@@ -621,16 +621,16 @@ describe('TypeFactoryInterface', () => {
621
621
const lastNameResolver = vi . fn ( ( ) => 'Mikami' ) ;
622
622
const UserFactory = defineUserFactory ( {
623
623
defaultFields : {
624
- id : lazy ( ( { seq } ) => `User-${ seq } ` ) ,
624
+ id : dynamic ( ( { seq } ) => `User-${ seq } ` ) ,
625
625
firstName : '' ,
626
626
lastName : '' ,
627
627
fullName : '' ,
628
628
} ,
629
629
} ) ;
630
630
const User = await UserFactory . build ( {
631
- firstName : lazy ( firstNameResolver ) ,
632
- lastName : lazy ( lastNameResolver ) ,
633
- fullName : lazy (
631
+ firstName : dynamic ( firstNameResolver ) ,
632
+ lastName : dynamic ( lastNameResolver ) ,
633
+ fullName : dynamic (
634
634
async ( { get } ) => `${ ( await get ( 'firstName' ) ) ?? 'firstName' } ${ ( await get ( 'lastName' ) ) ?? 'lastName' } ` ,
635
635
) ,
636
636
} ) ;
@@ -657,7 +657,7 @@ describe('TypeFactoryInterface', () => {
657
657
it ( 'overrides defaultFields' , async ( ) => {
658
658
const BookFactory = defineBookFactory ( {
659
659
defaultFields : {
660
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
660
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
661
661
title : 'ゆゆ式' ,
662
662
author : undefined ,
663
663
} ,
@@ -717,7 +717,7 @@ describe('TypeFactoryInterface', () => {
717
717
it ( 'resets sequence' , async ( ) => {
718
718
const BookFactory = defineBookFactory ( {
719
719
defaultFields : {
720
- id : lazy ( ( { seq } ) => `Book-${ seq } ` ) ,
720
+ id : dynamic ( ( { seq } ) => `Book-${ seq } ` ) ,
721
721
title : 'ゆゆ式' ,
722
722
author : undefined ,
723
723
} ,
0 commit comments