Fix unit tests and remove unused code

This commit is contained in:
Samer Albahra
2018-07-22 19:31:38 -05:00
parent 1fa985e941
commit 616a0bda6f
8 changed files with 1551 additions and 315 deletions

View File

@@ -1,5 +1,4 @@
var http = require( "http" ),
Cache = require( "../models/Cache" ),
SunCalc = require( "suncalc" ),
moment = require( "moment-timezone" ),
geoTZ = require( "geo-tz" ),
@@ -105,14 +104,7 @@ function getOWMWeatherData( location, callback ) {
location = location.join( "," );
getCache( {
key: "yesterdayHumidity",
location: location,
weather: weather,
callback: callback
} );
updateCache( location, weather );
callback( weather );
} );
} );
}
@@ -135,58 +127,6 @@ function getTimeData( location, callback ) {
} );
}
// Retrieve cached record for a given location
// opt is defined as an object with two required items
// opt.location defines the location for the cache record
// opt.key defines the key to return for the location
function getCache( opt, callback ) {
// Find the cache entry for the provided location
Cache.findOne( { location: opt.location }, function( err, record ) {
if ( err ) {
return;
}
// If a record is found for the provided key, return it
if ( record && record[ opt.key ] !== null ) {
opt.weather[ opt.key ] = record[ opt.key ];
}
opt.callback( opt.weather );
} );
}
// Update weather cache record in the local database
function updateCache( location, weather ) {
// Search for a cache record for the provided location
Cache.findOne( { location: location }, function( err, record ) {
if ( err ) {
return;
}
// If a record is found update the data and save it
if ( record ) {
record.currentHumidityTotal += weather.humidity;
record.currentHumidityCount++;
record.save();
} else {
// If no cache record is found, generate a new one and save it
new Cache( {
location: location,
currentHumidityTotal: weather.humidity,
currentHumidityCount: 1
} ).save();
}
} );
}
// Calculates the resulting water scale using the provided weather data, adjustment method and options
function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) {
@@ -394,7 +334,7 @@ exports.getWeather = function( req, res ) {
// Attempt to resolve provided location to GPS coordinates when it does not match
// a GPS coordinate or Weather Underground location using Weather Underground autocomplete
resolveCoordinates( location, function( result, timezone ) {
resolveCoordinates( location, function( result ) {
if ( result === false ) {
res.send( "Error: Unable to resolve location" );
return;