Skip to content

Commit

Permalink
Getting integration tests to pass again
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed May 12, 2014
1 parent 678e1c0 commit a5a7018
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/router/req.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module.exports = function buildRequest (_req) {

function FakeSession() {
// TODO: mimic the session store impl in sockets hook
// (all of this can drastically simplify the request interpreter)
// (all of this can drastically simplify that hook and consolidate
// request interpreter logic)
}

req = _.defaults(req, {
Expand Down
8 changes: 7 additions & 1 deletion lib/router/res.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Module dependencies
*/
var util = require('util');
var _ = require('lodash');
var MockRes = require('mock-res');

Expand Down Expand Up @@ -42,7 +43,12 @@ module.exports = function buildResponse (req, _res) {
res.statusCode = args.statusCode || res.statusCode || 200;

if (args.other) {
res.write(args.other);
var toWrite = args.other;
if (typeof toWrite === 'object') {
toWrite = util.inspect(toWrite);
}
console.log('writing:',toWrite, '(a '+typeof toWrite+')');
res.write(toWrite);
}
res.end();
}
Expand Down
2 changes: 2 additions & 0 deletions test/hooks/request/initialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Request hook', function (){
var ROUTEADDRESS = '/req_params_all';
sails.router.bind(ROUTEADDRESS, function (req, res) {
assert(typeof req.params.all === 'function', 'req.params.all() should be defined when request hook is enabled.');
res.send(200);
done();
})
.emit('router:request', {url: ROUTEADDRESS});
Expand All @@ -34,6 +35,7 @@ describe('Request hook', function (){
var ROUTEADDRESS = '/req_validate';
sails.router.bind(ROUTEADDRESS, function (req, res, next) {
assert(typeof req.validate === 'function', 'req.validate() should be defined when request hook is enabled.');
res.send(200);
done();
})
.emit('router:request', { url: ROUTEADDRESS });
Expand Down
7 changes: 5 additions & 2 deletions test/hooks/request/req.validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ describe('Request hook', function (){
it('should not throw when required params are specified in req.query', function (done) {
var ROUTEADDRESS = '/req_validate0';
sails.router.bind(ROUTEADDRESS, function (req, res, next) {
assert.doesNotThrow(function () {
try {
req.validate({
foo: 'string'
});
});
}
catch(e) {
return done(e);
}
done();
})
.emit('router:request', {
Expand Down

0 comments on commit a5a7018

Please sign in to comment.