@@ -182,6 +182,44 @@ export const databaseSpec = () => {
182
182
assert . end ( ) ;
183
183
} ) ;
184
184
185
+ test ( 'DB # first' , ( assert ) => {
186
+ const db = new Database ( ) ;
187
+
188
+ db . register ( 'user' , userFactory ) ;
189
+ db . create ( 'user' , 5 ) ;
190
+
191
+ const user = db . first ( 'user' ) ;
192
+
193
+ assert . ok ( _ . isObject ( user ) , 'returns first entity of collection.' ) ;
194
+ assert . equal ( user . id , 0 , 'returns correct first entity of collection.' ) ;
195
+
196
+ assert . doesNotThrow ( ( ) => db . first ( 'user' ) ,
197
+ 'Doesn\'t throw error when collection is present.' ) ;
198
+ assert . throws ( ( ) => db . first ( 'game' ) ,
199
+ 'Throws error when collection is not present.' ) ;
200
+
201
+ assert . end ( ) ;
202
+ } ) ;
203
+
204
+ test ( 'DB # last' , ( assert ) => {
205
+ const db = new Database ( ) ;
206
+
207
+ db . register ( 'user' , userFactory ) ;
208
+ db . create ( 'user' , 5 ) ;
209
+
210
+ const user = db . last ( 'user' ) ;
211
+
212
+ assert . ok ( _ . isObject ( user ) , 'returns last entity of collection.' ) ;
213
+ assert . equal ( user . id , 4 , 'returns correct last entity of collection.' ) ;
214
+
215
+ assert . doesNotThrow ( ( ) => db . last ( 'user' ) ,
216
+ 'Doesn\'t throw error when collection is present.' ) ;
217
+ assert . throws ( ( ) => db . last ( 'game' ) ,
218
+ 'Throws error when collection is not present.' ) ;
219
+
220
+ assert . end ( ) ;
221
+ } ) ;
222
+
185
223
test ( 'DB # push' , ( assert ) => {
186
224
const db = new Database ( ) ;
187
225
0 commit comments