Skip to content
Myr

moved more tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 7374027 · Browse files · 2 files+64 added−64 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+64 added−64 removed

  • tests:+64 added−64 removed

2 files+64 added−64 removed

modified:test/express.test.js-64 removed
433 unmodified lines
434 assert.response(app,435 { url: '/' },436 { body: 'restored' }437 );438 },439 440 'test route middleware': function(beforeExit){441 var app = express.createServer()442 , calls = 0;443444 function allow(role) {445 return function(req, res, next) {446 // this is totally not real, dont use this :)447 // for tests only448 if (req.headers['x-role'] == role) {449 next();450 } else {451 res.send(401);452 }453 }454 }455 456 function restrictAge(age) {457 return function(req, res, next){458 if (req.headers['x-age'] >= age) {459 next();460 } else {461 res.send(403);462 }463 }464 }465466 app.param('user', function(req, res, next, user){467 ++calls;468 next();469 });470471 app.get('/xxx', allow('member'), restrictAge(18), function(req, res){472 res.send(200);473 });474475 app.get('/booze', [allow('member')], restrictAge(18), function(req, res){476 res.send(200);477 });478479 app.get('/tobi', [allow('member')], [[restrictAge(18)]], function(req, res){480 res.send(200);481 });482 483 app.get('/user/:user', [allow('member')], [[restrictAge(18)]], function(req, res){484 res.send(200);485 });486487 ['xxx', 'booze', 'tobi', 'user/tj'].forEach(function(thing){488 assert.response(app,489 { url: '/' + thing },490 { body: 'Unauthorized', status: 401 });491 assert.response(app,492 { url: '/' + thing, headers: { 'X-Role': 'member' }},493 { body: 'Forbidden', status: 403 });494 assert.response(app,495 { url: '/' + thing, headers: { 'X-Role': 'member', 'X-Age': 18 }},496 { body: 'OK', status: 200 });497 });498499 beforeExit(function(){500 calls.should.equal(3);501 });438 }439};
modified:test/router.test.js+64 added