Skip to content

Instantly share code, notes, and snippets.

@realyze
Last active December 15, 2015 04:50
Show Gist options
  • Save realyze/5204836 to your computer and use it in GitHub Desktop.
Save realyze/5204836 to your computer and use it in GitHub Desktop.
var request = require('supertest'),
should = require('should'),
express = require('express');
var sessionStore = new express.session.MemoryStore();
var app = express()
var secret = 'aaaaaa'
var sessionID;
app.use(express.cookieParser(secret));
app.use(express.session({
key: 'express.sid'
, store: sessionStore
}));
app.post('/v1/sessions', function(req, res){
req.session.authenticated = true;
res.send('ok')
sessionID = req.sessionID;
});
describe('Functional Test <Sessions>:', function () {
it('should create user session for valid user', function (done) {
request(app)
.post('/v1/sessions')
.set('Accept','application/json')
.send({"email": "[email protected]", "password": "123"})
.end(function (err, res) {
sessionID.should.exist;
sessionStore.load(sessionID, function(err, session) {
if (err) {
return done(err);
}
session.authenticated.should.be.true;
done()
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment