Add expected data reply to compare
This commit is contained in:
42
test/api.js
42
test/api.js
@@ -1,16 +1,35 @@
|
|||||||
var hippie = require( "hippie" ),
|
var hippie = require( "hippie" ),
|
||||||
nock = require( "nock" ),
|
nock = require( "nock" ),
|
||||||
|
expect = require( "chai" ).expect,
|
||||||
replies = require( "./replies" ),
|
replies = require( "./replies" ),
|
||||||
|
expected = require( "./expected" ),
|
||||||
server = require( "../server" ).app;
|
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 ) {
|
function apiTest( opt ) {
|
||||||
|
|
||||||
var opt = extend( {}, {
|
var opt = extend( {}, {
|
||||||
method: 0,
|
method: 0,
|
||||||
loc: "",
|
|
||||||
key: "",
|
key: "",
|
||||||
format: "json",
|
format: "json"
|
||||||
callback: function() {}
|
|
||||||
}, opt ),
|
}, opt ),
|
||||||
url = "/" + opt.method + "?loc=" + opt.loc + "&key=" + opt.key + "&format=" + opt.format;
|
url = "/" + opt.method + "?loc=" + opt.loc + "&key=" + opt.key + "&format=" + opt.format;
|
||||||
|
|
||||||
@@ -24,11 +43,14 @@ function apiTest( opt ) {
|
|||||||
if ( err ) {
|
if ( err ) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
expect( body ).to.eql( opt.expected );
|
||||||
opt.callback( body );
|
opt.callback( body );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupMocks( location ) {
|
function setupMocks( location ) {
|
||||||
|
nock.cleanAll();
|
||||||
|
|
||||||
nock( "http://autocomplete.wunderground.com" )
|
nock( "http://autocomplete.wunderground.com" )
|
||||||
.filteringPath( function( path ) {
|
.filteringPath( function( path ) {
|
||||||
return "/";
|
return "/";
|
||||||
@@ -51,20 +73,6 @@ function setupMocks( location ) {
|
|||||||
.reply( 200, replies[location].WSIcurrent );
|
.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 ) {
|
function extend( target ) {
|
||||||
var sources = [].slice.call( arguments, 1 );
|
var sources = [].slice.call( arguments, 1 );
|
||||||
sources.forEach( function( source ) {
|
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