2015-04-28 19:52:29 +02:00
|
|
|
nock = require 'nock'
|
|
|
|
expect = require("chai").should()
|
|
|
|
|
|
|
|
Asjon = require '../asjon-testing.coffee'
|
|
|
|
asjon = undefined
|
|
|
|
|
2015-08-28 01:08:36 +02:00
|
|
|
loc_payload =
|
|
|
|
city: "Milano"
|
|
|
|
|
2015-04-28 19:52:29 +02:00
|
|
|
payload =
|
2015-08-28 01:08:36 +02:00
|
|
|
name: loc_payload.city
|
2015-04-28 19:52:29 +02:00
|
|
|
sys:
|
|
|
|
sunrise: 12345
|
|
|
|
sunset: 12345
|
|
|
|
main:
|
|
|
|
humidity: 50
|
|
|
|
temp: 20
|
|
|
|
weather: [ description: 'ok' ]
|
|
|
|
|
|
|
|
describe 'modulo meteo', ->
|
|
|
|
before (done) ->
|
|
|
|
# Inizializzo robot
|
|
|
|
Asjon (assa) ->
|
|
|
|
asjon = assa
|
|
|
|
after asjon.after
|
|
|
|
afterEach asjon.clear
|
|
|
|
beforeEach nock.disableNetConnect
|
|
|
|
require('../scripts/meteo.coffee')(asjon.robot)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'dovrebbe rispondere quando interrogato', (done) ->
|
|
|
|
questions = [
|
|
|
|
"asjon che tempo c'è a crema"
|
|
|
|
"asjon che tempo fa a crema?"
|
2015-08-28 01:08:36 +02:00
|
|
|
"asjon che tempo c'è?"
|
2015-04-28 19:52:29 +02:00
|
|
|
"asjon che tempo fa?"
|
|
|
|
]
|
|
|
|
nock('http://api.openweathermap.org')
|
2015-08-28 01:08:36 +02:00
|
|
|
.get('/data/2.5/weather?lang=it&units=metric&q='+loc_payload.city)
|
2015-04-28 19:52:29 +02:00
|
|
|
.times questions.length
|
|
|
|
.reply 200, payload
|
2015-08-28 01:08:36 +02:00
|
|
|
nock('http://ip-api.com')
|
|
|
|
.get('/json')
|
|
|
|
.times 2
|
|
|
|
.reply 200, loc_payload
|
2015-04-28 19:52:29 +02:00
|
|
|
acc = 0
|
|
|
|
asjon.receive (e,l) ->
|
|
|
|
acc++
|
|
|
|
if acc is questions.length then done()
|
|
|
|
questions.map (q) -> asjon.send q
|
|
|
|
|
|
|
|
it 'dovrebbe reagire correttamente a un errore nel payload', (done) ->
|
|
|
|
nock('http://api.openweathermap.org')
|
2015-08-28 01:08:36 +02:00
|
|
|
.get('/data/2.5/weather?lang=it&units=metric&q='+loc_payload.city)
|
2015-04-28 19:52:29 +02:00
|
|
|
.reply 500, 'very error'
|
|
|
|
asjon.receive (e,l) ->
|
2015-08-28 01:08:36 +02:00
|
|
|
l.join().should.match /^errore nel guardare il cielo/g
|
2015-04-28 19:52:29 +02:00
|
|
|
done()
|
|
|
|
asjon.send 'asjon meteo'
|
|
|
|
|
2015-08-28 01:08:36 +02:00
|
|
|
it 'dovrebbe trovare la posizione correttamente', (done) ->
|
2015-04-28 19:52:29 +02:00
|
|
|
nock('http://api.openweathermap.org')
|
2015-08-28 01:08:36 +02:00
|
|
|
.get('/data/2.5/weather?lang=it&units=metric&q='+loc_payload.city)
|
2015-04-28 19:52:29 +02:00
|
|
|
.reply 200, payload
|
2015-08-28 01:08:36 +02:00
|
|
|
nock('http://ip-api.com')
|
|
|
|
.get('/json/')
|
|
|
|
.times 1
|
|
|
|
.reply 200, loc_payload
|
|
|
|
asjon.receive (e,l) ->
|
|
|
|
l.join().split(' ')[2].should.equal loc_payload.city+":\n"
|
|
|
|
l.join().should.match /^meteo per /g
|
|
|
|
done()
|
2015-04-28 19:52:29 +02:00
|
|
|
asjon.send 'asjon meteo'
|