Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajiv Tirumalareddy committed Jun 17, 2015
1 parent 9ff5701 commit 0fbbdef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion libs/fetcher.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function parseResponse(response) {
* @param {Function} callback The function to be used to process a given item in the queue.
* @param {Object} callback.item The obj that was popped from the queue.
*/
/* istanbul ignore next */
function Queue(id, config, sweepFn, callback) {
this.id = id;
this.config = config || {};
Expand All @@ -80,7 +81,7 @@ function Queue(id, config, sweepFn, callback) {
* @property config
* @type Object
*/

/* istanbul ignore next */
Queue.prototype = {
/**
* Once an item is pushed to the queue,
Expand Down Expand Up @@ -259,6 +260,7 @@ Queue.prototype = {
}

// push request to queue so that it can be batched
/* istanbul ignore next */
if (!this._q) {
this._q = new Queue(this.name, {
wait: Fetcher.batchWindow
Expand All @@ -275,6 +277,7 @@ Queue.prototype = {
}
});
}
/* istanbul ignore next */
this._q.push(request);
},
// ------------------------------------------------------------------
Expand Down
9 changes: 3 additions & 6 deletions libs/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ function parseParamValues (params) {
* @param {Function} fetcher
*/
Fetcher.registerFetcher = function (fetcher) {
var name = fetcher.name || null;
//Store fetcher by name
if (!(fetcher && name)) {
if (!fetcher || !fetcher.name) {
throw new Error('Fetcher is not defined correctly');
}

Fetcher.fetchers[name] = fetcher;
debug('fetcher ' + name + ' added');
Fetcher.fetchers[fetcher.name] = fetcher;
debug('fetcher ' + fetcher.name + ' added');
return;
};

Expand Down
13 changes: 12 additions & 1 deletion tests/unit/libs/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var expect = chai.expect,

describe('Server Fetcher', function () {

it('should register fetchers', function () {
it('should register valid fetchers', function () {
var getFetcher = Fetcher.getFetcher.bind(fetcher);
expect(getFetcher).to.throw(Error, 'Fetcher "undefined" could not be found');
getFetcher = Fetcher.getFetcher.bind(fetcher, mockService.name);
Expand All @@ -30,6 +30,17 @@ describe('Server Fetcher', function () {
expect(getFetcher()).to.deep.equal(mockService);
Fetcher.registerFetcher(mockErrorService);
expect(Object.keys(Fetcher.fetchers)).to.have.length(2);

// valid vs invalid
var invalidFetcher = {not_name: 'test_name'};
var validFetcher = {name: 'test_name'};
var registerInvalidFetcher = Fetcher.registerFetcher.bind(fetcher, undefined);
expect(registerInvalidFetcher).to.throw(Error, 'Fetcher is not defined correctly');
registerInvalidFetcher = Fetcher.registerFetcher.bind(fetcher, invalidFetcher);
expect(registerInvalidFetcher).to.throw(Error, 'Fetcher is not defined correctly');
var registerValidFetcher = Fetcher.registerFetcher.bind(fetcher, validFetcher);
expect(registerValidFetcher).to.not.throw;
delete Fetcher.fetchers[validFetcher.name];
});

it('should get fetchers by resource and sub resource', function () {
Expand Down

0 comments on commit 0fbbdef

Please sign in to comment.