forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.reserved.js
66 lines (59 loc) · 2.02 KB
/
test.reserved.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
'use strict';
var adapters = [
['local', 'http'],
['http', 'http'],
['http', 'local'],
['local', 'local']
];
adapters.forEach(function (adapters) {
describe('test.reserved.js-' + adapters[0] + '-' + adapters[1], function () {
var dbs = {};
beforeEach(function (done) {
dbs.name = testUtils.adapterUrl(adapters[0], 'testdb');
dbs.remote = testUtils.adapterUrl(adapters[1], 'test_repl_remote');
testUtils.cleanup([dbs.name, dbs.remote], done);
});
after(function (done) {
testUtils.cleanup([dbs.name, dbs.remote], done);
});
it('test docs with reserved javascript ids', function () {
var db = new PouchDB(dbs.name);
var remote = new PouchDB(dbs.remote);
return db.bulkDocs([
{_id: 'constructor'},
{_id: 'toString'},
{_id: 'valueOf'}
]).then(function () {
return db.allDocs({key: 'constructor'});
}).then(function (res) {
res.rows.should.have.length(1, 'allDocs with key');
return db.allDocs({keys: ['constructor']});
}).then(function (res) {
res.rows.should.have.length(1, 'allDocs with keys');
return db.allDocs();
}).then(function (res) {
res.rows.should.have.length(3, 'allDocs empty opts');
return db.query(function (doc) {
emit(doc._id);
}, {key: 'constructor'});
}).then(function (res) {
res.rows.should.have.length(1, 'query with key');
return db.query(function (doc) {
emit(doc._id);
}, {keys: ['constructor']});
}).then(function (res) {
res.rows.should.have.length(1, 'query with keys');
return new PouchDB.utils.Promise(function (resolve, reject) {
db.replicate.to(remote).on('complete', resolve).on('error', reject);
});
});
});
it('can create db with reserved name', function () {
return new PouchDB('constructor').then(function (db) {
return db.info().then(function () {
return db.destroy();
});
});
});
});
});