Skip to content

Commit

Permalink
added test for GET / with authenticated session.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Sep 23, 2013
1 parent 5c0a72c commit 94b7a47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/lib/app-request.js
Expand Up @@ -4,11 +4,23 @@ var util = require('./util');
var app = util.getApp();

module.exports = function appRequest(options, cb) {
var jar = request.jar();

if (typeof(options) == 'string') options = {url: options};

if (!('followAllRedirects' in options))
options.followAllRedirects = true;

if ('user' in options) {
jar.add(request.cookie(app.sessionCookie.serialize({
user: options.user
})));
delete options.user;
}

options.jar = jar;
app.db = options.db || util.level();
delete options.db;
util.serve(app, function(server) {
options.url = server.baseURL + options.url;
request(options, function(err, res, body) {
Expand Down
13 changes: 13 additions & 0 deletions test/test-app.js
Expand Up @@ -12,6 +12,19 @@ test("GET / w/o session shows login form", function(t) {
});
});

test("GET / w/ session shows notes, logout button", function(t) {
appRequest({
url: '/',
user: 'foo'
}, function(err, res, body) {
t.notOk(err);
t.has(body, /logout foo/i, "logout button is visible");
t.has(body, /update notes/i, "update notes button is visible");
t.has(res.statusCode, 200);
t.end();
});
});

test("GET /blarg returns 404", function(t) {
appRequest('/blarg', function(err, res, body) {
t.notOk(err);
Expand Down

0 comments on commit 94b7a47

Please sign in to comment.