Update weather tests
This commit is contained in:
parent
fcd2186319
commit
d6ffcdf2e3
@ -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
|
||||
|
@ -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/')
|
||||
|
Loading…
Reference in New Issue
Block a user