nock = require 'nock' expect = require("chai").should() Asjon = require '../asjon-testing.coffee' asjon = undefined githubhook = undefined describe 'modulo github', -> before (done) -> # Inizializzo robot Asjon (assa) -> asjon = assa after asjon.after afterEach asjon.clear githubhook = 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' 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