From d6ffcdf2e34bbadc5f44502f622c2fed554a12d2 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 19 Mar 2016 16:09:25 +0100 Subject: [PATCH] Update weather tests --- scripts/meteo.coffee | 2 +- test/meteo-test.coffee | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/meteo.coffee b/scripts/meteo.coffee index 4faade8..34e52b3 100644 --- a/scripts/meteo.coffee +++ b/scripts/meteo.coffee @@ -47,7 +47,7 @@ module.exports = (robot) -> callback err, body send_weather = (res) -> (err, body) -> - return res.send "#{err2}:\n #{err}" if err + return res.send "#{err2}:\n#{err}" if err try body = JSON.parse body catch e diff --git a/test/meteo-test.coffee b/test/meteo-test.coffee index 50b5641..3aa646f 100644 --- a/test/meteo-test.coffee +++ b/test/meteo-test.coffee @@ -7,6 +7,8 @@ asjon = undefined loc_payload = city: "Milano" +key = 'totally-legit-key' + payload = name: loc_payload.city sys: @@ -28,7 +30,15 @@ describe 'modulo meteo', -> require('../scripts/meteo.coffee')(asjon.robot) done() + it 'non dovrebbe rispondere se manca l\'API key', (done) -> + process.env.WEATHER_API_KEY = '' + asjon.receive (e,l) -> + l.join().should.equal 'errore nel guardare il cielo:\nnon ho la chiave per openweathermap :(' + done() + asjon.send 'asjon meteo' + it 'dovrebbe rispondere quando interrogato', (done) -> + process.env.WEATHER_API_KEY = key questions = [ "asjon che tempo c'รจ a crema" "asjon che tempo fa a crema?" @@ -36,7 +46,7 @@ describe 'modulo meteo', -> "asjon che tempo fa?" ] nock('http://api.openweathermap.org') - .get('/data/2.5/weather?lang=it&units=metric&q='+loc_payload.city) + .get('/data/2.5/weather?lang=it&units=metric&appid='+key+'&q='+loc_payload.city) .times questions.length .reply 200, payload nock('http://ip-api.com') @@ -50,8 +60,9 @@ describe 'modulo meteo', -> questions.map (q) -> asjon.send q it 'dovrebbe reagire correttamente a un errore nel payload', (done) -> + process.env.WEATHER_API_KEY = key nock('http://api.openweathermap.org') - .get('/data/2.5/weather?lang=it&units=metric&q='+loc_payload.city) + .get('/data/2.5/weather?lang=it&units=metric&appid='+key+'&q='+loc_payload.city) .reply 500, 'very error' asjon.receive (e,l) -> l.join().should.match /^errore nel guardare il cielo/g @@ -59,8 +70,9 @@ describe 'modulo meteo', -> asjon.send 'asjon meteo' it 'dovrebbe trovare la posizione correttamente', (done) -> + process.env.WEATHER_API_KEY = key nock('http://api.openweathermap.org') - .get('/data/2.5/weather?lang=it&units=metric&q='+loc_payload.city) + .get('/data/2.5/weather?lang=it&units=metric&appid='+key+'&q='+loc_payload.city) .reply 200, payload nock('http://ip-api.com') .get('/json/')