aboutsummaryrefslogtreecommitdiff
path: root/node_modules/express-validator/test/nestedInputSanitizeTest.js
blob: 18b6fcd045fd91bbedf8b111ac36f0dfe49cf7fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var chai = require('chai');
var expect = chai.expect;
var request = require('supertest');

var app;
function validation(req, res) {
  req.sanitize(['user', 'fields', 'email']).trim();
  res.send( req.body );
}

function pass(body) {
  expect(body).to.have.deep.property('user.fields.email', 'test@example.com');
}

function postRoute(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('#nestedInputSanitizers', function() {
  describe('POST tests', function() {

    it('should return property and sanitized value', function(done) {
      postRoute('/', { user: { fields: { email: '     test@example.com       ' } } }, pass, done);
    });

  });
});