Change tests for new Typescript change

This commit is contained in:
Samer Albahra
2019-05-13 20:54:03 -05:00
parent e94f8bf8ff
commit caf381ab73
9 changed files with 198 additions and 6040 deletions

View File

@@ -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
View 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
})
}
}