diff options
| author | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-04-16 13:17:06 +0000 |
|---|---|---|
| committer | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-04-16 13:17:06 +0000 |
| commit | dc46b87abee1e441c07524ddde67fd902a919336 (patch) | |
| tree | 13eba08b8655dfd78e9600ec5f612011a0bf3b35 /node_modules/express-validator/test/nestedInputTest.js | |
| parent | 26f4b38e9e5a202756a7c33abc775aea2617aeaf (diff) | |
added some dependencies to package.json
Diffstat (limited to 'node_modules/express-validator/test/nestedInputTest.js')
| -rw-r--r-- | node_modules/express-validator/test/nestedInputTest.js | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/node_modules/express-validator/test/nestedInputTest.js b/node_modules/express-validator/test/nestedInputTest.js deleted file mode 100644 index bf08854..0000000 --- a/node_modules/express-validator/test/nestedInputTest.js +++ /dev/null @@ -1,61 +0,0 @@ -var chai = require('chai'); -var expect = chai.expect; -var request = require('supertest'); - -var app; - -function validation(req, res) { - req.assert(['user', 'fields', 'email'], 'not empty').notEmpty(); - req.assert('user.fields.email', 'not empty').notEmpty(); - req.assert(['user', 'fields', 'email'], 'valid email required').isEmail(); - req.assert(['admins', '0', 'name'], 'must only contain letters').isAlpha(); - - var errors = req.validationErrors(); - if (errors) { - return res.send(errors); - } - res.send(req.body); -} - -function fail(body) { - expect(body[0]).to.have.property('msg', 'not empty'); - expect(body[1]).to.have.property('msg', 'not empty'); - expect(body[2]).to.have.property('msg', 'valid email required'); - - // Should convert ['user', 'fields', 'email'] to 'user.fields.email' - // when formatting the error output - expect(body[0]).to.have.property('param').and.to.be.a('string'); - expect(body[1]).to.have.property('param').and.to.be.a('string'); - expect(body[2]).to.have.property('param').and.to.be.a('string'); -} - -function pass(body) { - expect(body).to.have.deep.property('user.fields.email', 'test@example.com'); -} - -function testRoute(path, data, test, done) { - request(app) - .post(path) - .send(data) - .end(function(err, res) { - test(res.body); - done(); - }); -} - -// This before() is required in each set of tests in -// order to use a new validation function in each file -before(function() { - delete require.cache[require.resolve('./helpers/app')]; - app = require('./helpers/app')(validation); -}); - -describe('nested input as array or dot notation', function() { - it('should return a success when the correct data is passed on the body', function(done) { - testRoute('/', { user: { fields: { email: 'test@example.com' } }, admins: [{ name: 'Bobby' }] }, pass, done); - }); - - it('should return an error object with each failing param as a property data is invalid', function(done) { - testRoute('/', { user: { fields: { email: '' } }, admins: [{ name: 0 }] }, fail, done); - }); -});
\ No newline at end of file |
