Change tests for new Typescript change
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import * as express from "express";
|
||||
import { CronJob } from "cron";
|
||||
|
||||
import * as server from "../server";
|
||||
|
||||
const count = { temp: 0, humidity: 0 };
|
||||
|
||||
let today: PWSStatus = {},
|
||||
@@ -45,7 +43,7 @@ export const captureWUStream = function( req: express.Request, res: express.Resp
|
||||
};
|
||||
|
||||
export const useLocalWeather = function(): boolean {
|
||||
return server.pws !== "none" ? true : false;
|
||||
return process.env.PWS ? true : false;
|
||||
};
|
||||
|
||||
export const getLocalWeather = function(): LocalWeather {
|
||||
|
||||
48
routes/weather.spec.ts
Normal file
48
routes/weather.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { expect } from 'chai';
|
||||
import * as nock from 'nock';
|
||||
import * as MockExpressRequest from 'mock-express-request';
|
||||
import * as MockExpressResponse from 'mock-express-response';
|
||||
|
||||
import { getWateringData } from './weather';
|
||||
|
||||
const expected = require( '../test/expected.json' );
|
||||
const replies = require( '../test/replies.json' );
|
||||
|
||||
const location = '01002';
|
||||
|
||||
describe('/:method endpoint', () => {
|
||||
beforeEach(() => {
|
||||
nock( 'http://api.openweathermap.org' )
|
||||
.filteringPath( function() { return "/"; } )
|
||||
.get( "/" )
|
||||
.reply( 200, replies[location].OWMData );
|
||||
});
|
||||
|
||||
it('Information lookup without weather lookup', async () => {
|
||||
const expressMocks = createExpressMocks(location);
|
||||
await getWateringData(expressMocks.request, expressMocks.response);
|
||||
expect( expressMocks.response._getJSON() ).to.eql( expected.noWeather[location] );
|
||||
});
|
||||
});
|
||||
|
||||
function createExpressMocks(location: string) {
|
||||
const request = new MockExpressRequest({
|
||||
method: 'GET',
|
||||
url: '/0?loc=' + location,
|
||||
query: {
|
||||
loc: location,
|
||||
format: 'json'
|
||||
},
|
||||
params: [ 0 ],
|
||||
headers: {
|
||||
'x-forwarded-for': '127.0.0.1'
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
request,
|
||||
response: new MockExpressResponse({
|
||||
request
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user