-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecates module-level configuration (#13)
This change brings the supertest-session API closer in-line with the `supertest` API it wraps. Dependents adopting the new API should create sessions using the exported factory function: var request = require('supertest-session'); request(myApp, myOpts) .get('/hello') ... The API remains back-compatible for the time being, though legacy usage should be considered deprecated and will be removed in the future.
- Loading branch information
Showing
5 changed files
with
200 additions
and
89 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
var assert = require('assert'), | ||
app = require('./app'), | ||
session = require('../index'); | ||
|
||
describe('legacy configuration', function () { | ||
|
||
describe('supertest session', function () { | ||
|
||
var sess = null; | ||
|
||
var Session = session({ | ||
app: app, | ||
envs: { NODE_ENV: 'development'} | ||
}); | ||
|
||
beforeEach(function (done) { | ||
sess = new Session(); | ||
sess.request('get', '/') | ||
.expect(200) | ||
.expect('GET,,1') | ||
.end(done); | ||
}); | ||
|
||
it('should increment session counter', function (done) { | ||
sess.request('get', '/') | ||
.expect(200) | ||
.expect('GET,,2') | ||
.end(done); | ||
}); | ||
|
||
it('should set enviromental variables', function(done) { | ||
sess.request('get', '/env') | ||
.expect(200) | ||
.end(function(err, res) { | ||
assert.equal(err, undefined); | ||
assert.equal(JSON.parse(res.text).NODE_ENV, 'development'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should destroy session', function (done) { | ||
sess.destroy(); | ||
sess.get('/') | ||
.expect(200) | ||
.expect('GET,,1') | ||
.end(done); | ||
}); | ||
|
||
describe('method sugar', function () { | ||
var methods = { | ||
'del' : 'DELETE', | ||
'get' : 'GET', | ||
'post' : 'POST', | ||
'put' : 'PUT', | ||
'patch' : 'PATCH' | ||
}; | ||
|
||
Object.keys(methods).forEach(function (key) { | ||
it('should support ' + key, function (done) { | ||
sess[key]('/') | ||
.expect(200) | ||
.expect(methods[key] + ',,2') | ||
.end(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Session with a .before hook', function () { | ||
|
||
var sess = null; | ||
|
||
var Session = session({ | ||
app: app, | ||
before: function (req) { | ||
req.set('authorization', 'bearer TEST_SESSION_TOKEN'); | ||
} | ||
}); | ||
|
||
beforeEach(function (done) { | ||
sess = new Session(); | ||
sess.request('get', '/token') | ||
.expect(200) | ||
.expect('GET,token,1') | ||
.end(done); | ||
}); | ||
|
||
it('should increment session counter', function (done) { | ||
sess.request('get', '/token') | ||
.expect(200) | ||
.expect('GET,token,2') | ||
.end(done); | ||
}); | ||
}); | ||
}); |
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