Added first working version of unit tests

This commit is contained in:
Samer Albahra
2015-07-12 09:41:45 -05:00
parent 5190a65b77
commit 9cacab7deb
5 changed files with 1946 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
bundler_args: --retry 3 bundler_args: --retry 3
language: node_js language: node_js
services:
- mongodb
before_install: before_install:
- export TZ=America/Chicago - export TZ=America/Chicago
- npm install -g grunt-cli - npm install -g grunt-cli

View File

@@ -3,6 +3,9 @@
"description": "OpenSprinkler Weather Service", "description": "OpenSprinkler Weather Service",
"version": "0.0.1", "version": "0.0.1",
"repository": "https://github.com/OpenSprinkler/Weather-Adjustments/", "repository": "https://github.com/OpenSprinkler/Weather-Adjustments/",
"scripts": {
"test": "mocha test"
},
"dependencies": { "dependencies": {
"cron": "^1.0.9", "cron": "^1.0.9",
"dotenv": "^1.2.0", "dotenv": "^1.2.0",
@@ -14,7 +17,11 @@
"xml2js": "^0.4.9" "xml2js": "^0.4.9"
}, },
"devDependencies": { "devDependencies": {
"chai": "^3.0.0",
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.2" "grunt-contrib-jshint": "^0.11.2",
"hippie": "^0.3.0",
"mocha": "^2.2.5",
"nock": "^2.7.0"
} }
} }

View File

@@ -61,3 +61,5 @@ new CronJob( "0 0 0 * * *", function() {
} ); } );
} ); } );
}, null, true, "UTC" ); }, null, true, "UTC" );
exports.app = app;

76
test/api.js Normal file
View File

@@ -0,0 +1,76 @@
var hippie = require( "hippie" ),
nock = require( "nock" ),
replies = require( "./replies" ),
server = require( "../server" ).app;
function apiTest( opt ) {
var opt = extend( {}, {
method: 0,
loc: "",
key: "",
format: "json",
callback: function() {}
}, opt ),
url = "/" + opt.method + "?loc=" + opt.loc + "&key=" + opt.key + "&format=" + opt.format;
setupMocks( opt.loc );
hippie( server )
.json()
.get( url )
.expectStatus( 200 )
.end( function( err, res, body ) {
if ( err ) {
throw err;
}
opt.callback( body );
} );
}
function setupMocks( location ) {
nock( "http://autocomplete.wunderground.com" )
.filteringPath( function( path ) {
return "/";
} )
.get( "/" )
.reply( 200, replies[location].WUautoComplete );
nock( "http://api.wunderground.com" )
.filteringPath( function( path ) {
return "/";
} )
.get( "/" )
.reply( 200, replies[location].WUyesterday );
nock( "http://api.weather.com" )
.filteringPath( function( path ) {
return "/";
} )
.get( "/" )
.reply( 200, replies[location].WSIcurrent );
}
describe( "Weather API", function() {
describe( "/:method endpoint", function() {
it( "The Weather Channel Source Test", function( done ) {
apiTest( {
method: 1,
loc: "01002",
callback: function( reply ) {
done();
}
} );
} );
} );
} );
function extend( target ) {
var sources = [].slice.call( arguments, 1 );
sources.forEach( function( source ) {
for ( var prop in source ) {
target[prop] = source[prop];
}
} );
return target;
}

1858
test/replies.json Normal file

File diff suppressed because it is too large Load Diff