Consolidate OWM mocks

This commit is contained in:
Samer Albahra
2019-05-13 21:43:35 -05:00
parent 2928e3e515
commit 4b2198fed7

View File

@@ -12,11 +12,7 @@ const location = '01002';
describe('Watering Data', () => {
it('OpenWeatherMap Lookup (Adjustment Method 0, Location 01002)', async () => {
nock( 'http://api.openweathermap.org' )
.filteringPath( function() { return "/"; } )
.get( "/" )
.reply( 200, replies[location].OWMData );
mockOWM();
const expressMocks = createExpressMocks(0, location);
await getWateringData(expressMocks.request, expressMocks.response);
@@ -24,11 +20,7 @@ describe('Watering Data', () => {
});
it('OpenWeatherMap Lookup (Adjustment Method 1, Location 01002)', async () => {
nock( 'http://api.openweathermap.org' )
.filteringPath( function() { return "/"; } )
.get( "/" )
.reply( 200, replies[location].OWMData );
mockOWM();
const expressMocks = createExpressMocks(1, location);
await getWateringData(expressMocks.request, expressMocks.response);
@@ -57,3 +49,10 @@ function createExpressMocks(method: number, location: string) {
})
}
}
function mockOWM() {
nock( 'http://api.openweathermap.org' )
.filteringPath( function() { return "/"; } )
.get( "/" )
.reply( 200, replies[location].OWMData );
}