@@ -16,6 +16,36 @@ describe('pipe', () => {
1616 { _id : 5 , name : 'Eve' , ts : 40 , date : new Date ( '2025-07-16T05:00:00.000Z' ) } ,
1717 ] ;
1818
19+ describe ( 'missing fields' , ( ) => {
20+ it ( 'should let the rows with missing fields at the end' , ( ) => {
21+ const arr = [ ...sampleData ] ;
22+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 6 , name : 'A' , ts : 50 } as ITestData ) ;
23+
24+ const result = pipe < ITestData > ( ) . sortByField ( 'date' , 1 ) . apply ( arr ) ;
25+ expect ( result ) . toEqual ( [ ...sampleData , { _id : 6 , name : 'A' , ts : 50 } ] ) ;
26+ } ) ;
27+ it ( 'should sort by fallback fields if a field is missing' , ( ) => {
28+ // adds randomly an row if missing date
29+ const arr = [ ...sampleData ] ;
30+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 6 , name : 'A' , ts : 50 } as ITestData ) ;
31+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 7 , name : 'B' , ts : 50 } as ITestData ) ;
32+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 8 , name : 'C' , ts : 50 } as ITestData ) ;
33+
34+ const result = pipe < ITestData > ( ) . sortByField ( 'date' , 1 , [ 'name' ] ) . apply ( arr ) ;
35+ expect ( result ) . toEqual ( [ ...sampleData , { _id : 6 , name : 'A' , ts : 50 } , { _id : 7 , name : 'B' , ts : 50 } , { _id : 8 , name : 'C' , ts : 50 } ] ) ;
36+ } ) ;
37+ it ( 'should sort by fallback fields if a field is missing with second signature' , ( ) => {
38+ // adds randomly an row if missing date
39+ const arr = [ ...sampleData ] ;
40+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 6 , name : 'A' , ts : 50 } as ITestData ) ;
41+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 7 , name : 'B' , ts : 50 } as ITestData ) ;
42+ arr . splice ( Math . floor ( Math . random ( ) * arr . length ) , 0 , { _id : 8 , name : 'C' , ts : 50 } as ITestData ) ;
43+
44+ const result = pipe < ITestData > ( ) . sortByField ( [ 'date' , 'name' ] , 1 ) . apply ( arr ) ;
45+ expect ( result ) . toEqual ( [ ...sampleData , { _id : 6 , name : 'A' , ts : 50 } , { _id : 7 , name : 'B' , ts : 50 } , { _id : 8 , name : 'C' , ts : 50 } ] ) ;
46+ } ) ;
47+ } ) ;
48+
1949 it ( 'should correctly slice the array with skip and limit' , ( ) => {
2050 const result = pipe < ITestData > ( ) . slice ( 1 , 2 ) . apply ( sampleData ) ;
2151 expect ( result ) . toEqual ( [
0 commit comments