diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-21 06:29:31 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-21 06:29:31 +0000 |
| commit | ee8e1a13b60a6adfdc691b2a9b57289188397641 (patch) | |
| tree | 096633208d9b8b6b59b67f4034a0cbb41e1f4c5d /node_modules/express-validator/test/helpers/app.js | |
| parent | 689df70a38ace2f88cfef6ab50f10dc546b48f00 (diff) | |
need pull
Diffstat (limited to 'node_modules/express-validator/test/helpers/app.js')
| -rw-r--r-- | node_modules/express-validator/test/helpers/app.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/node_modules/express-validator/test/helpers/app.js b/node_modules/express-validator/test/helpers/app.js new file mode 100644 index 0000000..d86a4bb --- /dev/null +++ b/node_modules/express-validator/test/helpers/app.js @@ -0,0 +1,45 @@ +// Sample app +var express = require('express'); +var expressValidator = require('../../index'); +var bodyParser = require('body-parser'); + +var port = process.env.PORT || 8888; +var app = express(); + +// If no native implementation of Promise exists (less than Node v4), +// use Bluebird promises so we can test for both depending on the Node version +if (typeof Promise === 'undefined') { + Promise = require('bluebird'); +} + +module.exports = function(validation) { + + app.set('port', port); + app.use(bodyParser.json()); + app.use(expressValidator({ + customValidators: { + isArray: function(value) { + return Array.isArray(value); + }, + isAsyncTest: function(testparam) { + return new Promise(function(resolve, reject) { + setTimeout(function() { + if (testparam === '42') { return resolve(); } + reject(); + }, 200); + }); + } + }, + customSanitizers: { + toTestSanitize: function() { + return "!!!!"; + } + } + })); + + app.get(/\/test(\d+)/, validation); + app.get('/:testparam?', validation); + app.post('/:testparam?', validation); + + return app; +}; |
