From 4b2198fed724d1f8b3f305c49a2933c69b883636 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 13 May 2019 21:43:35 -0500 Subject: [PATCH] Consolidate OWM mocks --- routes/weather.spec.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/routes/weather.spec.ts b/routes/weather.spec.ts index e18952d..7513466 100644 --- a/routes/weather.spec.ts +++ b/routes/weather.spec.ts @@ -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); @@ -56,4 +48,11 @@ function createExpressMocks(method: number, location: string) { request }) } +} + +function mockOWM() { + nock( 'http://api.openweathermap.org' ) + .filteringPath( function() { return "/"; } ) + .get( "/" ) + .reply( 200, replies[location].OWMData ); } \ No newline at end of file