Skip to content

Commit

Permalink
Merge pull request #13 from yahoo/bugfix
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
Vijar committed Aug 27, 2014
2 parents 73644a9 + dd3e5a9 commit 294edcf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
5 changes: 5 additions & 0 deletions libs/fetcher.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ module.exports = function createFetcherClient (options) {
* @private
*/
_sync: function (resource, operation, params, body, config, callback) {
if (typeof config === 'function') {
callback = config;
config = {};
}

config = config || {};
config.xhr = Fetcher.pathPrefix;

Expand Down
14 changes: 11 additions & 3 deletions libs/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = function createFetcherClass (options) {
var defaultPath = Fetcher.pathPrefix + '/resource/',
path = req.path.substr(defaultPath.length).split(';');
request = {
req: req,
resource: path.shift(),
operation: OP_READ,
params: qs.parse(path.join('&')),
Expand All @@ -102,7 +103,7 @@ module.exports = function createFetcherClass (options) {
var requests = req.body.requests;

if (!requests || requests.length === 0) {
res.send(204);
res.status(204).end();
}

var DEFAULT_GUID = 'g0',
Expand All @@ -116,7 +117,7 @@ module.exports = function createFetcherClass (options) {
config: singleRequest.config,
callback: function(err, data) {
if(err) {
res.send('400', 'request failed');
res.status(400).send('request failed');
}
var responseObj = {};
responseObj[DEFAULT_GUID] = {data: data};
Expand Down Expand Up @@ -161,7 +162,14 @@ module.exports = function createFetcherClass (options) {
body = request.body,
config = request.config,
callback = request.callback,
args = [req, resource, params, config, callback];
args;

if (typeof config === 'function') {
callback = config;
config = {};
}

args = [req, resource, params, config, callback];

if ((op === OP_CREATE) || (op === OP_UPDATE)) {
args.splice(3, 0, body);
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/libs/fetcher.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,34 @@ describe('Client Fetcher', function () {
var operation = 'create';
fetcher[operation](resource, params, body, config, callback(operation, done));
});
it('should handle CREATE w/ no config', function (done) {
var operation = 'create';
fetcher[operation](resource, params, body, callback(operation, done));
});
it('should handle READ', function (done) {
var operation = 'read';
fetcher[operation](resource, params, config, done);
});
it('should handle READ w/ no config', function (done) {
var operation = 'read';
fetcher[operation](resource, params, done);
});
it('should handle UPDATE', function (done) {
var operation = 'update';
fetcher[operation](resource, params, body, config, callback(operation, done));
});
it('should handle UPDATE w/ no config', function (done) {
var operation = 'update';
fetcher[operation](resource, params, body, callback(operation, done));
});
it('should handle DELETE', function (done) {
var operation = 'del';
fetcher[operation](resource, params, config, callback('delete', done));
});
it('should handle DELETE w/ no config', function (done) {
var operation = 'del';
fetcher[operation](resource, params, callback('delete', done));
});
});

});
20 changes: 16 additions & 4 deletions tests/unit/libs/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ var expect = chai.expect,
qs = require('querystring');

describe('Server Fetcher', function () {
// var Fetcher = fetchr(),
// fetcher = new Fetcher();

it('should register fetchers', function () {
var fn = Fetcher.getFetcher.bind(fetcher, mockFetcher.name);
Expand All @@ -40,8 +38,11 @@ describe('Server Fetcher', function () {
json: function () {
console.log('Not Expected: middleware responded with json');
},
send: function (code) {
status: function (code) {
console.log('Not Expected: middleware responded with', code);
},
send: function () {
console.log('Not Expected: middleware responded with');
}
},
next = function () {
Expand Down Expand Up @@ -133,19 +134,30 @@ describe('Server Fetcher', function () {
body = {},
config = {};


it('should handle CREATE', function (done) {
fetcher.create(resource, params, body, config, done);
});
it('should handle CREATE w/ no config', function (done) {
fetcher.create(resource, params, body, done);
});
it('should handle READ', function (done) {
fetcher.read(resource, params, config, done);
});
it('should handle READ w/ no config', function (done) {
fetcher.read(resource, params, done);
});
it('should handle UPDATE', function (done) {
fetcher.update(resource, params, body, config, done);
});
it('should handle UPDATE w/ no config', function (done) {
fetcher.update(resource, params, body, done);
});
it('should handle DELETE', function (done) {
fetcher.del(resource, params, config, done);
});
it('should handle DELETE w/ no config', function (done) {
fetcher.del(resource, params, done);
});
});

});

0 comments on commit 294edcf

Please sign in to comment.