Change tests for new Typescript change
This commit is contained in:
95
test/api.js
95
test/api.js
@@ -1,95 +0,0 @@
|
||||
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( "Weather Underground Source Test", function( done ) {
|
||||
for ( var test in expected.WU ) {
|
||||
if ( expected.WU.hasOwnProperty( test ) ) {
|
||||
apiTest( {
|
||||
method: 1,
|
||||
loc: test,
|
||||
key: process.env.WU_API_KEY,
|
||||
expected: expected.WU[test],
|
||||
callback: function() {
|
||||
done();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
it( "Information lookup without weather lookup", function( done ) {
|
||||
for ( var test in expected.noWeather ) {
|
||||
if ( expected.noWeather.hasOwnProperty( test ) ) {
|
||||
apiTest( {
|
||||
method: 0,
|
||||
loc: test,
|
||||
expected: expected.noWeather[test],
|
||||
callback: function() {
|
||||
done();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
function apiTest( opt ) {
|
||||
|
||||
opt = extend( {}, {
|
||||
method: 0,
|
||||
key: "",
|
||||
format: "json"
|
||||
}, opt );
|
||||
|
||||
var 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;
|
||||
}
|
||||
expect( body ).to.eql( opt.expected );
|
||||
opt.callback( body );
|
||||
} );
|
||||
}
|
||||
|
||||
function setupMocks( location ) {
|
||||
nock.cleanAll();
|
||||
|
||||
nock( "http://autocomplete.wunderground.com" )
|
||||
.filteringPath( function() { return "/"; } )
|
||||
.get( "/" )
|
||||
.reply( 200, replies[location].WUautoComplete );
|
||||
|
||||
nock( "http://api.wunderground.com" )
|
||||
.filteringPath( function() { return "/"; } )
|
||||
.get( "/" )
|
||||
.reply( 200, replies[location].WUyesterday );
|
||||
|
||||
nock( "http://api.openweathermap.org" )
|
||||
.filteringPath( function() { return "/"; } )
|
||||
.get( "/" )
|
||||
.reply( 200, replies[location].OWMData );
|
||||
}
|
||||
|
||||
function extend( target ) {
|
||||
var sources = [].slice.call( arguments, 1 );
|
||||
sources.forEach( function( source ) {
|
||||
for ( var prop in source ) {
|
||||
target[prop] = source[prop];
|
||||
}
|
||||
} );
|
||||
return target;
|
||||
}
|
||||
@@ -1,22 +1,18 @@
|
||||
{
|
||||
"WU": {
|
||||
"01002": {
|
||||
"scale": 0,
|
||||
"rd": -1,
|
||||
"tz": 28,
|
||||
"sunrise": 387,
|
||||
"sunset": 1060,
|
||||
"eip": null
|
||||
}
|
||||
},
|
||||
"noWeather": {
|
||||
"01002": {
|
||||
"scale": -1,
|
||||
"rd": -1,
|
||||
"tz": 28,
|
||||
"sunrise": 387,
|
||||
"sunset": 1060,
|
||||
"eip": null
|
||||
"tz": 32,
|
||||
"sunrise": 332,
|
||||
"sunset": 1203,
|
||||
"eip": 2130706433,
|
||||
"rawData": {
|
||||
"h": 98.5,
|
||||
"p": 1.09,
|
||||
"t": 70.8,
|
||||
"raining": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1806
test/replies.json
1806
test/replies.json
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user