Code coverage report for lib/config.js

Statements: 100% (17 / 17)      Branches: 100% (8 / 8)      Functions: 100% (3 / 3)      Lines: 100% (14 / 14)     

All files » lib/ » config.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341   1             1 35 63   19 19   14 14 14   63       1 23     1          
var _ = require('lodash');
 
var httpConfig = {
  timeout: undefined,
  retries: 3,
  retryDelay: 15,
  baseUrl: undefined
};
 
function _configureHttp(httpConfig, opts) {
  _(_.keys(httpConfig)).intersection(_.keys(opts)).each(function(key) {
    switch(key) {
      case 'timeout':
        if(opts[key] === 'default') { opts[key] = undefined; }
      break;
      case 'retries':
        if(opts[key] === 'always') { opts[key] = 0; }
        if(opts[key] === 'never') { opts[key] = -1; }
      break;
    }
    httpConfig[key] = opts[key];
  }, this);
}
 
function configureHttp(opts) {
  _configureHttp(httpConfig, opts);
}
 
module.exports = {
  httpConfig: httpConfig,
  _configureHttp: _configureHttp,
  configureHttp: configureHttp
};