Skip to content

Commit

Permalink
Added tests for #3738
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Jul 5, 2016
1 parent ba24d81 commit 1a06cb5
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/integration/router.params.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Module dependencies
*/

var util = require('util');
var assert = require('assert');
var httpHelper = require('./helpers/httpHelper.js');
var appHelper = require('./helpers/appHelper');




var Err = {
badResponse: function(response) {
return 'Wrong server response! Response :::\n' + util.inspect(response.body);
}
};




describe('router :: ', function() {
describe('Parameters', function() {
var appName = 'testApp';

before(function(done) {
appHelper.build(done);
});

beforeEach(function(done) {
appHelper.lift({verbose: false}, function(err, sails) {
if (err) {throw new Error(err);}
sailsprocess = sails;
setTimeout(done, 100);
});
});

afterEach(function(done) {
sailsprocess.lower(function(){setTimeout(done, 100);});
});

after(function() {
process.chdir('../');
appHelper.teardown();
});

describe('"length" param', function() {

before(function(){
require('fs').writeFileSync('config/routes.js', 'module.exports.routes = {"/testLength": function(req,res){res.send(req.param("length"));}};');
});

it('when sent as a query param, should respond with the correct value of `length`', function(done) {
httpHelper.testRoute('get', 'testLength?length=long', function(err, response) {
if (err) { return done(err); }
assert(response.body==='long', Err.badResponse(response));
done();
});

});

it('when sent as a body param, should respond with the correct value of `length`', function(done) {
httpHelper.testRoute('post', {url: 'testLength', json: {length: 'short'}}, function(err, response) {
if (err) { return done(err); }
assert(response.body==='short', Err.badResponse(response));
done();
});

});

});

});

});

0 comments on commit 1a06cb5

Please sign in to comment.