Adding basic express-validator-tests

This commit is contained in:
Eric Byers
2015-04-16 11:06:23 -05:00
parent ca99daff70
commit 72fece2722
@@ -0,0 +1,35 @@
/// <reference path="./express-validator.d.ts" />
// @todo Most of the sanitize/validator methods are not tested here.
import express = require('express');
import expressValidator = require('express-validator');
var app = express();
// Add the middleware to make sure it includes.
app.use(expressValidator({
errorFormatter: function(param: string, msg: string, value: string): {} {
return {};
}
}));
var router: express.Router = express.Router();
// Add a sample route so we can use the request.
router.get('/test/:testParam', function(req: express.Request, res: express.Response): void {
// Various different request tests.
// The fluid calls are just random, making sure to cover a portion of the Validator.
req.checkParams('testParam', 'Invalid testParam').notEmpty().isInt();
req.checkBody('testBody', 'Invalid testBody').isNumeric();
req.checkFiles('testFiles', 'Invalid testFiles').isUrl();
req.checkQuery('testQuery', 'Invalid testQuery').isDate();
req.checkHeader('testHeader', 'Invalid testHeader').isLowercase().isUppercase();
var test = req.filter('postparam').toBoolean();
var test2 = req.sanitize('postparam').toInt();
var errors = req.validationErrors();
var mappedErrors = req.validationErrors(true);
});