Skip to content

Commit

Permalink
upgrade mocha and start modularizing lodash to make sure tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterGit committed Jul 22, 2018
1 parent e4a90f6 commit f60c1bf
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 379 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _ = require('lodash');
var _get = require('lodash/get');
var express = require('express');
var compression = require('compression');
var bodyParser = require('body-parser');
Expand Down Expand Up @@ -29,7 +29,7 @@ function create(env, ctx) {
}

if (env.settings.isEnabled('cors')) {
var allowOrigin = _.get(env, 'extendedSettings.cors.allowOrigin') || '*';
var allowOrigin = _get(env, 'extendedSettings.cors.allowOrigin') || '*';
console.info('Enabled CORS, allow-origin:', allowOrigin);
app.use(function allowCrossDomain(req, res, next) {
res.header('Access-Control-Allow-Origin', allowOrigin);
Expand Down
17 changes: 11 additions & 6 deletions env.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';

var _ = require('lodash');
var _each = require('lodash/each');
var _trim = require('lodash/trim');
var _forIn = require('lodash/forIn');
var _startsWith = require('lodash/startsWith');
var _camelCase = require('lodash/camelCase');

var fs = require('fs');
var crypto = require('crypto');
var consts = require('./lib/constants');
Expand Down Expand Up @@ -168,16 +173,16 @@ function findExtendedSettings (envs) {
return key.toUpperCase().replace('CUSTOMCONNSTR_', '');
}

_.each(env.settings.enable, function eachEnable(enable) {
if (_.trim(enable)) {
_.forIn(envs, function eachEnvPair (value, key) {
_each(env.settings.enable, function eachEnable(enable) {
if (_trim(enable)) {
_forIn(envs, function eachEnvPair (value, key) {
var env = normalizeEnv(key);
if (_.startsWith(env, enable.toUpperCase() + '_')) {
if (_startsWith(env, enable.toUpperCase() + '_')) {
var split = env.indexOf('_');
if (split > -1 && split <= env.length) {
var exts = extended[enable] || {};
extended[enable] = exts;
var ext = _.camelCase(env.substring(split + 1).toLowerCase());
var ext = _camelCase(env.substring(split + 1).toLowerCase());
if (!isNaN(value)) { value = Number(value); }
if (typeof value === 'string' && (value.toLowerCase() === 'on' || value.toLowerCase() === 'true')) { value = true; }
if (typeof value === 'string' && (value.toLowerCase() === 'off' || value.toLowerCase() === 'false')) { value = false; }
Expand Down
31 changes: 18 additions & 13 deletions lib/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';

var _ = require('lodash');
var _find = require('lodash/find');
var _each = require('lodash/each');
var _filter = require('lodash/filter');
var _get = require('lodash/get');
var _isArray = require('lodash/isArray');
var _map = require('lodash/map');

function init (ctx) {

Expand All @@ -9,7 +14,7 @@ function init (ctx) {

function plugins(name) {
if (name) {
return _.find(allPlugins, {name: name});
return _find(allPlugins, {name: name});
} else {
return plugins;
}
Expand Down Expand Up @@ -78,19 +83,19 @@ function init (ctx) {
};

plugins.register = function register(all) {
_.each(all, function eachPlugin(plugin) {
_each(all, function eachPlugin(plugin) {
allPlugins.push(plugin);
});

enabledPlugins = [];

var enable = _.get(ctx, 'settings.enable');
var enable = _get(ctx, 'settings.enable');
function isEnabled(plugin) {
//TODO: unify client/server env/app
return enable && enable.indexOf(plugin.name) > -1;
}

_.each(allPlugins, function eachPlugin(plugin) {
_each(allPlugins, function eachPlugin(plugin) {
plugin.enabled = isEnabled(plugin);
if (plugin.enabled) {
enabledPlugins.push(plugin);
Expand All @@ -100,28 +105,28 @@ function init (ctx) {
};

plugins.eachPlugin = function eachPlugin(f) {
_.each(allPlugins, f);
_each(allPlugins, f);
};

plugins.eachEnabledPlugin = function eachEnabledPlugin(f) {
_.each(enabledPlugins, f);
_each(enabledPlugins, f);
};

//these plugins are either always on or have custom settings
plugins.specialPlugins = 'ar2 bgnow delta direction timeago upbat rawbg errorcodes profile';

plugins.shownPlugins = function(sbx) {
return _.filter(enabledPlugins, function filterPlugins(plugin) {
return _filter(enabledPlugins, function filterPlugins(plugin) {
return plugins.specialPlugins.indexOf(plugin.name) > -1 || (sbx && sbx.showPlugins && sbx.showPlugins.indexOf(plugin.name) > -1);
});
};

plugins.eachShownPlugins = function eachShownPlugins(sbx, f) {
_.each(plugins.shownPlugins(sbx), f);
_each(plugins.shownPlugins(sbx), f);
};

plugins.hasShownType = function hasShownType(pluginType, sbx) {
return _.find(plugins.shownPlugins(sbx), function findWithType(plugin) {
return _find(plugins.shownPlugins(sbx), function findWithType(plugin) {
return plugin.pluginType === pluginType;
}) !== undefined;
};
Expand Down Expand Up @@ -155,7 +160,7 @@ function init (ctx) {
plugins.eachEnabledPlugin(function eachPlugin(plugin) {
if (plugin.getEventTypes) {
var eventTypes = plugin.getEventTypes(sbx.withExtendedSettings(plugin));
if (_.isArray(eventTypes)) {
if (_isArray(eventTypes)) {
all = all.concat(eventTypes);
}
}
Expand All @@ -165,14 +170,14 @@ function init (ctx) {
};

plugins.enabledPluginNames = function enabledPluginNames() {
return _.map(enabledPlugins, function mapped(plugin) {
return _map(enabledPlugins, function mapped(plugin) {
return plugin.name;
}).join(' ');
};

plugins.extendedClientSettings = function extendedClientSettings (allExtendedSettings) {
var clientSettings = {};
_.each(clientDefaultPlugins, function eachClientPlugin (plugin) {
_each(clientDefaultPlugins, function eachClientPlugin (plugin) {
clientSettings[plugin.name] = allExtendedSettings[plugin.name];
});

Expand Down
7 changes: 4 additions & 3 deletions lib/plugins/pluginbase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var _ = require('lodash');
var _map = require('lodash/map');
var _each = require('lodash/each');

var TOOLTIP_WIDTH = 275; //min-width + padding

Expand Down Expand Up @@ -78,7 +79,7 @@ function init (majorPills, minorPills, statusPills, bgStatus, tooltip) {
}

if (options.info && options.info.length) {
var html = _.map(options.info, function mapInfo (i) {
var html = _map(options.info, function mapInfo (i) {
return '<strong>' + i.label + '</strong> ' + i.value;
}).join('<br/>\n');

Expand All @@ -103,7 +104,7 @@ function init (majorPills, minorPills, statusPills, bgStatus, tooltip) {
};

pluginBase.addForecastPoints = function addForecastPoints (points, info) {
_.each(points, function eachPoint (point) {
_each(points, function eachPoint (point) {
point.type = 'forecast';
point.info = info;
if (point.mgdl < 13) {
Expand Down
Loading

0 comments on commit f60c1bf

Please sign in to comment.