diff --git a/test/api.js b/test/api.js index 8ac2d94..278ee2a 100644 --- a/test/api.js +++ b/test/api.js @@ -1,16 +1,35 @@ -var hippie = require( "hippie" ), - nock = require( "nock" ), - replies = require( "./replies" ), - server = require( "../server" ).app; +var hippie = require( "hippie" ), + nock = require( "nock" ), + expect = require( "chai" ).expect, + replies = require( "./replies" ), + expected = require( "./expected" ), + server = require( "../server" ).app; + +describe( "Weather API", function() { + describe( "/:method endpoint", function() { + it( "The Weather Channel Source Test", function( done ) { + for ( var test in expected ) { + if ( expected.hasOwnProperty( test ) ) { + apiTest( { + method: 1, + loc: test, + expected: expected[test], + callback: function( reply ) { + done(); + } + } ); + } + } + } ); + } ); +} ); function apiTest( opt ) { var opt = extend( {}, { method: 0, - loc: "", key: "", - format: "json", - callback: function() {} + format: "json" }, opt ), url = "/" + opt.method + "?loc=" + opt.loc + "&key=" + opt.key + "&format=" + opt.format; @@ -24,11 +43,14 @@ function apiTest( opt ) { if ( err ) { throw err; } + expect( body ).to.eql( opt.expected ); opt.callback( body ); } ); } function setupMocks( location ) { + nock.cleanAll(); + nock( "http://autocomplete.wunderground.com" ) .filteringPath( function( path ) { return "/"; @@ -51,20 +73,6 @@ function setupMocks( location ) { .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 ) { diff --git a/test/expected.json b/test/expected.json new file mode 100644 index 0000000..23656b9 --- /dev/null +++ b/test/expected.json @@ -0,0 +1,10 @@ +{ + "01002": { + "scale": 83, + "restrict": 0, + "tz": 32, + "sunrise": 324, + "sunset": 1226, + "eip": 2130706433 + } +}