1 | const
|
2 | { expect } = require('chai'),
|
3 | Datastore = require('../src/Datastore')
|
4 |
|
5 | describe('testing document finding', () => {
|
6 | let documents = [
|
7 | { name: 'first document' },
|
8 | { name: 'second document' },
|
9 | { name: 'third document' }
|
10 | ]
|
11 |
|
12 | describe('single', () => {
|
13 | let datastore = Datastore.create(),
|
14 | insert = datastore.insert(documents)
|
15 | it('should find the first inserted doc', () => {
|
16 | return insert
|
17 | .then((inserted) => {
|
18 | return datastore.findOne()
|
19 | }).then((result) => {
|
20 | expect(result).to.be.an('object').that.has.all.keys('_id', 'name')
|
21 | })
|
22 | })
|
23 |
|
24 | it('should find the last inserted doc when sorting backwards', () => {
|
25 | return insert
|
26 | .then((inserted) => {
|
27 | return datastore.findOne().sort({ name: -1 })
|
28 | }).then((result) => {
|
29 | expect(result).to.be.an('object').that.has.all.keys('_id', 'name')
|
30 | expect(result.name).to.equal('third document')
|
31 | })
|
32 | })
|
33 | })
|
34 |
|
35 | describe('bulk', () => {
|
36 | let datastore = Datastore.create()
|
37 | it('should find all inserted docs', () => {
|
38 | return datastore.insert(documents)
|
39 | .then(() => {
|
40 | return datastore.find().exec()
|
41 | }).then((result) => {
|
42 | expect(result).to.be.an('array').that.has.lengthOf(3)
|
43 | })
|
44 | })
|
45 | })
|
46 |
|
47 | describe('find().then()', () => {
|
48 | let datastore = Datastore.create()
|
49 | it('should find all inserted docs', () => {
|
50 | return datastore.insert(documents)
|
51 | .then(() => {
|
52 | return datastore.find().then((result) => {
|
53 | expect(result).to.be.an('array').that.has.lengthOf(3)
|
54 | })
|
55 | })
|
56 | })
|
57 | })
|
58 | })
|