@@ -27,9 +27,12 @@ describe('Script Generation', () => {
2727
2828 expect ( result . success ) . to . equal ( true ) ;
2929 if ( result . success ) {
30+ const expectedReturnBlock = `return {
31+ name: faker.person.fullName(),
32+ email: faker.internet.email()
33+ };` ;
34+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
3035 expect ( result . script ) . to . contain ( "use('testdb')" ) ;
31- expect ( result . script ) . to . contain ( 'faker.person.fullName()' ) ;
32- expect ( result . script ) . to . contain ( 'faker.internet.email()' ) ;
3336 expect ( result . script ) . to . contain ( 'insertMany' ) ;
3437 }
3538 } ) ;
@@ -49,8 +52,10 @@ describe('Script Generation', () => {
4952
5053 expect ( result . success ) . to . equal ( true ) ;
5154 if ( result . success ) {
52- expect ( result . script ) . to . contain ( 'Array.from' ) ;
53- expect ( result . script ) . to . contain ( 'faker.lorem.word()' ) ;
55+ const expectedReturnBlock = `return {
56+ tags: Array.from({length: 3}, () => faker.lorem.word())
57+ };` ;
58+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
5459 }
5560 } ) ;
5661
@@ -68,12 +73,14 @@ describe('Script Generation', () => {
6873
6974 expect ( result . success ) . to . equal ( true ) ;
7075 if ( result . success ) {
71- expect ( result . script ) . to . contain ( 'Array.from' ) ;
72- expect ( result . script ) . to . contain ( 'faker.person.fullName()' ) ;
73- expect ( result . script ) . to . contain ( 'faker.internet.email()' ) ;
74- // Should have nested object structure
75- expect ( result . script ) . to . match ( / n a m e : \s * f a k e r \. p e r s o n \. f u l l N a m e \( \) / ) ;
76- expect ( result . script ) . to . match ( / e m a i l : \s * f a k e r \. i n t e r n e t \. e m a i l \( \) / ) ;
76+ // Should generate the complete return block with proper structure
77+ const expectedReturnBlock = `return {
78+ users: Array.from({length: 3}, () => {
79+ name: faker.person.fullName(),
80+ email: faker.internet.email()
81+ })
82+ };` ;
83+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
7784 }
7885 } ) ;
7986
@@ -90,12 +97,10 @@ describe('Script Generation', () => {
9097
9198 expect ( result . success ) . to . equal ( true ) ;
9299 if ( result . success ) {
93- // Should have nested Array.from calls
94- expect ( result . script ) . to . contain ( 'Array.from' ) ;
95- expect ( result . script ) . to . contain ( 'faker.number.int()' ) ;
96- // Should have two levels of Array.from for 2D array
97- const arrayFromMatches = result . script . match ( / A r r a y \. f r o m / g) ;
98- expect ( arrayFromMatches ?. length ) . to . be . greaterThanOrEqual ( 2 ) ;
100+ const expectedReturnBlock = `return {
101+ matrix: Array.from({length: 3}, () => Array.from({length: 3}, () => faker.number.int()))
102+ };` ;
103+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
99104 }
100105 } ) ;
101106
@@ -113,11 +118,13 @@ describe('Script Generation', () => {
113118
114119 expect ( result . success ) . to . equal ( true ) ;
115120 if ( result . success ) {
116- expect ( result . script ) . to . contain ( 'faker.person.fullName()' ) ;
117- expect ( result . script ) . to . contain ( 'faker.lorem.word()' ) ;
118- // Should have nested structure: users array containing objects with tags arrays
119- expect ( result . script ) . to . match ( / n a m e : \s * f a k e r \. p e r s o n \. f u l l N a m e \( \) / ) ;
120- expect ( result . script ) . to . match ( / t a g s : \s * A r r a y \. f r o m / ) ;
121+ const expectedReturnBlock = `return {
122+ users: Array.from({length: 3}, () => {
123+ name: faker.person.fullName(),
124+ tags: Array.from({length: 3}, () => faker.lorem.word())
125+ })
126+ };` ;
127+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
121128 }
122129 } ) ;
123130 } ) ;
@@ -139,11 +146,17 @@ describe('Script Generation', () => {
139146
140147 expect ( result . success ) . to . equal ( true ) ;
141148 if ( result . success ) {
142- expect ( result . script ) . to . contain ( 'faker.location.streetAddress()' ) ;
143- expect ( result . script ) . to . contain ( 'faker.location.city()' ) ;
144- // Should have nested object structure
145- expect ( result . script ) . to . contain ( 'profile' ) ;
146- expect ( result . script ) . to . contain ( 'address' ) ;
149+ const expectedReturnBlock = `return {
150+ users: Array.from({length: 3}, () => {
151+ profile: {
152+ address: {
153+ street: faker.location.streetAddress(),
154+ city: faker.location.city()
155+ }
156+ }
157+ })
158+ };` ;
159+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
147160 }
148161 } ) ;
149162
@@ -163,10 +176,15 @@ describe('Script Generation', () => {
163176
164177 expect ( result . success ) . to . equal ( true ) ;
165178 if ( result . success ) {
166- expect ( result . script ) . to . contain ( 'faker.lorem.sentence()' ) ;
167- expect ( result . script ) . to . contain ( 'faker.person.fullName()' ) ;
168- expect ( result . script ) . to . contain ( 'faker.lorem.words()' ) ;
169- expect ( result . script ) . to . contain ( 'faker.date.recent()' ) ;
179+ const expectedReturnBlock = `return {
180+ title: faker.lorem.sentence(),
181+ authors: Array.from({length: 3}, () => {
182+ name: faker.person.fullName(),
183+ books: Array.from({length: 3}, () => faker.lorem.words())
184+ }),
185+ publishedYear: faker.date.recent()
186+ };` ;
187+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
170188 }
171189 } ) ;
172190 } ) ;
@@ -184,10 +202,8 @@ describe('Script Generation', () => {
184202
185203 expect ( result . success ) . to . equal ( true ) ;
186204 if ( result . success ) {
187- expect ( result . script ) . to . contain ( "use('testdb')" ) ;
188- expect ( result . script ) . to . contain ( 'insertMany' ) ;
189- // Should generate empty objects
190- expect ( result . script ) . to . contain ( '{}' ) ;
205+ const expectedReturnBlock = `return {};` ;
206+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
191207 }
192208 } ) ;
193209
@@ -204,35 +220,10 @@ describe('Script Generation', () => {
204220
205221 expect ( result . success ) . to . equal ( true ) ;
206222 if ( result . success ) {
207- expect ( result . script ) . to . contain ( 'faker.number.int()' ) ;
208- expect ( result . script ) . to . match ( / v a l u e : \s * f a k e r \. n u m b e r \. i n t \( \) / ) ;
209- }
210- } ) ;
211-
212- it ( 'should handle multiple fields in the same nested object' , ( ) => {
213- const schema = {
214- 'profile.name' : createFieldMapping ( 'person.fullName' ) ,
215- 'profile.email' : createFieldMapping ( 'internet.email' ) ,
216- 'profile.age' : createFieldMapping ( 'number.int' ) ,
217- } ;
218-
219- const result = generateScript ( schema , {
220- databaseName : 'testdb' ,
221- collectionName : 'users' ,
222- documentCount : 1 ,
223- } ) ;
224-
225- expect ( result . success ) . to . equal ( true ) ;
226- if ( result . success ) {
227- // All three fields should be present in the same profile object
228- expect ( result . script ) . to . contain ( 'faker.person.fullName()' ) ;
229- expect ( result . script ) . to . contain ( 'faker.internet.email()' ) ;
230- expect ( result . script ) . to . contain ( 'faker.number.int()' ) ;
231- expect ( result . script ) . to . contain ( 'profile' ) ;
232- // Should have all fields in nested structure
233- expect ( result . script ) . to . match ( / n a m e : \s * f a k e r \. p e r s o n \. f u l l N a m e \( \) / ) ;
234- expect ( result . script ) . to . match ( / e m a i l : \s * f a k e r \. i n t e r n e t \. e m a i l \( \) / ) ;
235- expect ( result . script ) . to . match ( / a g e : \s * f a k e r \. n u m b e r \. i n t \( \) / ) ;
223+ const expectedReturnBlock = `return {
224+ value: faker.number.int()
225+ };` ;
226+ expect ( result . script ) . to . contain ( expectedReturnBlock ) ;
236227 }
237228 } ) ;
238229 } ) ;
0 commit comments