-
-
Save calidion/7d407eb182ab786fdfae540e88263c65 to your computer and use it in GitHub Desktop.
Login session test with mocha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('supertest'), | |
should = require('should'), | |
app = require('../server'); | |
var Cookies; | |
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"}) | |
.expect('Content-Type', /json/) | |
.expect(200) | |
.end(function (err, res) { | |
res.body.id.should.equal('1'); | |
res.body.short_name.should.equal('Test user'); | |
res.body.email.should.equal('[email protected]'); | |
// Save the cookie to use it later to retrieve the session | |
Cookies = res.headers['set-cookie'].pop().split(';')[0]; | |
done(); | |
}); | |
}); | |
it('should get user session for current user', function (done) { | |
var req = request(app).get('/v1/sessions'); | |
// Set cookie to get saved user session | |
req.cookies = Cookies; | |
req.set('Accept','application/json') | |
.expect('Content-Type', /json/) | |
.expect(200) | |
.end(function (err, res) { | |
res.body.id.should.equal('1'); | |
res.body.short_name.should.equal('Test user'); | |
res.body.email.should.equal('[email protected]'); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment