<commit_before>/**
 * Module dependencies
 */

var assert = require('assert');

var $Sails = require('../helpers/sails');
var $Router = require('../helpers/router');





describe('Request hook', function (){

  var sails = $Sails.load({
    globals: false,
    log: {
      level: 'silent'
    },
    loadHooks: [
      'moduleloader',
      'userconfig',
      'request'
    ]
  });

  describe('setting req.options.usage', function () {

    it('should call `req.validate(req.options.usage)` and cause server to send 400 response upon receiving invalid params', function (done) {
      var ROUTEADDRESS = '/req_options_usage';
      sails.router.bind('/*', function (req,res,next) {
        req.options.usage = {
          foo: 'integer'
        };
        next();
      })
      .router.bind(ROUTEADDRESS, function (req, res, next) {
        done(new Error('Should never get here'));
      })
      .emit('router:request', {
        url: ROUTEADDRESS,
        query: {
          foo: 'nasty string'
        }
      }, {
        send: function () {
          console.log('ok');
          done();
        }
      });
    });

    it('should call `req.validate(req.options.usage)` but still work correctly upon receiving valid params', function (done) {
      var ROUTEADDRESS = '/req_options_usage';
      sails.router.bind('/*', function (req,res,next) {
        req.options.usage = {
          foo: 'integer'
        };
        next();
      })
      .emit('router:request', {
        url: ROUTEADDRESS,
        query: {
          foo: 123
        }
      }, {
        send: function () {
          console.log('ok');
          done();
        }
      });
    });

  });



});<commit_msg>Added better coverage of req.options.usage.<commit_after>/**
 * Module dependencies
 */

var assert = require('assert');

var $Sails = require('../helpers/sails');
var $Router = require('../helpers/router');





describe('Request hook', function (){

  var sails = $Sails.load({
    globals: false,
    log: {
      level: 'silent'
    },
    loadHooks: [
      'moduleloader',
      'userconfig',
      'request'
    ]
  });

  describe('setting req.options.usage', function () {

    it('should call `req.validate(req.options.usage)` and cause server to send 400 response upon receiving invalid params', function (done) {
      var ROUTEADDRESS = '/req_options_usage';
      sails.router.bind(ROUTEADDRESS, function (req,res,next) {
        req.options.usage = {
          foo: 'integer'
        };
        next();
      })
      .router.bind(ROUTEADDRESS, function (req, res, next) {
        done(new Error('Should never get here'));
      })
      .emit('router:request', {
        url: ROUTEADDRESS,
        query: {
          foo: 'nasty string'
        }
      }, {
        send: function () {
          done();
        }
      });
    });

    it('should call `req.validate(req.options.usage)` but still work correctly upon receiving valid params', function (done) {
      var ROUTEADDRESS = '/req_options_usage2';
      sails.router.bind(ROUTEADDRESS, function (req,res,next) {
        req.options.usage = {
          foo: 'integer'
        };
        next();
      })
      .router.bind(ROUTEADDRESS, function (req, res, next) {
        res.send(200);
      })
      .emit('router:request', {
        url: ROUTEADDRESS,
        query: {
          foo: 123
        }
      }, {
        send: function () {
          console.log(arguments);
          done();
        }
      });
    });

  });



});
{'fraction_non_alphanumeric': 0.1553398058252427, 'fraction_numerical': 0.004568817818389492, 'mean_word_length': 1.9412258606213266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6195364', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1049, 'n_words': 229}