@@ -67,7 +67,101 @@ describe('BaseRepository', () => {
6767      const  albumsLimited  =  await  albumsSubColl . limit ( 2 ) . find ( ) ; 
6868      expect ( albumsLimited . length ) . to . equal ( 2 ) ; 
6969    } ) ; 
70-   } ) 
70+   } ) ; 
71+ 
72+   describe ( 'orderByAscending' ,  ( )  =>  { 
73+     it ( 'must order repository objects' ,  async  ( )  =>  { 
74+       const  bands  =  await  bandRepository 
75+         . orderByAscending ( 'formationYear' ) 
76+         . find ( ) ; 
77+       expect ( bands [ 0 ] . id ) . to . equal ( 'pink-floyd' ) ; 
78+     } ) ; 
79+ 
80+     it ( 'must order the objects in a subcollection' ,  async  ( )  =>  { 
81+       const  pt  =  await  bandRepository . findById ( 'porcupine-tree' ) ; 
82+       const  albumsSubColl  =  pt . albums ; 
83+       const  discographyNewestFirst  =  await  albumsSubColl 
84+         . orderByAscending ( 'releaseDate' ) 
85+         . find ( ) ; 
86+       expect ( discographyNewestFirst [ 0 ] . id ) . to . equal ( 'lightbulb-sun' ) ; 
87+     } ) ; 
88+ 
89+     it ( 'must be chainable with where* filters' ,  async  ( )  =>  { 
90+       const  pt  =  await  bandRepository . findById ( 'porcupine-tree' ) ; 
91+       const  albumsSubColl  =  pt . albums ; 
92+       const  discographyNewestFirst  =  await  albumsSubColl 
93+         . whereGreaterOrEqualThan ( 'releaseDate' ,  new  Date ( '2001-01-01' ) ) 
94+         . orderByAscending ( 'releaseDate' ) 
95+         . find ( ) ; 
96+       expect ( discographyNewestFirst [ 0 ] . id ) . to . equal ( 'in-absentia' ) ; 
97+     } ) ; 
98+ 
99+     it ( 'must be chainable with limit' ,  async  ( )  =>  { 
100+       const  bands  =  await  bandRepository 
101+         . orderByAscending ( 'formationYear' ) 
102+         . limit ( 2 ) 
103+         . find ( ) ; 
104+       const  lastBand  =  bands [ bands . length  -  1 ] ; 
105+       expect ( lastBand . id ) . to . equal ( 'red-hot-chili-peppers' ) ; 
106+     } ) ; 
107+ 
108+     it ( 'must throw an Error if an orderBy* function is called more than once in the same expression' ,  async  ( )  =>  { 
109+       const  pt  =  await  bandRepository . findById ( 'porcupine-tree' ) ; 
110+       const  albumsSubColl  =  pt . albums ; 
111+       expect ( ( )  =>  { 
112+         albumsSubColl 
113+           . orderByAscending ( 'releaseDate' ) 
114+           . orderByDescending ( 'releaseDate' ) ; 
115+       } ) . to . throw ; 
116+     } ) ; 
117+   } ) ; 
118+ 
119+   describe ( 'orderByDescending' ,  ( )  =>  { 
120+     it ( 'must order repository objects' ,  async  ( )  =>  { 
121+       const  bands  =  await  bandRepository 
122+         . orderByDescending ( 'formationYear' ) 
123+         . find ( ) ; 
124+       expect ( bands [ 0 ] . id ) . to . equal ( 'porcupine-tree' ) ; 
125+     } ) ; 
126+ 
127+     it ( 'must order the objects in a subcollection' ,  async  ( )  =>  { 
128+       const  pt  =  await  bandRepository . findById ( 'porcupine-tree' ) ; 
129+       const  albumsSubColl  =  pt . albums ; 
130+       const  discographyNewestFirst  =  await  albumsSubColl 
131+         . orderByDescending ( 'releaseDate' ) 
132+         . find ( ) ; 
133+       expect ( discographyNewestFirst [ 0 ] . id ) . to . equal ( 'fear-blank-planet' ) ; 
134+     } ) ; 
135+ 
136+     it ( 'must be chainable with where* filters' ,  async  ( )  =>  { 
137+       const  pt  =  await  bandRepository . findById ( 'porcupine-tree' ) ; 
138+       const  albumsSubColl  =  pt . albums ; 
139+       const  discographyNewestFirst  =  await  albumsSubColl 
140+         . whereGreaterOrEqualThan ( 'releaseDate' ,  new  Date ( '2001-01-01' ) ) 
141+         . orderByDescending ( 'releaseDate' ) 
142+         . find ( ) ; 
143+       expect ( discographyNewestFirst [ 0 ] . id ) . to . equal ( 'fear-blank-planet' ) ; 
144+     } ) ; 
145+ 
146+     it ( 'must be chainable with limit' ,  async  ( )  =>  { 
147+       const  bands  =  await  bandRepository 
148+         . orderByDescending ( 'formationYear' ) 
149+         . limit ( 2 ) 
150+         . find ( ) ; 
151+       const  lastBand  =  bands [ bands . length  -  1 ] ; 
152+       expect ( lastBand . id ) . to . equal ( 'red-hot-chili-peppers' ) ; 
153+     } ) ; 
154+ 
155+     it ( 'must throw an Error if an orderBy* function is called more than once in the same expression' ,  async  ( )  =>  { 
156+       const  pt  =  await  bandRepository . findById ( 'porcupine-tree' ) ; 
157+       const  albumsSubColl  =  pt . albums ; 
158+       expect ( ( )  =>  { 
159+         albumsSubColl 
160+           . orderByAscending ( 'releaseDate' ) 
161+           . orderByDescending ( 'releaseDate' ) ; 
162+       } ) . to . throw ; 
163+     } ) ; 
164+   } ) ; 
71165
72166  describe ( 'findById' ,  ( )  =>  { 
73167    it ( 'must find by id' ,  async  ( )  =>  { 
0 commit comments