forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test for cookie-sessions example
- Loading branch information
1 parent
279c8bb
commit 389ab1b
Showing
1 changed file
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
var app = require('../../examples/cookie-sessions') | ||
var request = require('supertest') | ||
|
||
function getCookie(res) { | ||
return res.headers['set-cookie'][0].split(';')[0] | ||
} | ||
|
||
describe('cookie-sessions', function () { | ||
describe('GET /', function () { | ||
it('should display no views', function (done) { | ||
request(app) | ||
.get('/') | ||
.expect(200, 'viewed 0 times\n', done) | ||
}) | ||
|
||
it('should set a session cookie', function (done) { | ||
request(app) | ||
.get('/') | ||
.expect('Set-Cookie', /connect\.sess=/) | ||
.expect(200, done) | ||
}) | ||
|
||
it('should display 1 view on revisit', function (done) { | ||
request(app) | ||
.get('/') | ||
.expect(200, 'viewed 0 times\n', function (err, res) { | ||
if (err) return done(err) | ||
request(app) | ||
.get('/') | ||
.set('Cookie', getCookie(res)) | ||
.expect(200, 'viewed 1 times\n', done) | ||
}) | ||
}) | ||
}) | ||
}) |