asjon/test/git-test.coffee

124 lines
3.4 KiB
CoffeeScript
Raw Normal View History

2015-04-29 15:18:03 +02:00
nock = require 'nock'
expect = require("chai").should()
2017-02-27 00:27:39 +01:00
Asjon = require './asjon-testing.coffee'
2015-04-29 15:18:03 +02:00
asjon = undefined
2018-06-08 08:57:39 +02:00
githook = undefined
2015-04-29 15:18:03 +02:00
2018-06-08 08:57:39 +02:00
describe 'modulo git', ->
2015-04-29 15:18:03 +02:00
before (done) ->
# Inizializzo robot
Asjon (assa) ->
asjon = assa
after asjon.after
afterEach asjon.clear
2018-06-08 08:57:39 +02:00
githook = require('../scripts/git.coffee')(asjon.robot)
2015-04-29 15:18:03 +02:00
done()
2018-06-08 08:57:39 +02:00
process.env.HUBOT_GIT_URL = 'https://git.example.com'
2018-06-12 01:50:40 +02:00
process.env.HUBOT_GIT_API = 'https://api.example.com'
2018-06-08 08:57:39 +02:00
process.env.HUBOT_GIT_REPO = 'owner/asjon'
process.env.HUBOT_GIT_TOKEN = 'secret'
2015-04-29 15:18:03 +02:00
it 'dovrebbe rispondere a "mostra le issues"', (done) ->
questions = [
"asjon mostrami le issue"
"asjon mostrami le issues"
"asjon issues"
"asjon le issue"
"asjon issue"
]
2018-06-12 01:50:40 +02:00
nock('https://api.example.com')
2018-06-08 08:57:39 +02:00
.get('/repos/owner/asjon/issues?state=open&sort=updated')
2015-04-29 15:18:03 +02:00
.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) ->
2018-06-12 01:50:40 +02:00
nock('https://api.example.com')
2018-06-08 08:57:39 +02:00
.get('/repos/owner/asjon/issues?state=open&sort=updated')
2015-04-29 15:18:03 +02:00
.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) ->
2018-06-12 01:50:40 +02:00
nock('https://api.example.com')
2018-06-08 08:57:39 +02:00
.get('/repos/owner/asjon/issues?state=open&sort=updated')
2015-04-29 15:18:03 +02:00
.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
2018-06-08 08:57:39 +02:00
l.join().should.equal 'https://git.example.com/owner/asjon/issues/5'
2015-04-29 15:18:03 +02:00
else
2018-06-08 08:57:39 +02:00
l.join().should.equal 'https://git.example.com/owner/asjon/issues/456'
2015-04-29 15:18:03 +02:00
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', ->
2018-06-08 08:57:39 +02:00
githook.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
2017-02-27 15:45:25 +01:00
l.join().should.equal 'branch '+req.body.ref+' aggiornato!\n'
if acc is 1
2017-02-27 15:45:25 +01:00
l.join().should.equal 'branch '+req.body.ref+' aggiornato!\ntest -> commit'
acc++
if acc is 2 then done()
2018-06-08 08:57:39 +02:00
githook req, res
req.body.ref = 'refs/heads/master'
req.body.commits.push
committer:
username: 'test'
message: 'commit'
2018-06-08 08:57:39 +02:00
githook req, res