viewdb 0.5.12 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +1 -0
- package/README.md +416 -1
- package/jest.config.js +11 -0
- package/lib/cursor.js +13 -9
- package/lib/index.js +1 -1
- package/lib/inmemory/collection.js +8 -10
- package/lib/inmemory/store.js +12 -12
- package/lib/merger.js +55 -56
- package/lib/observe.js +41 -41
- package/lib/plugins/viewdb_timestamp_plugin.js +2 -2
- package/lib/plugins/viewdb_versioning_plugin.js +7 -9
- package/lib/viewdb.js +12 -14
- package/package.json +12 -11
- package/test/cursor.js +50 -35
- package/test/merger.js +193 -160
- package/test/observe.js +63 -25
- package/test/plugins/viewdb_timestamp_plugin.js +39 -35
- package/test/plugins/viewdb_versioning_plugin.js +28 -28
- package/test/viewdb.js +88 -77
|
@@ -1,57 +1,55 @@
|
|
|
1
|
-
var should = require('should');
|
|
2
1
|
var ViewDb = require('../..');
|
|
3
2
|
var ViewDbTimestampPlugin = require('../..').plugins.TimestampPlugin;
|
|
4
3
|
var ViewDBVersioningPlugin = require('../..').plugins.VersioningPlugin;
|
|
5
4
|
|
|
6
|
-
describe('Viewdb timestamp plugin',
|
|
7
|
-
it('should add changeDateTime and createDateTime timestamp on insert',
|
|
5
|
+
describe('Viewdb timestamp plugin', () => {
|
|
6
|
+
it('should add changeDateTime and createDateTime timestamp on insert', (done) => {
|
|
8
7
|
var viewDb = new ViewDb();
|
|
9
8
|
new ViewDbTimestampPlugin(viewDb);
|
|
10
9
|
new ViewDBVersioningPlugin(viewDb);
|
|
11
10
|
var obj = { id: '123' };
|
|
12
11
|
var collection = viewDb.collection('test');
|
|
13
|
-
var currentTime =
|
|
12
|
+
var currentTime = new Date().valueOf();
|
|
14
13
|
|
|
15
14
|
// wait 1ms until update operation to check for lastModified updated
|
|
16
15
|
setTimeout(function () {
|
|
17
16
|
collection.insert(obj, function () {
|
|
18
17
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
19
18
|
var object = objects[0];
|
|
20
|
-
|
|
19
|
+
expect(object.createDateTime).exists;
|
|
21
20
|
if (currentTime < object.createDateTime) {
|
|
22
21
|
done();
|
|
23
22
|
} else {
|
|
24
|
-
done(new Error('Timestamp was not renewed'))
|
|
23
|
+
done(new Error('Timestamp was not renewed'));
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
});
|
|
28
27
|
}, 5);
|
|
29
28
|
});
|
|
30
|
-
it('should add changeDateTime and createDateTime timestamp on bulk insert',
|
|
29
|
+
it('should add changeDateTime and createDateTime timestamp on bulk insert', (done) => {
|
|
31
30
|
var viewDb = new ViewDb();
|
|
32
31
|
new ViewDbTimestampPlugin(viewDb);
|
|
33
32
|
new ViewDBVersioningPlugin(viewDb);
|
|
34
33
|
var collection = viewDb.collection('test');
|
|
35
|
-
var currentTime =
|
|
34
|
+
var currentTime = new Date().valueOf();
|
|
36
35
|
|
|
37
36
|
// wait 1ms until update operation to check for lastModified updated
|
|
38
37
|
setTimeout(function () {
|
|
39
38
|
collection.insert([{ _id: '123' }, { _id: '999' }], function () {
|
|
40
39
|
collection.find({}).toArray(function (err, objects) {
|
|
41
|
-
var object = objects[0];
|
|
42
40
|
var hasError = false;
|
|
43
41
|
objects.forEach(function (object) {
|
|
44
|
-
|
|
42
|
+
expect(object.createDateTime).exists;
|
|
45
43
|
if (currentTime >= object.createDateTime) {
|
|
46
44
|
hasError = true;
|
|
47
45
|
}
|
|
48
46
|
});
|
|
49
|
-
hasError && done(new Error('Timestamp was not renewed')) || done();
|
|
47
|
+
(hasError && done(new Error('Timestamp was not renewed'))) || done();
|
|
50
48
|
});
|
|
51
49
|
});
|
|
52
50
|
});
|
|
53
51
|
});
|
|
54
|
-
it('should update changeDateTime on builk save',
|
|
52
|
+
it('should update changeDateTime on builk save', (done) => {
|
|
55
53
|
var viewDb = new ViewDb();
|
|
56
54
|
new ViewDbTimestampPlugin(viewDb);
|
|
57
55
|
new ViewDBVersioningPlugin(viewDb);
|
|
@@ -61,24 +59,30 @@ describe('Viewdb timestamp plugin', function () {
|
|
|
61
59
|
collection.find({}).toArray(function (err, objects) {
|
|
62
60
|
var insertTime = objects[0].createDateTime;
|
|
63
61
|
var updateTime = objects[0].changeDateTime;
|
|
64
|
-
|
|
65
|
-
insertTime.
|
|
62
|
+
expect(insertTime).toBeDefined();
|
|
63
|
+
expect(insertTime).toBe(updateTime);
|
|
66
64
|
setTimeout(function () {
|
|
67
|
-
collection.save(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
collection.save(
|
|
66
|
+
[
|
|
67
|
+
{ _id: '123', name: 'Pelle', createDateTime: insertTime, changeDateTime: insertTime },
|
|
68
|
+
{ _id: '999', name: 'Kalle', createDateTime: insertTime, changeDateTime: insertTime }
|
|
69
|
+
],
|
|
70
|
+
function () {
|
|
71
|
+
collection.find({}).toArray(function (err, objects) {
|
|
72
|
+
objects.forEach(function (object) {
|
|
73
|
+
expect(object.createDateTime).toBe(insertTime);
|
|
74
|
+
expect(object.changeDateTime).toBeGreaterThan(insertTime);
|
|
75
|
+
});
|
|
76
|
+
done();
|
|
72
77
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
})
|
|
78
|
+
}
|
|
79
|
+
);
|
|
76
80
|
}, 100);
|
|
77
81
|
});
|
|
78
82
|
|
|
79
83
|
// wait 1ms until update operation to check for lastModified updated
|
|
80
84
|
});
|
|
81
|
-
it('should update changeDateTime on save',
|
|
85
|
+
it('should update changeDateTime on save', (done) => {
|
|
82
86
|
var viewDb = new ViewDb();
|
|
83
87
|
new ViewDbTimestampPlugin(viewDb);
|
|
84
88
|
new ViewDBVersioningPlugin(viewDb);
|
|
@@ -98,14 +102,14 @@ describe('Viewdb timestamp plugin', function () {
|
|
|
98
102
|
collection.save(obj);
|
|
99
103
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
100
104
|
var object = objects[0];
|
|
101
|
-
object.createDateTime.
|
|
102
|
-
object.changeDateTime.
|
|
105
|
+
expect(object.createDateTime).toBe(insertTime);
|
|
106
|
+
expect(object.changeDateTime).toBeGreaterThan(insertTime);
|
|
103
107
|
done();
|
|
104
108
|
});
|
|
105
|
-
}, 1)
|
|
109
|
+
}, 1);
|
|
106
110
|
});
|
|
107
111
|
|
|
108
|
-
it('should skip changing timestamp with skipTimestamp option on save',
|
|
112
|
+
it('should skip changing timestamp with skipTimestamp option on save', (done) => {
|
|
109
113
|
var viewDb = new ViewDb();
|
|
110
114
|
new ViewDbTimestampPlugin(viewDb);
|
|
111
115
|
new ViewDBVersioningPlugin(viewDb);
|
|
@@ -125,15 +129,15 @@ describe('Viewdb timestamp plugin', function () {
|
|
|
125
129
|
collection.save(obj, { skipTimestamp: true }, function () {
|
|
126
130
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
127
131
|
var object = objects[0];
|
|
128
|
-
object.createDateTime.
|
|
129
|
-
object.changeDateTime.
|
|
132
|
+
expect(object.createDateTime).toBe(insertTime);
|
|
133
|
+
expect(object.changeDateTime).toBe(insertTime);
|
|
130
134
|
done();
|
|
131
135
|
});
|
|
132
136
|
});
|
|
133
|
-
}, 1)
|
|
137
|
+
}, 1);
|
|
134
138
|
});
|
|
135
139
|
|
|
136
|
-
it('should work together with version plugin',
|
|
140
|
+
it('should work together with version plugin', (done) => {
|
|
137
141
|
var viewDb = new ViewDb();
|
|
138
142
|
new ViewDbTimestampPlugin(viewDb);
|
|
139
143
|
new ViewDBVersioningPlugin(viewDb);
|
|
@@ -145,10 +149,10 @@ describe('Viewdb timestamp plugin', function () {
|
|
|
145
149
|
collection.save(obj);
|
|
146
150
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
147
151
|
var object = objects[0];
|
|
148
|
-
object.version.
|
|
149
|
-
object.name.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
expect(object.version).toBe(0);
|
|
153
|
+
expect(object.name).toBe('Pelle');
|
|
154
|
+
expect(object.createDateTime).exists;
|
|
155
|
+
expect(object.changeDateTime).exists;
|
|
152
156
|
done();
|
|
153
157
|
});
|
|
154
158
|
});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
var should = require('should');
|
|
2
1
|
var _ = require('lodash');
|
|
3
2
|
|
|
4
3
|
var ViewDb = require('../..');
|
|
5
4
|
var ViewDbVersioningPlugin = require('../..').plugins.VersioningPlugin;
|
|
6
5
|
|
|
7
|
-
describe('Viewdb versioning plugin',
|
|
8
|
-
it('should add version on insert',
|
|
6
|
+
describe('Viewdb versioning plugin', () => {
|
|
7
|
+
it('should add version on insert', (done) => {
|
|
9
8
|
var viewDb = new ViewDb();
|
|
10
9
|
new ViewDbVersioningPlugin(viewDb);
|
|
11
10
|
var obj = { id: '123' };
|
|
@@ -16,11 +15,11 @@ describe('Viewdb versioning plugin', function () {
|
|
|
16
15
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
17
16
|
var object = objects[0];
|
|
18
17
|
|
|
19
|
-
object.version.
|
|
18
|
+
expect(object.version).toBe(0);
|
|
20
19
|
done();
|
|
21
20
|
});
|
|
22
21
|
});
|
|
23
|
-
it('should add version on builk insert',
|
|
22
|
+
it('should add version on builk insert', (done) => {
|
|
24
23
|
var viewDb = new ViewDb();
|
|
25
24
|
new ViewDbVersioningPlugin(viewDb);
|
|
26
25
|
|
|
@@ -28,12 +27,12 @@ describe('Viewdb versioning plugin', function () {
|
|
|
28
27
|
collection.insert([{ id: '123' }, { id: '999' }]);
|
|
29
28
|
|
|
30
29
|
collection.find({}).toArray(function (err, objects) {
|
|
31
|
-
objects[0].version.
|
|
32
|
-
objects[1].version.
|
|
30
|
+
expect(objects[0].version).toBe(0);
|
|
31
|
+
expect(objects[1].version).toBe(0);
|
|
33
32
|
done();
|
|
34
33
|
});
|
|
35
34
|
});
|
|
36
|
-
it('should increase version on save',
|
|
35
|
+
it('should increase version on save', (done) => {
|
|
37
36
|
var viewDb = new ViewDb();
|
|
38
37
|
new ViewDbVersioningPlugin(viewDb);
|
|
39
38
|
var obj = { id: '123' };
|
|
@@ -45,34 +44,37 @@ describe('Viewdb versioning plugin', function () {
|
|
|
45
44
|
|
|
46
45
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
47
46
|
var object = objects[0];
|
|
48
|
-
object.version.
|
|
49
|
-
object.name.
|
|
47
|
+
expect(object.version).toBe(1);
|
|
48
|
+
expect(object.name).toBe('Pelle');
|
|
50
49
|
done();
|
|
51
50
|
});
|
|
52
51
|
});
|
|
53
52
|
|
|
54
|
-
it('should increase version on bulk save',
|
|
53
|
+
it('should increase version on bulk save', (done) => {
|
|
55
54
|
var viewDb = new ViewDb();
|
|
56
55
|
new ViewDbVersioningPlugin(viewDb);
|
|
57
56
|
|
|
58
57
|
var collection = viewDb.collection('test');
|
|
59
|
-
collection.insert([
|
|
58
|
+
collection.insert([
|
|
59
|
+
{ _id: '123', version: 10 },
|
|
60
|
+
{ _id: '999', version: 101 }
|
|
61
|
+
]);
|
|
60
62
|
collection.find({}).toArray(function (err, objects) {
|
|
61
63
|
_.forEach(objects, function (o, i) {
|
|
62
64
|
o.name = i === 0 ? 'Pelle' : 'Kalle';
|
|
63
|
-
})
|
|
65
|
+
});
|
|
64
66
|
collection.save(objects, function () {
|
|
65
67
|
collection.find({}).toArray(function (err, objects) {
|
|
66
|
-
objects[0].version.
|
|
67
|
-
objects[0].name.
|
|
68
|
-
objects[1].version.
|
|
69
|
-
objects[1].name.
|
|
68
|
+
expect(objects[0].version).toBe(12); // add 1 version for insert and one for save
|
|
69
|
+
expect(objects[0].name).toBe('Pelle');
|
|
70
|
+
expect(objects[1].version).toBe(103);
|
|
71
|
+
expect(objects[1].name).toBe('Kalle');
|
|
70
72
|
done();
|
|
71
73
|
});
|
|
72
74
|
});
|
|
73
75
|
});
|
|
74
76
|
});
|
|
75
|
-
it('should skip changing version with skipVersioning option on save',
|
|
77
|
+
it('should skip changing version with skipVersioning option on save', (done) => {
|
|
76
78
|
var viewDb = new ViewDb();
|
|
77
79
|
new ViewDbVersioningPlugin(viewDb);
|
|
78
80
|
var obj = { id: '123' };
|
|
@@ -80,16 +82,16 @@ describe('Viewdb versioning plugin', function () {
|
|
|
80
82
|
var collection = viewDb.collection('test');
|
|
81
83
|
collection.insert(obj);
|
|
82
84
|
obj.name = 'Pelle';
|
|
83
|
-
collection.save(obj, {skipVersioning: true});
|
|
85
|
+
collection.save(obj, { skipVersioning: true });
|
|
84
86
|
|
|
85
87
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
86
88
|
var object = objects[0];
|
|
87
|
-
object.version.
|
|
88
|
-
object.name.
|
|
89
|
+
expect(object.version).toBe(0); // still version 0
|
|
90
|
+
expect(object.name).toBe('Pelle');
|
|
89
91
|
done();
|
|
90
92
|
});
|
|
91
|
-
});
|
|
92
|
-
it('should add version on save',
|
|
93
|
+
});
|
|
94
|
+
it('should add version on save', (done) => {
|
|
93
95
|
var viewDb = new ViewDb();
|
|
94
96
|
new ViewDbVersioningPlugin(viewDb);
|
|
95
97
|
var obj = { id: '123' };
|
|
@@ -102,11 +104,9 @@ describe('Viewdb versioning plugin', function () {
|
|
|
102
104
|
|
|
103
105
|
collection.find({ id: '123' }).toArray(function (err, objects) {
|
|
104
106
|
var object = objects[0];
|
|
105
|
-
object.version.
|
|
106
|
-
object.name.
|
|
107
|
+
expect(object.version).toBe(0);
|
|
108
|
+
expect(object.name).toBe('Pelle');
|
|
107
109
|
done();
|
|
108
110
|
});
|
|
109
111
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})
|
|
112
|
+
});
|
package/test/viewdb.js
CHANGED
|
@@ -1,199 +1,210 @@
|
|
|
1
|
-
var should = require('should');
|
|
2
|
-
|
|
3
1
|
var ViewDB = require('..');
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
describe('
|
|
7
|
-
|
|
8
|
-
it('should return 0 for empty collection', function (done) {
|
|
3
|
+
describe('ViewDB', () => {
|
|
4
|
+
describe('#count', () => {
|
|
5
|
+
it('should return 0 for empty collection', (done) => {
|
|
9
6
|
var db = new ViewDB();
|
|
10
7
|
var collection = db.collection('documents');
|
|
11
8
|
// Perform a total count command
|
|
12
9
|
collection.count(function (err, count) {
|
|
13
|
-
count.
|
|
10
|
+
expect(count).toBe(0);
|
|
14
11
|
done();
|
|
15
12
|
});
|
|
16
13
|
});
|
|
17
14
|
});
|
|
18
|
-
describe('#insert',
|
|
19
|
-
it('should store a document and include it in count',
|
|
15
|
+
describe('#insert', () => {
|
|
16
|
+
it('should store a document and include it in count', (done) => {
|
|
20
17
|
var db = new ViewDB();
|
|
21
18
|
var collection = db.collection('documents');
|
|
22
|
-
collection.insert({ a: 1 }, function (err
|
|
23
|
-
|
|
19
|
+
collection.insert({ a: 1 }, function (err) {
|
|
20
|
+
expect(err).toBeFalsy();
|
|
24
21
|
// Perform a total count command
|
|
25
22
|
collection.count(function (err, count) {
|
|
26
|
-
count.
|
|
23
|
+
expect(count).toBe(1);
|
|
27
24
|
done();
|
|
28
25
|
//assert.equal(null, err);
|
|
29
26
|
//assert.equal(1, count);
|
|
30
27
|
});
|
|
31
28
|
});
|
|
32
29
|
});
|
|
33
|
-
it('should add id on insert if missing',
|
|
30
|
+
it('should add id on insert if missing', (done) => {
|
|
34
31
|
var db = new ViewDB();
|
|
35
32
|
var collection = db.collection('documents');
|
|
36
|
-
collection.insert({ a: 1 }, function (
|
|
33
|
+
collection.insert({ a: 1 }, function () {
|
|
37
34
|
collection.find({ a: 1 }).toArray(function (err, res) {
|
|
38
|
-
|
|
35
|
+
expect(res[0]._id).toBeDefined();
|
|
39
36
|
done();
|
|
40
37
|
});
|
|
41
38
|
});
|
|
42
39
|
});
|
|
43
|
-
it('should fail at storing a previously stored document',
|
|
40
|
+
it('should fail at storing a previously stored document', (done) => {
|
|
44
41
|
var db = new ViewDB();
|
|
45
42
|
var collection = db.collection('documents');
|
|
46
|
-
collection.insert({
|
|
47
|
-
collection.insert({
|
|
48
|
-
|
|
43
|
+
collection.insert({ _id: 1, a: 1 });
|
|
44
|
+
collection.insert({ _id: 1, a: 2 }, function (err) {
|
|
45
|
+
expect(err).toBeDefined();
|
|
49
46
|
done();
|
|
50
47
|
});
|
|
51
48
|
});
|
|
52
49
|
|
|
53
|
-
it('should fail at storing an empty document',
|
|
50
|
+
it('should fail at storing an empty document', (done) => {
|
|
54
51
|
var db = new ViewDB();
|
|
55
52
|
var collection = db.collection('documents');
|
|
56
|
-
collection.insert(1, function (err
|
|
57
|
-
|
|
53
|
+
collection.insert(1, function (err) {
|
|
54
|
+
expect(err).toBeDefined();
|
|
58
55
|
done();
|
|
59
56
|
});
|
|
60
57
|
});
|
|
61
|
-
it('#insert bulk should work',
|
|
58
|
+
it('#insert bulk should work', (done) => {
|
|
62
59
|
var db = new ViewDB();
|
|
63
60
|
var collection = db.collection('documents');
|
|
64
|
-
collection.insert([{ a: 1 }, { b: 2 }], function (
|
|
61
|
+
collection.insert([{ a: 1 }, { b: 2 }], function () {
|
|
65
62
|
collection.count(function (err, res) {
|
|
66
|
-
res.
|
|
63
|
+
expect(res).toBe(2);
|
|
67
64
|
});
|
|
68
65
|
done();
|
|
69
66
|
});
|
|
70
67
|
});
|
|
71
68
|
});
|
|
72
|
-
describe('#save',
|
|
73
|
-
it('should save multiple',
|
|
69
|
+
describe('#save', () => {
|
|
70
|
+
it('should save multiple', (done) => {
|
|
74
71
|
var db = new ViewDB();
|
|
75
72
|
var collection = db.collection('documents');
|
|
76
|
-
collection.insert(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
collection.insert(
|
|
74
|
+
[
|
|
75
|
+
{ _id: 1, a: 1 },
|
|
76
|
+
{ _id: 2, b: 2 }
|
|
77
|
+
],
|
|
78
|
+
function () {
|
|
79
|
+
collection.save(
|
|
80
|
+
[
|
|
81
|
+
{ _id: 1, a: 10 },
|
|
82
|
+
{ _id: 2, b: 20 }
|
|
83
|
+
],
|
|
84
|
+
function () {
|
|
85
|
+
collection.find({}).toArray(function (err, res) {
|
|
86
|
+
expect(res.length).toBe(2);
|
|
87
|
+
expect(res[0].a).toBe(10);
|
|
88
|
+
expect(res[1].b).toBe(20);
|
|
89
|
+
done();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
);
|
|
86
95
|
});
|
|
87
|
-
it('should add id on insert if missing',
|
|
96
|
+
it('should add id on insert if missing', (done) => {
|
|
88
97
|
var db = new ViewDB();
|
|
89
98
|
var collection = db.collection('documents');
|
|
90
99
|
collection.save({ a: 1 });
|
|
91
100
|
collection.save({ b: 1 });
|
|
92
101
|
collection.count(function (err, result) {
|
|
93
|
-
result.
|
|
102
|
+
expect(result).toBe(2);
|
|
94
103
|
done();
|
|
95
|
-
})
|
|
104
|
+
});
|
|
96
105
|
});
|
|
97
|
-
it('should add document on save',
|
|
106
|
+
it('should add document on save', (done) => {
|
|
98
107
|
var db = new ViewDB();
|
|
99
108
|
var collection = db.collection('documents');
|
|
100
|
-
collection.save({ a: 1 }, function (
|
|
109
|
+
collection.save({ a: 1 }, function () {
|
|
101
110
|
collection.count(function (err, count) {
|
|
102
|
-
count.
|
|
111
|
+
expect(count).toBe(1);
|
|
103
112
|
done();
|
|
104
113
|
});
|
|
105
114
|
//should.exist(ids._id);
|
|
106
115
|
//done();
|
|
107
116
|
});
|
|
108
117
|
});
|
|
109
|
-
it('should merge if id exists',
|
|
118
|
+
it('should merge if id exists', (done) => {
|
|
110
119
|
var db = new ViewDB();
|
|
111
120
|
var collection = db.collection('documents');
|
|
112
121
|
collection.save({ a: 1 }, function (err, docs) {
|
|
113
122
|
docs[0]['b'] = 2;
|
|
114
|
-
collection.save(docs, function (
|
|
123
|
+
collection.save(docs, function () {
|
|
115
124
|
collection.count(function (err, count) {
|
|
116
|
-
count.
|
|
125
|
+
expect(count).toBe(1);
|
|
117
126
|
done();
|
|
118
127
|
});
|
|
119
128
|
});
|
|
120
|
-
|
|
121
129
|
});
|
|
122
130
|
});
|
|
123
131
|
});
|
|
124
|
-
describe('#find',
|
|
125
|
-
it('find all documents',
|
|
132
|
+
describe('#find', () => {
|
|
133
|
+
it('find all documents', (done) => {
|
|
126
134
|
var db = new ViewDB();
|
|
127
135
|
var collection = db.collection('documents');
|
|
128
|
-
collection.insert({ a: 1 }, function (
|
|
136
|
+
collection.insert({ a: 1 }, function () {
|
|
129
137
|
collection.find({}).toArray(function (err, docs) {
|
|
130
|
-
docs.length.
|
|
131
|
-
docs[0].a.
|
|
138
|
+
expect(docs.length).toBe(1);
|
|
139
|
+
expect(docs[0].a).toBe(1);
|
|
132
140
|
done();
|
|
133
141
|
});
|
|
134
142
|
});
|
|
135
143
|
});
|
|
136
|
-
it('find one document',
|
|
144
|
+
it('find one document', (done) => {
|
|
137
145
|
var db = new ViewDB();
|
|
138
146
|
var collection = db.collection('documents');
|
|
139
147
|
collection.insert({ a: 1 }, function (err, ids) {
|
|
140
148
|
collection.find({ _id: ids[0]._id }).toArray(function (err, docs) {
|
|
141
|
-
docs.length.
|
|
142
|
-
docs[0].a.
|
|
149
|
+
expect(docs.length).toBe(1);
|
|
150
|
+
expect(docs[0].a).toBe(1);
|
|
143
151
|
done();
|
|
144
152
|
});
|
|
145
153
|
});
|
|
146
154
|
});
|
|
147
|
-
it('should return empty collection if query does not match',
|
|
155
|
+
it('should return empty collection if query does not match', (done) => {
|
|
148
156
|
var db = new ViewDB();
|
|
149
157
|
var collection = db.collection('documents');
|
|
150
|
-
collection.insert({ a: 1 }, function (
|
|
158
|
+
collection.insert({ a: 1 }, function () {
|
|
151
159
|
collection.find({ _id: 5 }).toArray(function (err, docs) {
|
|
152
|
-
docs.length.
|
|
160
|
+
expect(docs.length).toBe(0);
|
|
153
161
|
done();
|
|
154
162
|
});
|
|
155
163
|
});
|
|
156
164
|
});
|
|
157
165
|
});
|
|
158
|
-
describe('#remove',
|
|
159
|
-
it('should remove one document matching a query',
|
|
166
|
+
describe('#remove', () => {
|
|
167
|
+
it('should remove one document matching a query', (done) => {
|
|
160
168
|
var db = new ViewDB();
|
|
161
169
|
var collection = db.collection('documents');
|
|
162
|
-
collection.insert({ a: 1, name: 'hello' }, function (
|
|
163
|
-
collection.remove({ name: 'hello' }, null, function (
|
|
170
|
+
collection.insert({ a: 1, name: 'hello' }, function () {
|
|
171
|
+
collection.remove({ name: 'hello' }, null, function () {
|
|
164
172
|
collection.find({}).toArray(function (err, res) {
|
|
165
|
-
res.length.
|
|
173
|
+
expect(res.length).toBe(0);
|
|
166
174
|
done();
|
|
167
175
|
});
|
|
168
|
-
})
|
|
176
|
+
});
|
|
169
177
|
});
|
|
170
|
-
})
|
|
178
|
+
});
|
|
171
179
|
|
|
172
|
-
it('shouldnt do anything when no documents are matched against the query',
|
|
180
|
+
it('shouldnt do anything when no documents are matched against the query', (done) => {
|
|
173
181
|
var db = new ViewDB();
|
|
174
182
|
var collection = db.collection('documents');
|
|
175
|
-
collection.insert({ a: 1, name: 'hello' }, function (
|
|
176
|
-
collection.remove({ name: 'world' }, null, function (
|
|
183
|
+
collection.insert({ a: 1, name: 'hello' }, function () {
|
|
184
|
+
collection.remove({ name: 'world' }, null, function () {
|
|
177
185
|
collection.find({}).toArray(function (err, res) {
|
|
178
|
-
res.length.
|
|
186
|
+
expect(res.length).toBe(1);
|
|
179
187
|
done();
|
|
180
188
|
});
|
|
181
|
-
})
|
|
189
|
+
});
|
|
182
190
|
});
|
|
183
191
|
});
|
|
184
192
|
});
|
|
185
|
-
describe('#drop',
|
|
186
|
-
it('should remove all documents',
|
|
193
|
+
describe('#drop', () => {
|
|
194
|
+
it('should remove all documents', (done) => {
|
|
187
195
|
var store = new ViewDB();
|
|
188
196
|
store.open().then(function () {
|
|
189
197
|
store.collection('dollhouse').insert({ _id: 'echo' });
|
|
190
198
|
store.collection('dollhouse').drop();
|
|
191
199
|
|
|
192
|
-
store
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
store
|
|
201
|
+
.collection('dollhouse')
|
|
202
|
+
.find({})
|
|
203
|
+
.toArray(function (err, results) {
|
|
204
|
+
expect(results.length).toBe(0);
|
|
205
|
+
done();
|
|
206
|
+
});
|
|
196
207
|
});
|
|
197
208
|
});
|
|
198
209
|
});
|
|
199
|
-
});
|
|
210
|
+
});
|