nuovi test, sistemato circolari.html
This commit is contained in:
parent
657d4909e2
commit
ff03f693b1
@ -32,6 +32,7 @@ module.exports = (robot) ->
|
||||
res.send 'controllo issues...'
|
||||
github.issues.repoIssues msg, (err,data) ->
|
||||
if err then return res.send err
|
||||
if data.length is 0 then return res.send '0 issues'
|
||||
r = data.map (i) ->
|
||||
labels = i.labels.map((x) -> x.name).join ', '
|
||||
if labels is '' then labels = 'nessuno'
|
||||
|
@ -14,17 +14,19 @@
|
||||
# Enrico Fasoli (fazo96)
|
||||
#
|
||||
|
||||
Wolfram = require 'wolfram'
|
||||
|
||||
module.exports = (robot) ->
|
||||
if not process.env.WOLFRAM_API_KEY?
|
||||
console.log 'NO WOLFRAM_API_KEY SET!'
|
||||
return # no api key, no wolfy
|
||||
wolfram = require('wolfram').createClient process.env.WOLFRAM_API_KEY
|
||||
robot.respond /(?:quanto fa|compute|wfa|wolfram) (.+)/i, (res) ->
|
||||
res.send 'contattando Wolfram Alpha...'
|
||||
unless process.env.WOLFRAM_API_KEY
|
||||
return res.send 'non ho le chiavi per Wolfram Alpha :('
|
||||
wolfram = Wolfram.createClient process.env.WOLFRAM_API_KEY
|
||||
res.send 'Contattando Wolfram Alpha...'
|
||||
wolfram.query res.match[1], (err, result) ->
|
||||
if err then return res.send err
|
||||
unless result?.slice?
|
||||
return res.send 'invalid response from Wolfram Alpha'
|
||||
parseSubPod = (subpod) -> subpod.value or subpod.image
|
||||
parsePod = (pod) ->
|
||||
'\n=== ' + pod.title + '\n' + pod.subpods.map(parseSubPod).join('\n')
|
||||
res.send (parsePod(pod) for pod in result).join('')
|
||||
res.send (parsePod(pod) for pod in result).join('').trim()
|
||||
|
4440
test/circolari.html
4440
test/circolari.html
File diff suppressed because it is too large
Load Diff
89
test/github-test.coffee
Normal file
89
test/github-test.coffee
Normal file
@ -0,0 +1,89 @@
|
||||
nock = require 'nock'
|
||||
expect = require("chai").should()
|
||||
|
||||
Asjon = require '../asjon-testing.coffee'
|
||||
asjon = undefined
|
||||
|
||||
describe 'modulo github', ->
|
||||
before (done) ->
|
||||
# Inizializzo robot
|
||||
Asjon (assa) ->
|
||||
asjon = assa
|
||||
after asjon.after
|
||||
afterEach asjon.clear
|
||||
require('../scripts/github.coffee')(asjon.robot)
|
||||
done()
|
||||
|
||||
it 'dovrebbe rispondere a "mostra le issues"', (done) ->
|
||||
questions = [
|
||||
"asjon mostrami le issue"
|
||||
"asjon mostrami le issues"
|
||||
"asjon issues"
|
||||
"asjon le issue"
|
||||
"asjon issue"
|
||||
]
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/fazo96/asjon/issues?state=open&sort=updated')
|
||||
.times(questions.length)
|
||||
.reply 200, []
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
acc++
|
||||
if acc is questions.length*2 then done()
|
||||
questions.map (q) -> asjon.send q
|
||||
|
||||
it 'dovrebbe rispondere correttamente in caso di 0 issues', (done) ->
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/fazo96/asjon/issues?state=open&sort=updated')
|
||||
.reply 200, []
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
if acc is 0
|
||||
l.join().should.equal 'controllo issues...'
|
||||
else
|
||||
l.join().should.equal '0 issues'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
asjon.send 'asjon issues'
|
||||
|
||||
|
||||
issue1 =
|
||||
number: 1
|
||||
labels: []
|
||||
title: 'one'
|
||||
user:
|
||||
login: 'user'
|
||||
issue2 =
|
||||
number: 2,
|
||||
labels: [{name: 'a'},{name: 'b'}],
|
||||
title: 'two',
|
||||
user:
|
||||
login: 'user'
|
||||
|
||||
it 'dovrebbe rispondere correttamente in caso di 1 o più issues', (done) ->
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/fazo96/asjon/issues?state=open&sort=updated')
|
||||
.reply 200, [issue1, issue2]
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
if acc is 0
|
||||
l.join().should.equal 'controllo issues...'
|
||||
else
|
||||
a = l.join().split '\n'
|
||||
a[0].should.equal '#1 | one | By: user | Tags: nessuno'
|
||||
a[1].should.equal '#2 | two | By: user | Tags: a, b'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
asjon.send 'asjon issues'
|
||||
|
||||
it 'dovrebbe linkare correttamente le issues ', (done) ->
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
if acc is 0
|
||||
l.join().should.equal 'http://github.com/fazo96/asjon/issues/5'
|
||||
else
|
||||
l.join().should.equal 'http://github.com/fazo96/asjon/issues/456'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
asjon.send 'asjon linkami la issue numero 5'
|
||||
asjon.send 'asjon linkami issue 456'
|
72
test/wolfram-test.coffee
Normal file
72
test/wolfram-test.coffee
Normal file
@ -0,0 +1,72 @@
|
||||
nock = require 'nock'
|
||||
expect = require("chai").should()
|
||||
|
||||
Asjon = require '../asjon-testing.coffee'
|
||||
asjon = undefined
|
||||
|
||||
describe 'modulo github', ->
|
||||
before (done) ->
|
||||
# Inizializzo robot
|
||||
Asjon (assa) ->
|
||||
asjon = assa
|
||||
after asjon.after
|
||||
afterEach asjon.clear
|
||||
require('../scripts/wolfram.coffee')(asjon.robot)
|
||||
done()
|
||||
|
||||
it 'non dovrebbe rispondere se manca l\'API key', (done) ->
|
||||
asjon.receive (e,l) ->
|
||||
l.join().should.equal 'non ho le chiavi per Wolfram Alpha :('
|
||||
done()
|
||||
asjon.send 'asjon wfa test'
|
||||
|
||||
it 'dovrebbe reagire correttamente in caso di risposta malformata', (done) ->
|
||||
process.env.WOLFRAM_API_KEY = 'totally-legit-key'
|
||||
nock('http://api.wolframalpha.com')
|
||||
.get('/v2/query?input=test&primary=true&appid=totally-legit-key')
|
||||
.reply 400, 'no eenterwebz for u'
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
if acc is 0
|
||||
l.join().should.equal 'Contattando Wolfram Alpha...'
|
||||
else
|
||||
l.join().should.equal 'invalid response from Wolfram Alpha'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
asjon.send 'asjon wfa test'
|
||||
|
||||
it 'dovrebbe parsare correttamente la risposta', (done) ->
|
||||
process.env.WOLFRAM_API_KEY = 'totally-legit-key'
|
||||
nock('http://api.wolframalpha.com')
|
||||
.get('/v2/query?input=test&primary=true&appid=totally-legit-key')
|
||||
.replyWithFile 200, __dirname+'/wolfram.xml'
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
if acc is 0
|
||||
l.join().should.equal 'Contattando Wolfram Alpha...'
|
||||
else
|
||||
list = l.join().split '\n'
|
||||
list[0].should.equal '=== Input interpretation'
|
||||
list[1].should.match /^Answer to the/g
|
||||
list[2].should.equal '=== Result'
|
||||
list[3].should.equal '42'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
asjon.send 'asjon wfa test'
|
||||
it.skip 'dovrebbe rispondere a "mostra le issues"', (done) ->
|
||||
questions = [
|
||||
"asjon mostrami le issue"
|
||||
"asjon mostrami le issues"
|
||||
"asjon issues"
|
||||
"asjon le issue"
|
||||
"asjon issue"
|
||||
]
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/fazo96/asjon/issues?state=open&sort=updated')
|
||||
.times(questions.length)
|
||||
.reply 200, []
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
acc++
|
||||
if acc is questions.length*2 then done()
|
||||
questions.map (q) -> asjon.send q
|
81
test/wolfram.xml
Normal file
81
test/wolfram.xml
Normal file
@ -0,0 +1,81 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<queryresult success='true'
|
||||
error='false'
|
||||
numpods='2'
|
||||
datatypes=''
|
||||
timedout=''
|
||||
timedoutpods=''
|
||||
timing='0.698'
|
||||
parsetiming='0.336'
|
||||
parsetimedout='false'
|
||||
recalculate=''
|
||||
id='MSPa8471b0d2f5b7idegd7d000064dihf0gb1eafa3f'
|
||||
host='http://www4b.wolframalpha.com'
|
||||
server='60'
|
||||
related='http://www4b.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa8481b0d2f5b7idegd7d000029525ag6h9cegd4d&s=60'
|
||||
version='2.6'>
|
||||
<pod title='Input interpretation'
|
||||
scanner='Identity'
|
||||
id='Input'
|
||||
position='100'
|
||||
error='false'
|
||||
numsubpods='1'>
|
||||
<subpod title=''>
|
||||
<plaintext>Answer to the Ultimate Question of Life, the Universe, and Everything</plaintext>
|
||||
<img src='http://www4b.wolframalpha.com/Calculate/MSP/MSP8491b0d2f5b7idegd7d000022iage1b3dcfg035?MSPStoreType=image/gif&s=60'
|
||||
alt='Answer to the Ultimate Question of Life, the Universe, and Everything'
|
||||
title='Answer to the Ultimate Question of Life, the Universe, and Everything'
|
||||
width='455'
|
||||
height='18' />
|
||||
</subpod>
|
||||
</pod>
|
||||
<pod title='Result'
|
||||
scanner='Data'
|
||||
id='Result'
|
||||
position='200'
|
||||
error='false'
|
||||
numsubpods='1'
|
||||
primary='true'>
|
||||
<subpod title=''>
|
||||
<plaintext>42
|
||||
(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)</plaintext>
|
||||
<img src='http://www4b.wolframalpha.com/Calculate/MSP/MSP8501b0d2f5b7idegd7d00005h78918b68fh521g?MSPStoreType=image/gif&s=60'
|
||||
alt='42
|
||||
(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)'
|
||||
title='42
|
||||
(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)'
|
||||
width='486'
|
||||
height='47' />
|
||||
</subpod>
|
||||
</pod>
|
||||
<assumptions count='2'>
|
||||
<assumption type='MultiClash'
|
||||
word=''
|
||||
template='Assuming ${word1} is referring to ${desc1}. Use as ${desc2} instead. Use "${word3}" as ${desc3}.'
|
||||
count='3'>
|
||||
<value name='Miscellaneous'
|
||||
word='the input'
|
||||
desc='a quantity'
|
||||
input='*MC.%7E-_*Miscellaneous-' />
|
||||
<value name='WordData'
|
||||
word='the input'
|
||||
desc=' referring to English words'
|
||||
input='*MC.%7E-_*WordData-' />
|
||||
<value name='MathWorld'
|
||||
word='life'
|
||||
desc=' referring to a mathematical definition'
|
||||
input='*MC.%7E-_*MathWorld-' />
|
||||
</assumption>
|
||||
<assumption type='SubCategory'
|
||||
word='what is the meaning of life'
|
||||
template='Assuming ${desc1}. Use ${desc2} instead'
|
||||
count='2'>
|
||||
<value name='AnswerToLifeUniverseEverything'
|
||||
desc='The Ultimate Answer'
|
||||
input='*DPClash.MiscellaneousE.what+is+the+meaning+of+life-_*AnswerToLifeUniverseEverything-' />
|
||||
<value name='MontyPythonsMeaningOfLife'
|
||||
desc='Monty Python's Meaning of Life'
|
||||
input='*DPClash.MiscellaneousE.what+is+the+meaning+of+life-_*MontyPythonsMeaningOfLife-' />
|
||||
</assumption>
|
||||
</assumptions>
|
||||
</queryresult>
|
Loading…
Reference in New Issue
Block a user