Add expected data reply to compare
This commit is contained in:
50
test/api.js
50
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 ) {
|
||||
|
||||
10
test/expected.json
Normal file
10
test/expected.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"01002": {
|
||||
"scale": 83,
|
||||
"restrict": 0,
|
||||
"tz": 32,
|
||||
"sunrise": 324,
|
||||
"sunset": 1226,
|
||||
"eip": 2130706433
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user