Improve categories for tests

This commit is contained in:
Samer Albahra
2019-05-13 21:38:45 -05:00
parent ed33d61db7
commit 9275abde27

View File

@@ -10,30 +10,29 @@ const replies = require( '../test/replies.json' );
const location = '01002'; const location = '01002';
describe('/:method endpoint', () => { describe('Watering Data', () => {
beforeEach(() => { it('OpenWeatherMap Lookup (Adjustment Method 0, Location 01002)', async () => {
nock( 'http://api.openweathermap.org' ) nock( 'http://api.openweathermap.org' )
.filteringPath( function() { return "/"; } ) .filteringPath( function() { return "/"; } )
.get( "/" ) .get( "/" )
.reply( 200, replies[location].OWMData ); .reply( 200, replies[location].OWMData );
});
it('Information lookup without weather lookup', async () => {
const expressMocks = createExpressMocks(location); const expressMocks = createExpressMocks(0, location);
await getWateringData(expressMocks.request, expressMocks.response); await getWateringData(expressMocks.request, expressMocks.response);
expect( expressMocks.response._getJSON() ).to.eql( expected.noWeather[location] ); expect( expressMocks.response._getJSON() ).to.eql( expected.noWeather[location] );
}); });
}); });
function createExpressMocks(location: string) { function createExpressMocks(method: number, location: string) {
const request = new MockExpressRequest({ const request = new MockExpressRequest({
method: 'GET', method: 'GET',
url: '/0?loc=' + location, url: `/${method}?loc=${location}`,
query: { query: {
loc: location, loc: location,
format: 'json' format: 'json'
}, },
params: [ 0 ], params: [ method ],
headers: { headers: {
'x-forwarded-for': '127.0.0.1' 'x-forwarded-for': '127.0.0.1'
} }