Skip to content

Commit

Permalink
Add testcase for expire option
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsl committed Dec 2, 2016
1 parent c22b9a3 commit b7dc0b4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,31 @@ describe('BlueGate session', function() {
});
});

it('will use expire date from options', function() {
var app = new BlueGate({
log: false
});
var url = 'http://localhost:3001';
// app.error(function() { console.log(this.error); });
require('./bluegate-session.js')(app, {
cookieExpires: 3600
});
app.process('GET /', function(session) {
session.set('foo', 'bar');
});
return app.listen(3001).then(function() {
return Needle.getAsync(url);
}).then(function(response) {
var pattern = /Expires\=([^;]+);/;
expect(response[0].headers).to.have.property('set-cookie');
var value = response[0].headers['set-cookie'][0];
expect(value).to.match(pattern);
var expires = new Date(value.match(pattern)[1]);
var expiresIn = (expires - new Date()) / 1e3;
expect(expiresIn > 3595 && expiresIn < 3605).to.equal(true);
}).then(function() {
return app.close();
});
});

});

0 comments on commit b7dc0b4

Please sign in to comment.