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
Provenance
- Commit
a4cfde3- Tree
7f475ce- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
7374027
2 files changed+64 added−64 removed
modified:test/express.test.js-64 removed
433 unmodified lines434 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;443-444- 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- }465-466- app.param('user', function(req, res, next, user){467- ++calls;468- next();469- });470-471- app.get('/xxx', allow('member'), restrictAge(18), function(req, res){472- res.send(200);473- });474-475- app.get('/booze', [allow('member')], restrictAge(18), function(req, res){476- res.send(200);477- });478-479- 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- });486-487- ['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- });498-499- beforeExit(function(){500- calls.should.equal(3);501- });438 }439 };modified:test/router.test.js+64 added
8 unmodified lines91011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980134 unmodified linesExpand all8 unmodified lines , should = require('should') , Route = express.Route;
module.exports = { 'test route middleware': function(beforeExit){ var app = express.createServer() , calls = 0;
function allow(role) { return function(req, res, next) { // this is totally not real, dont use this :) // for tests only if (req.headers['x-role'] == role) { next(); } else { res.send(401); } } } function restrictAge(age) { return function(req, res, next){ if (req.headers['x-age'] >= age) { next(); } else { res.send(403); } } }
app.param('user', function(req, res, next, user){ ++calls; next(); });
app.get('/xxx', allow('member'), restrictAge(18), function(req, res){ res.send(200); });
app.get('/booze', [allow('member')], restrictAge(18), function(req, res){ res.send(200); });
app.get('/tobi', [allow('member')], [[restrictAge(18)]], function(req, res){ res.send(200); }); app.get('/user/:user', [allow('member')], [[restrictAge(18)]], function(req, res){ res.send(200); });
['xxx', 'booze', 'tobi', 'user/tj'].forEach(function(thing){ assert.response(app, { url: '/' + thing }, { body: 'Unauthorized', status: 401 }); assert.response(app, { url: '/' + thing, headers: { 'X-Role': 'member' }}, { body: 'Forbidden', status: 403 }); assert.response(app, { url: '/' + thing, headers: { 'X-Role': 'member', 'X-Age': 18 }}, { body: 'OK', status: 200 }); });
beforeExit(function(){ calls.should.equal(3); }); },
'test named capture groups': function(){ var app = express.createServer();
app.get('/user/:id([0-9]{2,10})', function(req, res){134 unmodified linesExpand all