11import { ObjectId } from 'mongodb' ;
2- import { testSetup , createLogger } from './test-setup' ;
3-
4- const log = createLogger ( 'nested-fields' ) ;
2+ import { testSetup } from './test-setup' ;
53
64describe ( 'Nested Fields Integration Tests' , ( ) => {
75 beforeAll ( async ( ) => {
@@ -62,8 +60,7 @@ describe('Nested Fields Integration Tests', () => {
6260 ` ;
6361
6462 const results = await queryLeaf . execute ( sql ) ;
65- log ( 'Nested fields results:' , JSON . stringify ( results , null , 2 ) ) ;
66-
63+
6764 // Assert: Verify we can access the data
6865 expect ( results ) . toHaveLength ( 1 ) ;
6966 expect ( results [ 0 ] . name ) . toBe ( 'John Smith' ) ;
@@ -113,17 +110,8 @@ describe('Nested Fields Integration Tests', () => {
113110 FROM contact_profiles
114111 WHERE contact.address.city = 'Boston'
115112 ` ;
116-
117- log ( 'Running nested field query:' , sql ) ;
118-
119- // Try direct MongoDB query to verify data exists
120- const directQueryResults = await testSetup . getDb ( ) . collection ( 'contact_profiles' )
121- . find ( { 'contact.address.city' : 'Boston' } )
122- . toArray ( ) ;
123- log ( 'Direct MongoDB query results:' , JSON . stringify ( directQueryResults , null , 2 ) ) ;
124-
113+
125114 const results = await queryLeaf . execute ( sql ) ;
126- log ( 'Nested filter results:' , JSON . stringify ( results , null , 2 ) ) ;
127115
128116 // Assert: Verify only Bostonians are returned
129117 expect ( results ) . toHaveLength ( 2 ) ;
@@ -176,7 +164,6 @@ describe('Nested Fields Integration Tests', () => {
176164 ` ;
177165
178166 const results = await queryLeaf . execute ( sql ) ;
179- log ( 'Nested comparison results:' , JSON . stringify ( results , null , 2 ) ) ;
180167
181168 // Assert: Verify only products matching nested criteria are returned
182169 expect ( results ) . toHaveLength ( 2 ) ;
@@ -227,11 +214,7 @@ describe('Nested Fields Integration Tests', () => {
227214 }
228215 }
229216 ] ) ;
230-
231- // Act - first check with direct MongoDB query to confirm data
232- const directLaptopQuery = await db . collection ( 'products' ) . findOne ( { name : 'Laptop' } ) ;
233- log ( 'Direct laptop query result:' , JSON . stringify ( directLaptopQuery , null , 2 ) ) ;
234-
217+
235218 // Use QueryLeaf to query the data
236219 const queryLeaf = testSetup . getQueryLeaf ( ) ;
237220 const sql = `
@@ -243,13 +226,7 @@ describe('Nested Fields Integration Tests', () => {
243226 ` ;
244227
245228 const results = await queryLeaf . execute ( sql ) ;
246- log ( 'Nested fields query results:' , JSON . stringify ( results , null , 2 ) ) ;
247-
248- // Helper function to safely access nested properties
249- const getNestedProp = ( obj : any , path : string [ ] ) => {
250- return path . reduce ( ( o , key ) => ( o && typeof o === 'object' ) ? o [ key ] : undefined , obj ) ;
251- } ;
252-
229+
253230 // Assert: Verify results count and basic structure
254231 expect ( results ) . toHaveLength ( 2 ) ;
255232
@@ -361,11 +338,7 @@ describe('Nested Fields Integration Tests', () => {
361338 zip : '98101'
362339 }
363340 } ) ;
364-
365- // Verify the data with a direct MongoDB query
366- const directQuery = await db . collection ( 'products' ) . findOne ( { name : 'Tablet' } ) ;
367- log ( 'Direct query result:' , JSON . stringify ( directQuery , null , 2 ) ) ;
368-
341+
369342 // Act: Execute a query selecting a nested field
370343 const queryLeaf = testSetup . getQueryLeaf ( ) ;
371344 const sql = `
@@ -375,31 +348,13 @@ describe('Nested Fields Integration Tests', () => {
375348 FROM products
376349 WHERE name = 'Tablet'
377350 ` ;
378-
379- log ( 'Running nested field selection query:' , sql ) ;
380-
381- // Use a direct MongoDB aggregate query to test our approach
382- const directAggregateResult = await db . collection ( 'products' ) . aggregate ( [
383- { $match : { name : 'Tablet' } } ,
384- { $project : {
385- name : 1 ,
386- address_city : '$address.city'
387- }
388- }
389- ] ) . toArray ( ) ;
390- log ( 'Direct aggregate result:' , JSON . stringify ( directAggregateResult , null , 2 ) ) ;
391-
392- // Use the direct MongoDB aggregation to verify the approach works
351+
393352 const results = await queryLeaf . execute ( sql ) ;
394- log ( 'Nested field selection results:' , JSON . stringify ( results , null , 2 ) ) ;
395353
396354 // Assert: Verify we can access the nested field data
397355 expect ( results ) . toHaveLength ( 1 ) ;
398356 expect ( results [ 0 ] . name ) . toBe ( 'Tablet' ) ;
399357
400- // Log the structure of the results for debugging
401- log ( 'Result structure:' , JSON . stringify ( results [ 0 ] , null , 2 ) ) ;
402-
403358 // With the updated implementation, the nested field should be "pulled up" to the top level
404359 // The field should be directly accessible using the field name without the parent part
405360 expect ( results [ 0 ] . name ) . toBe ( 'Tablet' ) ;
@@ -438,31 +393,12 @@ describe('Nested Fields Integration Tests', () => {
438393 WHERE name = 'Monitor'
439394 ` ;
440395
441- log ( 'Running multiple nested field selection query:' , sql ) ;
442396 const results = await queryLeaf . execute ( sql ) ;
443- log ( 'Multiple nested field selection results:' , JSON . stringify ( results , null , 2 ) ) ;
444-
397+
445398 // Assert: Verify we can access the nested field data at the top level
446399 expect ( results ) . toHaveLength ( 1 ) ;
447400 expect ( results [ 0 ] . name ) . toBe ( 'Monitor' ) ;
448-
449- // Log the full results for debugging
450- console . log ( 'FULL RESULTS:' , JSON . stringify ( results [ 0 ] , null , 2 ) ) ;
451- console . log ( 'AVAILABLE KEYS:' , Object . keys ( results [ 0 ] ) ) ;
452-
453- // For debugging, execute a direct MongoDB aggregation
454- const directAggResult = await db . collection ( 'products' ) . aggregate ( [
455- { $match : { name : 'Monitor' } } ,
456- { $project : {
457- name : 1 ,
458- specs_resolution : '$specs.resolution' ,
459- specs_refreshRate : '$specs.refreshRate' ,
460- specs_size_diagonal : '$specs.size.diagonal'
461- }
462- }
463- ] ) . toArray ( ) ;
464- console . log ( 'DIRECT AGGREGATE:' , JSON . stringify ( directAggResult [ 0 ] , null , 2 ) ) ;
465-
401+
466402 // All nested fields should be flattened to the top level with underscore notation
467403 expect ( results [ 0 ] . specs_resolution ) . toBe ( '4K' ) ;
468404 expect ( results [ 0 ] . specs_refreshRate ) . toBe ( 144 ) ;
@@ -471,4 +407,4 @@ describe('Nested Fields Integration Tests', () => {
471407 // The original nested structure should not be present
472408 expect ( results [ 0 ] . specs ) . toBeUndefined ( ) ;
473409 } ) ;
474- } ) ;
410+ } ) ;
0 commit comments