Skip to content

Commit

Permalink
cover auth test
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Aug 13, 2016
1 parent adef4be commit dd6a512
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -58,7 +58,7 @@ Commands prefixed by `.cron` are here taking in account we use the `.` as hubot
.cron blah room = shell
.cron blah message = tick tack
.cron start blah
activates the job, which ill run every 5 seconds
activates the job, which will run every 5 seconds
.cron blah * * * * *
modifies the job blah to run every minutes instead
and it will emit the same event cron.message
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"coveralls": "^2.11.11",
"es6-promise": "^3.2.1",
"hubot": "2.x",
"hubot-auth": "^2.0.0",
"hubot-test-helper": "1.4.4",
"istanbul": "^0.4.4",
"mocha": "^2.4.5",
Expand Down
49 changes: 48 additions & 1 deletion test/cron_events_test.coffee
Expand Up @@ -10,7 +10,7 @@ Helper = require('hubot-test-helper')
# helper loads a specific script if it's a file
helper = new Helper('../scripts/cron_events.coffee')

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

Expand Down Expand Up @@ -455,3 +455,50 @@ describe 'cron_events module', ->
expect(room.robot.brain.data.cron.somejob.started).to.be.true
it 'should keep the job in the queue', ->
expect(room.robot.cron.jobs.somejob).to.be.defined

# ---------------------------------------------------------------------------------
context 'permissions system', ->
beforeEach ->
process.env.HUBOT_AUTH_ADMIN = 'admin_user'
room.robot.loadFile path.resolve('node_modules/hubot-auth/src'), 'auth.coffee'
room.robot.brain.userForId 'admin_user', {
name: 'admin_user'
}
room.robot.brain.userForId 'user', {
name: 'user'
}

context 'user wants to stop a job', ->
beforeEach ->
room.robot.brain.data.cron = {
somejob: {
cronTime: '0 0 1 1 *',
eventName: 'event1',
eventData: { },
started: true
}
}
room.robot.brain.emit 'loaded'
room.robot.cron.loadAll()

afterEach ->
room.robot.brain.data.cron = { }
room.robot.cron.jobs = { }

context.only 'and user is not admin', ->
hubot 'cron stop somejob', 'user'
it 'should deny permission to the user', ->
expect(hubotResponse()).to.eql "@user You don't have permission to do that."
it 'should change brain to record it\'s not started', ->
expect(room.robot.brain.data.cron.somejob.started).to.be.true
it 'should not have added a job in the jobs queue', ->
expect(room.robot.cron.jobs.somejob).to.be.defined

context 'and user is admin', ->
hubot 'cron stop somejob', 'admin_user'
it 'should comply and stop the job', ->
expect(hubotResponse()).to.eql "The job somejob is now paused."
it 'should change brain to record it\'s not started', ->
expect(room.robot.brain.data.cron.somejob.started).to.be.false
it 'should not have added a job in the jobs queue', ->
expect(room.robot.cron.jobs.somejob).to.be.undefined

0 comments on commit dd6a512

Please sign in to comment.