Skip to content

Commit bf2c404

Browse files
committed
test(Database/first+last): Add tests for Database.first and Database.last
1 parent b3ff923 commit bf2c404

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/specs/database_spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,44 @@ export const databaseSpec = () => {
182182
assert.end();
183183
});
184184

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+
185223
test('DB # push', (assert) => {
186224
const db = new Database();
187225

0 commit comments

Comments
 (0)