add a test of .setDuration() - clean up whitespace in tests

This commit is contained in:
Lloyd Hilaiel 2012-03-13 12:40:14 -06:00
Родитель 2f1b87a1e0
Коммит f0a6fd6efc
1 изменённых файлов: 74 добавлений и 20 удалений

Просмотреть файл

@ -34,7 +34,7 @@ suite.addBatch({
self.callback(null, req);
res.send("hello");
});
var browser = tobi.createBrowser(app);
browser.get("/foo", function(res, $) {});
},
@ -44,7 +44,7 @@ suite.addBatch({
"session object stores and retrieves values properly": function(err, req) {
req.session.foo = 'bar';
assert.equal(req.session.foo, 'bar');
},
},
"session object has reset function": function(err, req) {
assert.isFunction(req.session.reset);
},
@ -65,10 +65,10 @@ suite.addBatch({
req.session.bar = 'foobar2';
req.session.reset(['foo']);
assert.isUndefined(req.session.bar);
assert.equal(req.session.foo, 'foobar');
}
}
}
});
@ -97,7 +97,7 @@ suite.addBatch({
assert.equal(res.headers['set-cookie'].length, 1);
},
"with an expires attribute": function(err, res) {
assert.match(res.headers['set-cookie'][0], /expires/);
assert.match(res.headers['set-cookie'][0], /expires/);
},
"with a path attribute": function(err, res) {
assert.match(res.headers['set-cookie'][0], /path/);
@ -168,7 +168,7 @@ suite.addBatch({
self.callback(null, req);
res.send("baz");
});
var browser = tobi.createBrowser(app);
browser.get("/foo", function(res, $) {
browser.get("/bar", function(res, $) {
@ -230,7 +230,7 @@ suite.addBatch({
app.get("/bar", function(req, res) {
req.session.reset();
req.session.reset();
req.session.reset();
req.session.bar = 'bar';
req.session.baz = 'baz';
res.send("bar");
@ -261,13 +261,13 @@ function create_app_with_duration() {
secret: 'yo',
duration: 500 // 0.5 seconds
}));
app.get("/foo", function(req, res) {
req.session.reset();
req.session.foo = 'foobar';
res.send("foo");
});
return app;
}
@ -281,7 +281,7 @@ suite.addBatch({
self.callback(null, req);
res.send("bar");
});
var browser = tobi.createBrowser(app);
browser.get("/foo", function(res, $) {
setTimeout(function () {
@ -306,7 +306,7 @@ suite.addBatch({
self.callback(null, req);
res.send("bar");
});
var browser = tobi.createBrowser(app);
var firstCreatedAt, secondCreatedAt;
browser.get("/foo", function(res, $) {
@ -330,7 +330,7 @@ suite.addBatch({
self.callback(null, req);
res.send("bar");
});
var browser = tobi.createBrowser(app);
browser.get("/foo", function(res, $) {
setTimeout(function () {
@ -355,12 +355,12 @@ suite.addBatch({
req.session.baz = Math.random();
res.send("bar");
});
app.get("/bar2", function(req, res) {
self.callback(null, req);
res.send("bar2");
});
var browser = tobi.createBrowser(app);
// first query resets the session to full duration
browser.get("/foo", function(res, $) {
@ -382,6 +382,60 @@ suite.addBatch({
}
});
function create_app_with_duration_modification() {
// simple app
var app = express.createServer();
app.use(cookieSessions({
cookieName: 'session',
secret: 'yobaby',
duration: 5000 // 5.0 seconds
}));
app.get("/create", function(req, res) {
req.session.foo = "foo";
res.send("created");
});
// invoking this will change the session duration to 500ms
app.get("/change", function(req, res) {
req.session.setDuration(500);
res.send("duration changed");
});
return app;
}
suite.addBatch({
"after changing cookie duration and querying outside the modified duration": {
topic: function() {
var self = this;
var app = create_app_with_duration_modification();
app.get("/complete", function(req, res) {
self.callback(null, req);
res.send("bar");
});
var browser = tobi.createBrowser(app);
browser.get("/create", function(res, $) {
browser.get("/change", function(res, $) {
setTimeout(function () {
browser.get("/complete", function(res, $) {
});
}, 800);
});
});
},
"session no longer has state": function(err, req) {
console.log(req.session);
assert.isUndefined(req.session.foo);
}
}
});
function create_app_with_secure(firstMiddleware) {
// set up the session middleware
var middleware = cookieSessions({
@ -392,13 +446,13 @@ function create_app_with_secure(firstMiddleware) {
secure: true
}
});
var app = express.createServer();
if (firstMiddleware)
app.use(firstMiddleware);
app.use(middleware);
return app;
}
@ -408,11 +462,11 @@ suite.addBatch({
var self = this;
var app = create_app_with_secure();
app.get("/foo", function(req, res) {
res.send("foo");
});
var browser = tobi.createBrowser(app);
browser.get("/foo", function(res, $) {
self.callback(null, res);
@ -439,7 +493,7 @@ suite.addBatch({
app.get("/foo", function(req, res) {
res.send("foo");
});
var browser = tobi.createBrowser(app);
browser.get("/foo", function(res, $) {
self.callback(null, res);