diff --git a/scripts/shell.coffee b/scripts/shell.coffee index 29a0437..7013eca 100644 --- a/scripts/shell.coffee +++ b/scripts/shell.coffee @@ -22,6 +22,7 @@ runCmd = (cmd,res,cb) -> if process.env.TESTING_ASJON # Fingi di eseguire l'operazione if res? then res.send 'Operazione "completata": '+cmd + if cb? then cb null,'','' else cp.exec cmd, (err,stdout,stderr) -> if res? if err @@ -51,7 +52,7 @@ module.exports = (robot) -> if process.env.AUTO_RUN_TESTS and process.env.ADMIN_ROOM dest = room: process.env.ADMIN_ROOM.replace(':','#') robot.send dest, 'Operazione in corso: npm test' - runCmd 'npm test', null, (err,stdout,stderr) -> + runCmd 'npm test', dest, (err,stdout,stderr) -> if err robot.send dest, 'ATTENZIONE: TEST FAILURE\n'+stdout+stderr else @@ -59,11 +60,12 @@ module.exports = (robot) -> robot.on 'githubhook', (data,params) -> if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE - runCmd 'git pull && npm install', null, -> - dest = name: params.name, room: params.room.replace(':','#') + dest = name: params.name, room: params.room.replace(':','#') + res = send: (x) -> robot.send dest, x + runCmd 'git pull && npm install', res, -> robot.send dest, 'riavvio in 5 SECONDI' - reboot = -> - console.log 'AUTO IMPICCAGIONE IN CORSO!' - process.exit 0 - setTimeout reboot, 5000 + reboot = -> process.exit 0 + unless process.env.TESTING_ASJON + # Non riavviare durante i test + setTimeout reboot, 5000 diff --git a/test/github-test.coffee b/test/github-test.coffee index 6fde0ec..b40e434 100644 --- a/test/github-test.coffee +++ b/test/github-test.coffee @@ -3,6 +3,7 @@ expect = require("chai").should() Asjon = require '../asjon-testing.coffee' asjon = undefined +githubhook = undefined describe 'modulo github', -> before (done) -> @@ -11,7 +12,7 @@ describe 'modulo github', -> asjon = assa after asjon.after afterEach asjon.clear - require('../scripts/github.coffee')(asjon.robot) + githubhook = require('../scripts/github.coffee')(asjon.robot) done() it 'dovrebbe rispondere a "mostra le issues"', (done) -> @@ -87,3 +88,32 @@ describe 'modulo github', -> if acc is 2 then done() asjon.send 'asjon linkami la issue numero 5' asjon.send 'asjon linkami issue 456' + + it 'dovrebbe rendere disponibile l\'handler del webhook', -> + githubhook.should.not.be.undefined + + it 'dovrebbe informare correttamente riguardo gli aggiornamenti', (done) -> + acc = 0 + req = + body: + ref: 'refs/heads/dev' + commits: [] + params: + room: ':mocha' + user: ':mocha' + res = + send: (code) -> code.should.equal 200 + asjon.receive (e,l) -> + if acc is 0 + l.join().should.equal 'Branch '+req.body.ref+' aggiornato!\n' + if acc is 1 + l.join().should.equal 'Branch '+req.body.ref+' aggiornato!\ntest -> commit' + acc++ + if acc is 2 then done() + githubhook req, res + req.body.ref = 'refs/heads/master' + req.body.commits.push + committer: + username: 'test' + message: 'commit' + githubhook req, res diff --git a/test/shell-test.coffee b/test/shell-test.coffee index ee06b5c..db07b7d 100644 --- a/test/shell-test.coffee +++ b/test/shell-test.coffee @@ -67,3 +67,20 @@ describe 'modulo shell', -> acc++ if acc is 2 then done() asjon.send 'asjon esegui i test' + + it 'dovrebbe autoriavviarsi in caso di update se richiesto', (done) -> + data = ref: 'refs/heads/master' + params = room: ':mocha', user: ':mocha' + acc = 0 + asjon.receive (e,l) -> + if acc is 0 + l.join().should.equal 'Operazione in corso: git pull && npm install' + if acc is 1 + l.join().should.equal 'Operazione "completata": git pull && npm install' + if acc is 2 + l.join().should.equal 'riavvio in 5 SECONDI' + acc++ + if acc is 3 + done() + process.env.AUTO_KILL_ON_UPDATE = 'true' + asjon.robot.emit 'githubhook', data, params