@@ -589,4 +589,132 @@ describe('InMemoryDriver', () => {
589589 expect ( results ) . toHaveLength ( 3 ) ;
590590 } ) ;
591591 } ) ;
592+
593+ describe ( 'FilterCondition Object Format (from parseFilterAST)' , ( ) => {
594+ beforeEach ( async ( ) => {
595+ await driver . create ( testTable , { id : '1' , name : 'Alice Johnson' , age : 30 , email : 'alice@example.com' , bio : null } ) ;
596+ await driver . create ( testTable , { id : '2' , name : 'Bob Smith' , age : 25 , email : 'bob@test.com' , bio : 'Developer' } ) ;
597+ await driver . create ( testTable , { id : '3' , name : 'Charlie Brown' , age : 35 , email : 'charlie@example.com' , bio : '' } ) ;
598+ await driver . create ( testTable , { id : '4' , name : 'Evan Davis' , age : 28 , email : 'evan@test.com' , bio : 'Designer' } ) ;
599+ } ) ;
600+
601+ it ( 'should filter with $contains operator' , async ( ) => {
602+ const results = await driver . find ( testTable , {
603+ object : testTable ,
604+ where : { name : { $contains : 'Evan' } } ,
605+ } ) ;
606+ expect ( results ) . toHaveLength ( 1 ) ;
607+ expect ( results [ 0 ] . name ) . toBe ( 'Evan Davis' ) ;
608+ } ) ;
609+
610+ it ( 'should filter with $contains case-insensitively' , async ( ) => {
611+ const results = await driver . find ( testTable , {
612+ object : testTable ,
613+ where : { name : { $contains : 'alice' } } ,
614+ } ) ;
615+ expect ( results ) . toHaveLength ( 1 ) ;
616+ expect ( results [ 0 ] . name ) . toBe ( 'Alice Johnson' ) ;
617+ } ) ;
618+
619+ it ( 'should filter with $notContains operator' , async ( ) => {
620+ const results = await driver . find ( testTable , {
621+ object : testTable ,
622+ where : { email : { $notContains : 'example' } } ,
623+ } ) ;
624+ expect ( results ) . toHaveLength ( 2 ) ;
625+ expect ( results . map ( ( r : any ) => r . name ) . sort ( ) ) . toEqual ( [ 'Bob Smith' , 'Evan Davis' ] ) ;
626+ } ) ;
627+
628+ it ( 'should filter with $startsWith operator' , async ( ) => {
629+ const results = await driver . find ( testTable , {
630+ object : testTable ,
631+ where : { name : { $startsWith : 'Ch' } } ,
632+ } ) ;
633+ expect ( results ) . toHaveLength ( 1 ) ;
634+ expect ( results [ 0 ] . name ) . toBe ( 'Charlie Brown' ) ;
635+ } ) ;
636+
637+ it ( 'should filter with $endsWith operator' , async ( ) => {
638+ const results = await driver . find ( testTable , {
639+ object : testTable ,
640+ where : { email : { $endsWith : '.com' } } ,
641+ } ) ;
642+ expect ( results ) . toHaveLength ( 4 ) ;
643+ } ) ;
644+
645+ it ( 'should filter with $between operator' , async ( ) => {
646+ const results = await driver . find ( testTable , {
647+ object : testTable ,
648+ where : { age : { $between : [ 26 , 32 ] } } ,
649+ } ) ;
650+ expect ( results ) . toHaveLength ( 2 ) ;
651+ expect ( results . map ( ( r : any ) => r . name ) . sort ( ) ) . toEqual ( [ 'Alice Johnson' , 'Evan Davis' ] ) ;
652+ } ) ;
653+
654+ it ( 'should filter with $null: true' , async ( ) => {
655+ const results = await driver . find ( testTable , {
656+ object : testTable ,
657+ where : { bio : { $null : true } } ,
658+ } ) ;
659+ expect ( results ) . toHaveLength ( 1 ) ;
660+ expect ( results [ 0 ] . name ) . toBe ( 'Alice Johnson' ) ;
661+ } ) ;
662+
663+ it ( 'should filter with $null: false' , async ( ) => {
664+ const results = await driver . find ( testTable , {
665+ object : testTable ,
666+ where : { bio : { $null : false } } ,
667+ } ) ;
668+ expect ( results ) . toHaveLength ( 3 ) ;
669+ } ) ;
670+
671+ it ( 'should handle $contains inside $and' , async ( ) => {
672+ const results = await driver . find ( testTable , {
673+ object : testTable ,
674+ where : { $and : [ { name : { $contains : 'a' } } , { age : { $gte : 30 } } ] } ,
675+ } ) ;
676+ expect ( results ) . toHaveLength ( 2 ) ;
677+ expect ( results . map ( ( r : any ) => r . name ) . sort ( ) ) . toEqual ( [ 'Alice Johnson' , 'Charlie Brown' ] ) ;
678+ } ) ;
679+
680+ it ( 'should handle $startsWith inside $or' , async ( ) => {
681+ const results = await driver . find ( testTable , {
682+ object : testTable ,
683+ where : { $or : [ { name : { $startsWith : 'Al' } } , { name : { $startsWith : 'Ev' } } ] } ,
684+ } ) ;
685+ expect ( results ) . toHaveLength ( 2 ) ;
686+ expect ( results . map ( ( r : any ) => r . name ) . sort ( ) ) . toEqual ( [ 'Alice Johnson' , 'Evan Davis' ] ) ;
687+ } ) ;
688+
689+ it ( 'should handle AST-converted notcontains via convertConditionToMongo' , async ( ) => {
690+ const results = await driver . find ( testTable , {
691+ object : testTable ,
692+ where : { type : 'comparison' , field : 'name' , operator : 'notcontains' , value : 'Bob' } ,
693+ } ) ;
694+ expect ( results ) . toHaveLength ( 3 ) ;
695+ } ) ;
696+
697+ it ( 'should handle combined $startsWith + $endsWith on same field' , async ( ) => {
698+ const results = await driver . find ( testTable , {
699+ object : testTable ,
700+ where : { name : { $startsWith : 'A' , $endsWith : 'son' } } ,
701+ } ) ;
702+ expect ( results ) . toHaveLength ( 1 ) ;
703+ expect ( results [ 0 ] . name ) . toBe ( 'Alice Johnson' ) ;
704+ } ) ;
705+
706+ it ( 'should filter with $null: true on missing fields' , async ( ) => {
707+ // bio is null for Alice Johnson — should match
708+ // Records without bio field at all should also match $null: true
709+ await driver . create ( testTable , { id : '5' , name : 'Frank' , age : 40 , email : 'frank@test.com' } ) ;
710+ const results = await driver . find ( testTable , {
711+ object : testTable ,
712+ where : { bio : { $null : true } } ,
713+ } ) ;
714+ // Alice (bio: null), Frank (bio: missing)
715+ expect ( results . length ) . toBeGreaterThanOrEqual ( 2 ) ;
716+ expect ( results . map ( ( r : any ) => r . name ) ) . toContain ( 'Alice Johnson' ) ;
717+ expect ( results . map ( ( r : any ) => r . name ) ) . toContain ( 'Frank' ) ;
718+ } ) ;
719+ } ) ;
592720} ) ;
0 commit comments