forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.revs_diff.js
140 lines (127 loc) · 4.03 KB
/
test.revs_diff.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
var adapters = ['http', 'local'];
adapters.forEach(function (adapter) {
describe('test.revs_diff.js-' + adapter, function () {
var dbs = {};
beforeEach(function (done) {
dbs.name = testUtils.adapterUrl(adapter, 'testdb');
testUtils.cleanup([dbs.name], done);
});
afterEach(function (done) {
testUtils.cleanup([dbs.name], done);
});
it('Test revs diff', function (done) {
var db = new PouchDB(dbs.name);
var revs = [];
db.post({
test: 'somestuff',
_id: 'somestuff'
}, function (err, info) {
revs.push(info.rev);
db.put({
_id: info.id,
_rev: info.rev,
another: 'test'
}, function (err, info2) {
revs.push(info2.rev);
db.revsDiff({ 'somestuff': revs }, function (err, results) {
results.should.not.include.keys('somestuff');
revs.push('2-randomid');
db.revsDiff({ 'somestuff': revs }, function (err, results) {
results.should.include.keys('somestuff');
results.somestuff.missing.should.have.length(1);
done();
});
});
});
});
});
it('Missing docs should be returned with all revisions', function (done) {
new PouchDB(dbs.name, function (err, db) {
var revs = ['1-a', '2-a', '2-b'];
db.revsDiff({'foo': revs }, function (err, results) {
results.should.include.keys('foo');
results.foo.missing.should.deep.equal(revs, 'listed all revs');
done();
});
});
});
it('Conflicting revisions that are available', function (done) {
var doc = {_id: '939', _rev: '1-a'};
function createConflicts(db, callback) {
db.put(doc, { new_edits: false }, function (err, res) {
testUtils.putAfter(db, {
_id: '939',
_rev: '2-a'
}, '1-a', function (err, res) {
testUtils.putAfter(db, {
_id: '939',
_rev: '2-b'
}, '1-a', callback);
});
});
}
var db = new PouchDB(dbs.name);
createConflicts(db, function () {
db.revsDiff({'939': ['1-a', '2-a', '2-b']}, function (err, results) {
results.should.not.include.keys('939');
done();
});
});
});
it('Deleted revisions that are available', function (done) {
function createDeletedRevision(db, callback) {
db.put({
_id: '935',
_rev: '1-a'
}, { new_edits: false }, function (err, info) {
testUtils.putAfter(db, {
_id: '935',
_rev: '2-a',
_deleted: true
}, '1-a', callback);
});
}
var db = new PouchDB(dbs.name);
createDeletedRevision(db, function () {
db.revsDiff({'935': ['1-a', '2-a']}, function (err, results) {
results.should.not.include.keys('939');
done();
});
});
});
it('Revs diff with empty revs', function () {
return new PouchDB(dbs.name).then(function (db) {
return db.revsDiff({}).then(function (res) {
should.exist(res);
});
});
});
it('Test revs diff with reserved ID', function (done) {
var db = new PouchDB(dbs.name);
var revs = [];
db.post({
test: 'constructor',
_id: 'constructor'
}, function (err, info) {
revs.push(info.rev);
db.put({
_id: info.id,
_rev: info.rev,
another: 'test'
}, function (err, info2) {
revs.push(info2.rev);
db.revsDiff({ 'constructor': revs }, function (err, results) {
results.should.not.include.keys('constructor');
revs.push('2-randomid');
db.revsDiff({ 'constructor': revs }, function (err, results) {
results.should.include.keys('constructor');
results.constructor.missing.should.have.length(1);
done();
});
});
});
});
});
});
});