build: update example dependencies
[express.git] / test / acceptance / cookies.js
blobaa9e1faef448d099a26736b377e0e34c6e433623
2 var app = require('../../examples/cookies')
3   , request = require('supertest');
4 var utils = require('../support/utils');
6 describe('cookies', function(){
7   describe('GET /', function(){
8     it('should have a form', function(done){
9       request(app)
10       .get('/')
11       .expect(/<form/, done);
12     })
14     it('should respond with no cookies', function(done){
15       request(app)
16       .get('/')
17       .expect(utils.shouldNotHaveHeader('Set-Cookie'))
18       .expect(200, done)
19     })
21     it('should respond to cookie', function(done){
22       request(app)
23       .post('/')
24       .type('urlencoded')
25       .send({ remember: 1 })
26       .expect(302, function(err, res){
27         if (err) return done(err)
28         request(app)
29         .get('/')
30         .set('Cookie', res.headers['set-cookie'][0])
31         .expect(200, /Remembered/, done)
32       })
33     })
34   })
36   describe('GET /forget', function(){
37     it('should clear cookie', function(done){
38       request(app)
39       .post('/')
40       .type('urlencoded')
41       .send({ remember: 1 })
42       .expect(302, function(err, res){
43         if (err) return done(err)
44         request(app)
45         .get('/forget')
46         .set('Cookie', res.headers['set-cookie'][0])
47         .expect('Set-Cookie', /remember=;/)
48         .expect(302, done)
49       })
50     })
51   })
53   describe('POST /', function(){
54     it('should set a cookie', function(done){
55       request(app)
56       .post('/')
57       .type('urlencoded')
58       .send({ remember: 1 })
59       .expect('Set-Cookie', /remember=1/)
60       .expect(302, done)
61     })
63     it('should no set cookie w/o reminder', function(done){
64       request(app)
65       .post('/')
66       .send({})
67       .expect(utils.shouldNotHaveHeader('Set-Cookie'))
68       .expect(302, done)
69     })
70   })