Update weather tests
This commit is contained in:
parent
fcd2186319
commit
d6ffcdf2e3
@ -47,7 +47,7 @@ module.exports = (robot) ->
|
|||||||
callback err, body
|
callback err, body
|
||||||
|
|
||||||
send_weather = (res) -> (err, body) ->
|
send_weather = (res) -> (err, body) ->
|
||||||
return res.send "#{err2}:\n #{err}" if err
|
return res.send "#{err2}:\n#{err}" if err
|
||||||
try
|
try
|
||||||
body = JSON.parse body
|
body = JSON.parse body
|
||||||
catch e
|
catch e
|
||||||
|
@ -7,6 +7,8 @@ asjon = undefined
|
|||||||
loc_payload =
|
loc_payload =
|
||||||
city: "Milano"
|
city: "Milano"
|
||||||
|
|
||||||
|
key = 'totally-legit-key'
|
||||||
|
|
||||||
payload =
|
payload =
|
||||||
name: loc_payload.city
|
name: loc_payload.city
|
||||||
sys:
|
sys:
|
||||||
@ -28,7 +30,15 @@ describe 'modulo meteo', ->
|
|||||||
require('../scripts/meteo.coffee')(asjon.robot)
|
require('../scripts/meteo.coffee')(asjon.robot)
|
||||||
done()
|
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) ->
|
it 'dovrebbe rispondere quando interrogato', (done) ->
|
||||||
|
process.env.WEATHER_API_KEY = key
|
||||||
questions = [
|
questions = [
|
||||||
"asjon che tempo c'è a crema"
|
"asjon che tempo c'è a crema"
|
||||||
"asjon che tempo fa a crema?"
|
"asjon che tempo fa a crema?"
|
||||||
@ -36,7 +46,7 @@ describe 'modulo meteo', ->
|
|||||||
"asjon che tempo fa?"
|
"asjon che tempo fa?"
|
||||||
]
|
]
|
||||||
nock('http://api.openweathermap.org')
|
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
|
.times questions.length
|
||||||
.reply 200, payload
|
.reply 200, payload
|
||||||
nock('http://ip-api.com')
|
nock('http://ip-api.com')
|
||||||
@ -50,8 +60,9 @@ describe 'modulo meteo', ->
|
|||||||
questions.map (q) -> asjon.send q
|
questions.map (q) -> asjon.send q
|
||||||
|
|
||||||
it 'dovrebbe reagire correttamente a un errore nel payload', (done) ->
|
it 'dovrebbe reagire correttamente a un errore nel payload', (done) ->
|
||||||
|
process.env.WEATHER_API_KEY = key
|
||||||
nock('http://api.openweathermap.org')
|
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'
|
.reply 500, 'very error'
|
||||||
asjon.receive (e,l) ->
|
asjon.receive (e,l) ->
|
||||||
l.join().should.match /^errore nel guardare il cielo/g
|
l.join().should.match /^errore nel guardare il cielo/g
|
||||||
@ -59,8 +70,9 @@ describe 'modulo meteo', ->
|
|||||||
asjon.send 'asjon meteo'
|
asjon.send 'asjon meteo'
|
||||||
|
|
||||||
it 'dovrebbe trovare la posizione correttamente', (done) ->
|
it 'dovrebbe trovare la posizione correttamente', (done) ->
|
||||||
|
process.env.WEATHER_API_KEY = key
|
||||||
nock('http://api.openweathermap.org')
|
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
|
.reply 200, payload
|
||||||
nock('http://ip-api.com')
|
nock('http://ip-api.com')
|
||||||
.get('/json/')
|
.get('/json/')
|
||||||
|
Loading…
Reference in New Issue
Block a user