-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
75 lines (65 loc) · 1.64 KB
/
test.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
/**
* Module dependencies.
*/
var assert = require('assert'),
connect = require('connect'),
MongoStore = require('./lib')(connect),
MongoClient = require('mongodb').MongoClient;
var testsCount = 3;
var done = (function () {
var count = 0;
return function () {
++count;
if (count == testsCount) {
console.log('done');
process.exit(0);
}
};
})();
var store = new MongoStore;
// simple test
store.on('connect', function() {
baseTest.apply(this);
});
// test with initialized db object
MongoClient.connect('mongodb://127.0.0.1:27017/testdb', function(err, db) {
var store = new MongoStore({db: db});
store.on('connect', function() {
baseTest.apply(this);
});
});
// test mongodb auth
MongoClient.connect('mongodb://127.0.0.1:27017/testauth', function(err, db) {
db.removeUser('user', function() {
db.addUser('user', 'pass', {roles: ['readWrite']}, function(err, res) {
assert.ok(!err, '#addUser error');
var store = new MongoStore({user: 'user', password: 'pass', db: 'testauth'});
store.on('connect', function() {
baseTest.apply(this);
});
});
});
});
// Basic functionality test
function baseTest() {
var self = this;
// #set()
self.set('123', {cookie: {maxAge: 2000}, name: 'name'}, function(err, ok) {
assert.ok(!err, '#set() got an error');
assert.ok(ok, '#set() is not ok');
// #get()
self.get('123', function(err, data) {
assert.ok(!err, '#get() got an error');
assert.deepEqual({
cookie: {maxAge: 2000},
name: 'name'
}, data);
// #set null
self.set('123', {cookie: {maxAge: 2000}, name: 'name'}, function() {
self.destroy('123', function() {
done();
});
});
});
});
}