forked from deployd/deployd
/
db-remote.unit.js
61 lines (54 loc) · 1.67 KB
/
db-remote.unit.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
var fs = require('fs')
, db = require('../lib/db')
, configContents = fs.readFileSync('db-remote.config.json','utf8')
, config = JSON.parse(configContents)
, tester = db.create(config)
, store = tester.createStore('test-store')
, Store = require('../lib/db').Store
, assert = require('assert')
;
if (config.host == 'foo.com') {
console.warn('Before you run db-remote.unit.js tests, set up the configuration in "db-remote.config.json".')
return;
}
beforeEach(function(done){
store.remove(function () {
store.find(function (err, result) {
assert.equal(err, null);
assert.equal(result.length, 0);
done(err);
});
});
});
describe('db', function(){
describe('.create(options)', function(){
it('should connect to a remote database', function(done) {
store.find(function (err, empty) {
assert.equal(empty.length, 0)
done(err);
});
});
});
});
describe('store', function(){
describe('.find(query, fn)', function(){
it('should not find anything when the store is empty', function(done) {
store.find(function (err, empty) {
assert.equal(empty.length, 0);
done(err);
});
});
it('should pass the query to the underlying database', function(done) {
store.insert([{i:1},{i:2},{i:3}], function () {
store.find({i: {$lt: 3}}, function (err, result) {
assert.equal(result.length, 2);
result.forEach(function (obj) {
assert.equal(typeof obj.id, 'string')
});
done(err);
});
});
});
// TODO: convert the rest of the tests
});
});