@@ -266,6 +266,40 @@ describe('SQL Builder', () => {
266266 } )
267267 } )
268268
269+ describe ( 'buildFilterClause > range operator value type validation' , ( ) => {
270+ it ( 'throws when $gt on a number column receives a string' , ( ) => {
271+ const cols : ColumnDefinition [ ] = [ { name : 'age' , type : 'number' } ]
272+ expect ( ( ) => buildFilterClause ( { age : { $gt : 'eighteen' } } as Filter , TABLE , cols ) ) . toThrow (
273+ / c o l u m n " a g e " \( n u m b e r \) r e q u i r e s a n u m b e r , g o t s t r i n g /
274+ )
275+ } )
276+
277+ it ( 'throws when $gte on a date column receives a number' , ( ) => {
278+ const cols : ColumnDefinition [ ] = [ { name : 'birthDate' , type : 'date' } ]
279+ expect ( ( ) =>
280+ buildFilterClause ( { birthDate : { $gte : 1704067200000 } } as Filter , TABLE , cols )
281+ ) . toThrow ( / c o l u m n " b i r t h D a t e " \( d a t e \) r e q u i r e s a d a t e s t r i n g , g o t n u m b e r / )
282+ } )
283+
284+ it ( 'throws when $lt on an unknown column (numeric fallback) receives a string' , ( ) => {
285+ expect ( ( ) =>
286+ buildFilterClause ( { score : { $lt : 'high' } } as Filter , TABLE , NO_COLUMNS )
287+ ) . toThrow ( / c o l u m n " s c o r e " \( n u m b e r \) r e q u i r e s a n u m b e r , g o t s t r i n g / )
288+ } )
289+
290+ it ( 'accepts valid number on number column' , ( ) => {
291+ const cols : ColumnDefinition [ ] = [ { name : 'age' , type : 'number' } ]
292+ expect ( ( ) => buildFilterClause ( { age : { $gt : 18 } } , TABLE , cols ) ) . not . toThrow ( )
293+ } )
294+
295+ it ( 'accepts valid ISO string on date column' , ( ) => {
296+ const cols : ColumnDefinition [ ] = [ { name : 'birthDate' , type : 'date' } ]
297+ expect ( ( ) =>
298+ buildFilterClause ( { birthDate : { $gte : '2024-01-01' } } , TABLE , cols )
299+ ) . not . toThrow ( )
300+ } )
301+ } )
302+
269303 describe ( 'buildSortClause' , ( ) => {
270304 it ( 'returns undefined for empty sort' , ( ) => {
271305 expect ( buildSortClause ( { } , TABLE , NO_COLUMNS ) ) . toBeUndefined ( )
0 commit comments