forked from mweibel/connect-session-sequelize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
47 lines (41 loc) · 1.17 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
var assert = require('assert')
, connect = require('connect')
, SequelizeStore = require('./lib/connect-session-sequelize')(connect.session.Store)
, Sequelize = require('sequelize');
var db = new Sequelize('session_test', 'test', '12345', {
dialect: 'sqlite'
, logging: false
})
, store = new SequelizeStore({db: db})
, sessionId = '1234a'
, sessionData = {foo: 'bar', 'baz': 42};
describe('connect-session-middleware', function() {
before(function(done) {
store.sync().success(function() {
done();
}).error(function(err) {
done(err);
})
})
it('should have no length', function() {
store.length(function(_err, c) {
assert.equal(0, c);
});
});
it('should save the session', function() {
store.set(sessionId, sessionData, function(err, session) {
assert.ok(!err, '#set() got an error');
assert.ok(session, '#set() is not ok');
store.length(function(c) {
assert.equals(1, c);
store.get(sessionId, function(err, data) {
assert.ok(!err, '#get() got an error');
assert.deepEqual(sessionData, data);
store.destroy(sessionId, function(err) {
assert.ok(err, '#destroy() got an error');
});
});
});
});
});
});