Skip to content

Fix failing tests #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/auth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ module.exports = (robot) ->

robot.auth = new Auth

robot.respond /@?(.+) ha(s|ve) (["'\w: -_]+) role/i, (msg) ->
robot.respond /@?([^\s]+) ha(?:s|ve) (["'\w: -_]+) role/i, (msg) ->
unless robot.auth.isAdmin msg.message.user
msg.reply "Sorry, only admins can assign roles."
else
name = msg.match[1].trim()
if name.toLowerCase() is 'i' then name = msg.message.user.name
newRole = msg.match[3].trim().toLowerCase()
newRole = msg.match[2].trim().toLowerCase()

unless name.toLowerCase() in ['', 'who', 'what', 'where', 'when', 'why']
user = robot.brain.userForName(name)
Expand All @@ -87,13 +87,13 @@ module.exports = (robot) ->
user.roles.push(newRole)
msg.reply "OK, #{name} has the '#{newRole}' role."

robot.respond /@?(.+) do(n['’]t|esn['’]t|es)( not)? have (["'\w: -_]+) role/i, (msg) ->
robot.respond /@?([^\s]+) (?:don['’]t|doesn['’]t|do not) have (["'\w: -_]+) role/i, (msg) ->
unless robot.auth.isAdmin msg.message.user
msg.reply "Sorry, only admins can remove roles."
else
name = msg.match[1].trim()
if name.toLowerCase() is 'i' then name = msg.message.user.name
newRole = msg.match[4].trim().toLowerCase()
newRole = msg.match[2].trim().toLowerCase()

unless name.toLowerCase() in ['', 'who', 'what', 'where', 'when', 'why']
user = robot.brain.userForName(name)
Expand All @@ -107,7 +107,7 @@ module.exports = (robot) ->
user.roles = (role for role in user.roles when role isnt newRole)
msg.reply "OK, #{name} doesn't have the '#{newRole}' role."

robot.respond /what roles? do(es)? @?(.+) have\?*$/i, (msg) ->
robot.respond /what roles? do(es)? @?([^\s]+) have\?*$/i, (msg) ->
name = msg.match[2].trim()
if name.toLowerCase() is 'i' then name = msg.message.user.name
user = robot.brain.userForName(name)
Expand Down
9 changes: 8 additions & 1 deletion test/auth-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ describe 'auth', ->

done()

afterEach ->
afterEach (done) ->
robot.shutdown()
done()

it 'list admin users', (done) ->
adapter.on "reply", (envelope, strings) ->
Expand Down Expand Up @@ -93,6 +94,9 @@ describe 'auth', ->
adapter.receive(new TextMessage admin_user, "hubot: admin-user has demo role")

adapter.on "reply", (envelope, strings) ->
if strings[0].match /OK, admin-user has .*demo/i
return

expect(strings[0]).to.match /ha(s|ve) the 'demo' role/i
done()

Expand All @@ -102,6 +106,9 @@ describe 'auth', ->
adapter.receive(new TextMessage admin_user, "hubot: admin-user has demo role")

adapter.on "reply", (envelope, strings) ->
if strings[0].match /OK, admin-user has .*demo/i
return

expect(strings[0]).to.match(/following roles: .*admin/)
expect(strings[0]).to.match(/following roles: .*demo/)
done()
Expand Down