Skip to content

Commit

Permalink
prepare a sample/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Dec 28, 2017
1 parent 6b3ccb3 commit 3b41e54
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/gitlab.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ class Gitlab
back += ' (' + timespent + ' min)\n\n'
if data.info.length > 0
back += 'Info\n'
back += '---------'
back += '---------\n'
for info in data.info
back += "- #{info}\n"
back += '\n\n'
if data.agreed.length > 0
back += 'Agreed\n'
back += '---------'
back += '---------\n'
for agreed in data.agreed
back += "- #{agreed}\n"
back += '\n\n'
Expand Down
2 changes: 1 addition & 1 deletion lib/meetbotlib.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Meetbot
if @data[room]
label = @data[room].label
@data[room].end = moment().utc().format()
@robot.emit 'meetbot.notes', @data[room]
# @robot.emit 'meetbot.notes', @data[room]
delete @data[room]
res label
else
Expand Down
2 changes: 1 addition & 1 deletion scripts/meetbot-gitlab.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (robot) ->
label = data.label.replace(/[^a-zA-Z0-9]/g, '')
date = moment(data.end).format('YYYY-MM-DD')
branchname = "#{date}-#{label}"
if process.env.MEETBOT_GITLAB_REPO and
if false and process.env.MEETBOT_GITLAB_REPO and
process.env.MEETBOT_GITLAB_URL and
process.env.MEETBOT_GITLAB_APIKEY
gitlab.getRepoId(process.env.MEETBOT_GITLAB_REPO)
Expand Down
308 changes: 308 additions & 0 deletions test/meetbot-gitlab_test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
require('source-map-support').install {
handleUncaughtExceptions: false,
environment: 'node'
}

require('es6-promise').polyfill()

Helper = require('hubot-test-helper')
Hubot = require('../node_modules/hubot')

# helper loads a specific script if it's a file
helper = new Helper('../scripts/meetbot.coffee')

path = require 'path'
sinon = require 'sinon'
moment = require 'moment'
expect = require('chai').use(require('sinon-chai')).expect

room = null
meetData = {
room1: {
label: 'standup meeting'
topic: ''
info: [ ]
action: [ ]
agreed: [ ]
logs: [ ]
}
}

# --------------------------------------------------------------------------------------------------
describe 'meetbot module', ->

hubotEmit = (e, data, tempo = 40) ->
beforeEach (done) ->
room.robot.emit e, data
setTimeout (done), tempo

hubotHear = (message, userName = 'momo', tempo = 40) ->
beforeEach (done) ->
room.user.say userName, message
setTimeout (done), tempo

hubot = (message, userName = 'momo') ->
hubotHear "@hubot #{message}", userName

hubotResponse = (i = 1) ->
room.messages[i]?[1]

hubotResponseCount = ->
room.messages?.length - 1

beforeEach ->
room = helper.createRoom { httpd: false }
room.robot.logger.error = sinon.stub()

# room.receive = (userName, message) ->
# new Promise (resolve) =>
# @messages.push [userName, message]
# user = room.robot.brain.userForId userName
# @robot.receive(new Hubot.TextMessage(user, message), resolve)

# --------------------------------------------------------------------------------------------------
context 'meetbot robot launch', ->
beforeEach ->
room.robot.brain.data.meetbot = meetData
room.robot.brain.emit 'loaded'

afterEach ->
room.robot.brain.data.meetbot = { }

context 'when brain is loaded', ->
it 'room1 notes should be loaded', ->
expect(room.robot.meetbot.data.room1).to.be.defined
it 'room2 notes should be absent', ->
expect(room.robot.meetbot.data.room2).not.to.be.defined

# --------------------------------------------------------------------------------------------------
context 'user wants to know hubot-meetbot version', ->

context 'meet version', ->
hubot 'meet version'
it 'should reply version number', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.match /hubot-meetbot is version [0-9]+\.[0-9]+\.[0-9]+/

# --------------------------------------------------------------------------------------------------
context 'user wants to know if a meeting is going on', ->

context 'there is no meeting going on', ->
beforeEach ->
room.robot.brain.data.meetbot = { }
room.robot.brain.emit 'loaded'

context 'meet', ->
hubot 'meet'
it 'should explain that there is no meeting', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.eq 'There is no meeting going on right now on this channel.'

context 'there is a meeting going on', ->
beforeEach ->
room.robot.brain.data.meetbot = meetData
room.robot.brain.emit 'loaded'

afterEach ->
room.robot.brain.data.meetbot = { }

context 'meet', ->
hubot 'meet'
it 'should give the label of the ongoing meeting', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.eq 'A meeting is in progress, named `standup meeting`.'
# --------------------------------------------------------------------------------------------------
context 'user starts a new meeting', ->

context 'but there is a meeting already going on', ->
beforeEach ->
room.robot.brain.data.meetbot = meetData
room.robot.brain.emit 'loaded'

afterEach ->
room.robot.brain.data.meetbot = { }

context 'meet start newmeeting', ->
hubot 'meet start newmeeting'
it 'should give the label of the ongoing meeting', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.eq 'A meeting is already in progress, named `standup meeting`.'

context 'and there is no meeting already going on', ->
beforeEach ->
room.robot.brain.data.meetbot = { }
afterEach ->
room.robot.brain.data.meetbot = { }

context 'meet start', ->
beforeEach ->
@now = moment().utc().format('HH:mm')
hubot 'meet start'
it 'should give the label of the new meeting', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse())
.to.eq "Meeting `meeting of #{@now}` is now open. All discussions will now be recorded."

context 'meet start newmeeting', ->
hubot 'meet start newmeeting'
it 'should announce the new meeting is started', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse())
.to.eq 'Meeting `newmeeting` is now open. All discussions will now be recorded.'

# --------------------------------------------------------------------------------------------------
context 'meeting is started', ->

context 'and someone says something', ->
beforeEach ->
room.robot.brain.data.meetbot = meetData
room.robot.brain.emit 'loaded'
@clock = sinon.useFakeTimers({ now: moment().valueOf(), toFake: ['Date'] })

afterEach ->
room.robot.brain.data.meetbot = { }
@clock.restore()

context 'I say something', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubotHear 'I say something'
it 'should record what someone says in the logs', ->
expect(hubotResponseCount()).to.eql 0
expect(room.robot.meetbot.data.room1.logs.length).to.eql 1
expect(room.robot.meetbot.data.room1.logs[0])
.to.eql {
time: moment(@clock.now, 'x').utc().format()
user: 'momo'
text: 'I say something'
}

# topic
context 'meet topic some topic', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'meet topic some topic'
it 'should record the new topic', ->
expect(hubotResponseCount()).to.eql 1
expect(room.robot.meetbot.data.room1.logs.length).to.eql 1
expect(room.robot.meetbot.data.room1.topic).to.eql 'some topic'
expect(hubotResponse())
.to.eq 'Topic `some topic` recorded for meeting `standup meeting`.'

context 'meet agree some topic', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'meet agree some topic'
it 'should record the new agreement', ->
expect(hubotResponseCount()).to.eql 1
expect(room.robot.meetbot.data.room1.logs.length).to.eql 1
expect(room.robot.meetbot.data.room1.agreed[0]).to.eql 'some topic'
expect(hubotResponse())
.to.eq 'Agreement `some topic` recorded for meeting `standup meeting`.'

context 'agree some topic', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'agree some topic'
it 'should record the new agreement', ->
expect(hubotResponse())
.to.eq 'Agreement `some topic` recorded for meeting `standup meeting`.'

context 'agreed some topic', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'agreed some topic'
it 'should record the new agreement', ->
expect(hubotResponse())
.to.eq 'Agreement `some topic` recorded for meeting `standup meeting`.'

# info
context 'meet info some info', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'meet info some info'
it 'should record the new info', ->
expect(hubotResponseCount()).to.eql 1
expect(room.robot.meetbot.data.room1.logs.length).to.eql 1
expect(room.robot.meetbot.data.room1.info[0]).to.eql 'some info'
expect(hubotResponse())
.to.eq 'Info `some info` recorded for meeting `standup meeting`.'

context 'info some info', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'info some info'
it 'should record the new info', ->
expect(hubotResponse())
.to.eq 'Info `some info` recorded for meeting `standup meeting`.'

# action
context 'meet action some action', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'meet action some action'
it 'should record the new action', ->
expect(hubotResponseCount()).to.eql 1
expect(room.robot.meetbot.data.room1.logs.length).to.eql 1
expect(room.robot.meetbot.data.room1.action[0]).to.eql 'some action'
expect(hubotResponse())
.to.eq 'Action `some action` recorded for meeting `standup meeting`.'

context 'action some action', ->
afterEach ->
room.robot.meetbot.data.room1.logs = []
hubot 'action some action'
it 'should record the new action', ->
expect(hubotResponse())
.to.eq 'Action `some action` recorded for meeting `standup meeting`.'

# end
context 'endmeeting', ->
beforeEach ->
room.robot.brain.data.meetbot = meetData
afterEach ->
room.robot.meetbot.data.room1 = { }
hubot 'endmeeting'
it 'should close the meeting', ->
expect(hubotResponseCount()).to.eql 1
# expect(room.robot.brain.data.meetbot).to.eql room1: { }
expect(hubotResponse())
.to.eq 'Closing meeting `standup meeting` ...'

# --------------------------------------------------------------------------------------------------
context 'meeting is NOT started', ->

context 'and someone says something', ->
beforeEach ->
room.robot.brain.data.meetbot = { }
room.robot.brain.emit 'loaded'

afterEach ->
room.robot.brain.data.meetbot = { }

context 'I say something', ->
hubotHear 'I say something'
it 'should not record anything', ->
expect(hubotResponseCount()).to.eql 0
expect(room.robot.meetbot.data).to.eql { }

# topic
context 'meet topic some topic', ->
hubot 'meet topic some topic'
it 'should warn that no meeting is ongoing', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.eq 'There is no ongoing meeting here.'

# info
context 'meet info some info', ->
hubot 'meet info some info'
it 'should warn that no meeting is ongoing', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.eq 'There is no ongoing meeting here.'

# action
context 'meet action some action', ->
hubot 'meet action some action'
it 'should warn that no meeting is ongoing', ->
expect(hubotResponseCount()).to.eql 1
expect(hubotResponse()).to.eq 'There is no ongoing meeting here.'
11 changes: 1 addition & 10 deletions test/meetbot_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ moment = require 'moment'
expect = require('chai').use(require('sinon-chai')).expect

room = null
meetData = {
room1: {
label: 'standup meeting'
topic: ''
info: [ ]
action: [ ]
agreed: [ ]
logs: [ ]
}
}
meetData = require './sample/meetdata-empty.json'

# --------------------------------------------------------------------------------------------------
describe 'meetbot module', ->
Expand Down
10 changes: 10 additions & 0 deletions test/sample/meetdata-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"room1": {
"label": "standup meeting",
"topic": "",
"info": [ ],
"action": [ ],
"agreed": [ ],
"logs": [ ]
}
}

0 comments on commit 3b41e54

Please sign in to comment.