[transport] before failing to send a request, ensure the return value is defined
This commit is contained in:
@ -32,12 +32,7 @@ module.exports = function (grunt) {
|
|||||||
grunt.task.run(tasks);
|
grunt.task.run(tasks);
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask('unit_test', [
|
grunt.registerTask('unit_test', 'mochacov:unit');
|
||||||
'jshint',
|
|
||||||
'run:generate',
|
|
||||||
'mochacov:unit',
|
|
||||||
]);
|
|
||||||
|
|
||||||
grunt.registerTask('coverage', [
|
grunt.registerTask('coverage', [
|
||||||
'mochacov:make_coverage_html',
|
'mochacov:make_coverage_html',
|
||||||
'open:coverage'
|
'open:coverage'
|
||||||
@ -84,4 +79,4 @@ module.exports = function (grunt) {
|
|||||||
})
|
})
|
||||||
.nodeify(this.async());
|
.nodeify(this.async());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -131,9 +131,20 @@ Transport.prototype.request = function (params, cb) {
|
|||||||
|
|
||||||
self.log.debug('starting request', params);
|
self.log.debug('starting request', params);
|
||||||
|
|
||||||
|
// determine the response based on the presense of a callback
|
||||||
|
if (typeof cb === 'function') {
|
||||||
|
ret = {
|
||||||
|
abort: abortRequest
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
defer = this.defer();
|
||||||
|
ret = defer.promise;
|
||||||
|
ret.abort = abortRequest;
|
||||||
|
}
|
||||||
|
|
||||||
if (params.body && params.method === 'GET') {
|
if (params.body && params.method === 'GET') {
|
||||||
_.nextTick(respond, new TypeError('Body can not be sent with method "GET"'));
|
_.nextTick(respond, new TypeError('Body can not be sent with method "GET"'));
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialize the body
|
// serialize the body
|
||||||
@ -287,18 +298,6 @@ Transport.prototype.request = function (params, cb) {
|
|||||||
}, requestTimeout);
|
}, requestTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine the response based on the presense of a callback
|
|
||||||
if (typeof cb === 'function') {
|
|
||||||
ret = {
|
|
||||||
abort: abortRequest
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
defer = this.defer();
|
|
||||||
ret = defer.promise;
|
|
||||||
ret.abort = abortRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (connection) {
|
if (connection) {
|
||||||
sendReqWithConnection(void 0, connection);
|
sendReqWithConnection(void 0, connection);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -360,7 +360,8 @@ describe('Transport Class', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('rejects get requests with bodies', function (done) {
|
|
||||||
|
it('rejects GET requests with a body (callback)', function (done) {
|
||||||
var trans = new Transport();
|
var trans = new Transport();
|
||||||
stub(trans.log, 'debug');
|
stub(trans.log, 'debug');
|
||||||
stub(trans.connectionPool, 'select', function (cb) {
|
stub(trans.connectionPool, 'select', function (cb) {
|
||||||
@ -377,6 +378,26 @@ describe('Transport Class', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rejects GET requests with a body (promise)', function (done) {
|
||||||
|
var trans = new Transport();
|
||||||
|
stub(trans.log, 'debug');
|
||||||
|
stub(trans.connectionPool, 'select', function (cb) {
|
||||||
|
// simulate "no connections"
|
||||||
|
process.nextTick(cb);
|
||||||
|
});
|
||||||
|
trans.request({
|
||||||
|
body: 'JSON!!',
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
done(new Error('expected the request to fail!'));
|
||||||
|
}, function (err) {
|
||||||
|
expect(err).to.be.a(TypeError);
|
||||||
|
expect(err.message).to.match(/body.*method.*get/i);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('gets a body', function () {
|
describe('gets a body', function () {
|
||||||
it('serializes it', function (done) {
|
it('serializes it', function (done) {
|
||||||
var trans = new Transport({
|
var trans = new Transport({
|
||||||
|
|||||||
Reference in New Issue
Block a user