forked from jeffmitchel/meteor-local-persist
-
Notifications
You must be signed in to change notification settings - Fork 7
/
persistent-minimongo-tests.js
56 lines (43 loc) · 1.89 KB
/
persistent-minimongo-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var data = [
{ firstName: 'Albert', lastName: 'Einstein', email: '[email protected]' },
{ firstName: 'Marie', lastName: 'Curie', email: '[email protected]' },
{ firstName: 'Max', lastName: 'Planck', email: '[email protected]' }
];
// test adding, retrieving and deleting data. the tests are a bit bogus since we can't
// reload the browser to exercise the persistence. the best we can do is to verify that
// amplify has stored the correct data.
Tinytest.add('Local Persist - Insert Data', function(test) {
var testCollection = new Mongo.Collection(null);
var testObserver = new PersistentMinimongo(testCollection);
data.forEach(function (doc) {
testCollection.insert(doc);
});
// right number of adds?
test.equal(testObserver._getStats().added, data.length);
// get the tracking list and verify it has the correct number of keys
var list = amplify.store(testObserver._getKey());
test.equal(list.length, data.length);
});
Tinytest.add('Local Persist - Retrieve Data', function(test) {
var testCollection = new Mongo.Collection(null);
var testObserver = new PersistentMinimongo(testCollection);
// right number of adds?
test.equal(testObserver._getStats().added, data.length);
data.forEach(function (doc) {
m = testCollection.findOne({ lastName: doc.lastName });
a = amplify.store(testObserver._makeDataKey(m._id));
test.equal(a, m);
});
});
Tinytest.add('Local Persist - Remove Data', function(test) {
var testCollection = new Mongo.Collection(null);
var testObserver = new PersistentMinimongo(testCollection);
// right number of adds?
test.equal(testObserver._getStats().added, data.length);
testCollection.remove({});
// right number of removes?
test.equal(testObserver._getStats().removed, data.length);
// the tracking list should be gone
var list = amplify.store(testObserver._getKey());
test.equal(!! list, false);
});