Skip to content

Commit 1687499

Browse files
Nick Woodwardpatcon
Nick Woodward
authored andcommitted
Updated tests to use hubot-test-helper for test clarity (#29)
* Updated tests to use hubot-test-helper for test clarity Also updated various packages to their latest version * Removed unnecessary adapter variable * Downgraded grunt version until grunt-releases dependencies are updated * Updated Travis Config to use Node Stable and 4.4 for build * Added caching of the node_modules directory to speed up builds
1 parent e330f35 commit 1687499

File tree

3 files changed

+136
-154
lines changed

3 files changed

+136
-154
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: node_js
2-
32
node_js:
4-
- "0.11"
5-
- "0.10"
6-
3+
- "node"
4+
- "4.4"
75
before_install: npm install -g grunt-cli
8-
6+
cache:
7+
directories:
8+
- node_modules
99
notifications:
1010
email: false

package.json

+13-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"jhubert",
1515
"davereid",
1616
"patcon",
17-
"therealklanni"
17+
"therealklanni",
18+
"nick-woodward"
1819
],
1920
"license": "MIT",
2021
"keywords": [
@@ -31,18 +32,19 @@
3132
"url": "https://github.com/hubot-scripts/hubot-auth/issues"
3233
},
3334
"dependencies": {
34-
"coffee-script": "~1.6"
35+
"coffee-script": "^1.10.0"
3536
},
3637
"devDependencies": {
37-
"chai": "*",
38-
"grunt": "^0.4.4",
39-
"grunt-contrib-watch": "~0.5.3",
40-
"grunt-mocha-test": "~0.7.0",
41-
"grunt-release": "~0.6.0",
42-
"hubot": "^2.7.5",
43-
"hubot-mock-adapter": "^1.0.0",
44-
"matchdep": "~0.1.2",
45-
"mocha": "*"
38+
"chai": "^3.5.0",
39+
"co": "^4.6.0",
40+
"grunt": "^0.4.5",
41+
"grunt-contrib-watch": "^1.0.0",
42+
"grunt-mocha-test": "^0.12.7",
43+
"grunt-release": "^0.13.0",
44+
"hubot": "^2.18.0",
45+
"hubot-test-helper": "^1.4.4",
46+
"matchdep": "^1.0.1",
47+
"mocha": "^2.4.5"
4648
},
4749
"main": "index.coffee",
4850
"scripts": {

test/auth-test.coffee

+118-138
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,118 @@
1-
expect = require('chai').expect
2-
path = require 'path'
3-
4-
Robot = require 'hubot/src/robot'
5-
TextMessage = require('hubot/src/message').TextMessage
6-
7-
describe 'auth', ->
8-
robot = {}
9-
admin_user = {}
10-
role_user = {}
11-
anon_user = {}
12-
adapter = {}
13-
14-
beforeEach (done) ->
15-
process.env.HUBOT_AUTH_ADMIN = "1"
16-
17-
# Create new robot, without http, using mock adapter
18-
robot = new Robot null, "mock-adapter", false
19-
20-
robot.adapter.on "connected", ->
21-
22-
# load the module under test and configure it for the
23-
# robot. This is in place of external-scripts
24-
require("../src/auth")(robot)
25-
26-
admin_user = robot.brain.userForId "1", {
27-
name: "admin-user"
28-
room: "#test"
29-
}
30-
31-
role_user = robot.brain.userForId "2", {
32-
name: "role-user"
33-
room: "#test"
34-
}
35-
36-
anon_user = robot.brain.userForId "3", {
37-
name: "anon-user"
38-
room: "#test"
39-
}
40-
41-
adapter = robot.adapter
42-
43-
robot.run()
44-
45-
done()
46-
47-
afterEach (done) ->
48-
robot.shutdown()
49-
done()
50-
51-
it 'list admin users', (done) ->
52-
adapter.on "reply", (envelope, strings) ->
53-
expect(strings[0]).to.match /admin-user/i
54-
done()
55-
56-
adapter.receive(new TextMessage admin_user, "hubot: who has admin role?")
57-
58-
it 'list admin users using non-admin user', (done) ->
59-
adapter.on "reply", (envelope, strings) ->
60-
expect(strings[0]).to.match /admin-user/i
61-
done()
62-
63-
adapter.receive(new TextMessage anon_user, "hubot: who has admin role?")
64-
65-
it 'anon user fails to set role', (done) ->
66-
adapter.on "reply", (envelope, strings) ->
67-
expect(strings[0]).to.match /only admins can assign roles/i
68-
done()
69-
70-
adapter.receive(new TextMessage anon_user, "hubot: role-user has demo role")
71-
72-
it 'admin user successfully sets role', (done) ->
73-
adapter.on "reply", (envelope, strings) ->
74-
expect(strings[0]).to.match /role-user has the 'demo' role/i
75-
done()
76-
77-
adapter.receive(new TextMessage admin_user, "hubot: role-user has demo role")
78-
79-
it 'admin user successfully sets role in the first-person', (done) ->
80-
adapter.on "reply", (envelope, strings) ->
81-
expect(strings[0]).to.match /admin-user has the 'demo' role/i
82-
done()
83-
84-
adapter.receive(new TextMessage admin_user, "hubot: I have demo role")
85-
86-
it 'fail to add admin role via command', (done) ->
87-
adapter.on "reply", (envelope, strings) ->
88-
expect(strings[0]).to.match /sorry/i
89-
done()
90-
91-
adapter.receive(new TextMessage admin_user, "hubot: role-user has admin role")
92-
93-
it 'fail to remove admin role via command', (done) ->
94-
adapter.on "reply", (envelope, strings) ->
95-
expect(strings[0]).to.match /sorry/i
96-
done()
97-
98-
adapter.receive(new TextMessage admin_user, "hubot: role-user doesn't have admin role")
99-
100-
it 'admin user successfully removes role in the first-person', (done) ->
101-
adapter.receive(new TextMessage admin_user, "hubot: admin-user has demo role")
102-
103-
adapter.on "reply", (envelope, strings) ->
104-
if strings[0].match /OK, admin-user has .*demo/i
105-
return
106-
107-
expect(strings[0]).to.match /ha(s|ve) the 'demo' role/i
108-
done()
109-
110-
adapter.receive(new TextMessage admin_user, "hubot: I don't have demo role")
111-
112-
it 'successfully list multiple roles of admin user', (done) ->
113-
adapter.receive(new TextMessage admin_user, "hubot: admin-user has demo role")
114-
115-
adapter.on "reply", (envelope, strings) ->
116-
if strings[0].match /OK, admin-user has .*demo/i
117-
return
118-
119-
expect(strings[0]).to.match(/following roles: .*admin/)
120-
expect(strings[0]).to.match(/following roles: .*demo/)
121-
done()
122-
123-
adapter.receive(new TextMessage anon_user, "hubot: what roles does admin-user have?")
124-
125-
it 'successfully list assigned roles', (done) ->
126-
adapter.receive(new TextMessage admin_user, "hubot: admin-user has demo role")
127-
adapter.receive(new TextMessage admin_user, "hubot: anon-user has test role")
128-
adapter.receive(new TextMessage admin_user, "hubot: admin-user has test role")
129-
130-
adapter.on "reply", (envelope, strings) ->
131-
if strings[0].match /OK, .* has .* role/i
132-
return
133-
134-
135-
expect(strings[0]).to.match(/following roles .*:.*demo.*test/)
136-
done()
137-
138-
adapter.receive(new TextMessage admin_user, "hubot: list assigned roles")
1+
Helper = require("hubot-test-helper")
2+
helper = new Helper("../src")
3+
4+
expect = require("chai").expect
5+
6+
describe "auth", ->
7+
8+
beforeEach ->
9+
process.env.HUBOT_AUTH_ADMIN = "alice"
10+
@room = helper.createRoom()
11+
@room.robot.brain.userForId "alice",
12+
name: "alice"
13+
14+
@room.robot.brain.userForId "jimmy",
15+
name: "jimmy"
16+
17+
@room.robot.brain.userForId "amy",
18+
name: "amy"
19+
20+
afterEach ->
21+
@room.destroy()
22+
23+
context "<user> has <role> role", ->
24+
25+
it "admin user successfully sets role", ->
26+
@room.user.say("alice", "hubot: jimmy has demo role").then =>
27+
expect(@room.messages).to.eql [
28+
["alice", "hubot: jimmy has demo role"]
29+
["hubot", "@alice OK, jimmy has the 'demo' role."]
30+
]
31+
32+
33+
it "admin user successfully sets role in the first-person", ->
34+
@room.user.say("alice", "hubot: I have demo role").then =>
35+
expect(@room.messages).to.eql [
36+
["alice", "hubot: I have demo role"]
37+
["hubot", "@alice OK, alice has the 'demo' role."]
38+
]
39+
40+
41+
it "fail to add admin role via command", ->
42+
@room.user.say("alice", "hubot: jimmy has admin role").then =>
43+
expect(@room.messages).to.eql [
44+
["alice", "hubot: jimmy has admin role"]
45+
["hubot", "@alice Sorry, the 'admin' role can only be defined in the HUBOT_AUTH_ADMIN env variable."]
46+
]
47+
48+
it "anon user fails to set role", ->
49+
@room.user.say("amy", "hubot: jimmy has demo role").then =>
50+
expect(@room.messages).to.eql [
51+
["amy", "hubot: jimmy has demo role"]
52+
["hubot", "@amy Sorry, only admins can assign roles."]
53+
]
54+
55+
context "<user> doesn't have <role> role", ->
56+
it "admin user successfully removes role in the first-person", ->
57+
@room.user.say("alice", "hubot: alice has demo role").then =>
58+
@room.user.say("alice", "hubot: I don't have demo role").then =>
59+
expect(@room.messages).to.eql [
60+
["alice", "hubot: alice has demo role"]
61+
["hubot", "@alice OK, alice has the 'demo' role."]
62+
["alice", "hubot: I don't have demo role"]
63+
["hubot", "@alice OK, alice doesn't have the 'demo' role."]
64+
]
65+
66+
it "fail to remove admin role via command", ->
67+
@room.user.say("alice", "hubot: jimmy doesn't have admin role").then =>
68+
expect(@room.messages).to.eql [
69+
["alice", "hubot: jimmy doesn't have admin role"]
70+
["hubot", "@alice Sorry, the 'admin' role can only be removed from the HUBOT_AUTH_ADMIN env variable."]
71+
]
72+
73+
context "what roles does <user> have", ->
74+
beforeEach ->
75+
@room.user.say("alice", "hubot: alice has demo role")
76+
77+
it "successfully list multiple roles of admin user", ->
78+
@room.user.say("amy", "hubot: what roles does alice have?").then =>
79+
expect(@room.messages).to.eql [
80+
["alice", "hubot: alice has demo role"]
81+
["hubot", "@alice OK, alice has the 'demo' role."]
82+
["amy", "hubot: what roles does alice have?"]
83+
["hubot", "@amy alice has the following roles: admin, demo."]
84+
]
85+
86+
context "who has <role> role", ->
87+
it "list admin users", ->
88+
@room.user.say("alice", "hubot: who has admin role?").then =>
89+
expect(@room.messages).to.eql [
90+
["alice", "hubot: who has admin role?"]
91+
["hubot", "@alice The following people have the 'admin' role: alice"]
92+
]
93+
94+
it "list admin users using non-admin user", ->
95+
@room.user.say("amy", "hubot: who has admin role?").then =>
96+
expect(@room.messages).to.eql [
97+
["amy", "hubot: who has admin role?"]
98+
["hubot", "@amy The following people have the 'admin' role: alice"]
99+
]
100+
101+
context "list assigned roles", ->
102+
beforeEach ->
103+
@room.user.say("alice", "hubot: alice has demo role").then =>
104+
@room.user.say("alice", "hubot: amy has test role").then =>
105+
@room.user.say "alice", "hubot: alice has test role"
106+
107+
it "successfully list assigned roles", ->
108+
@room.user.say("alice", "hubot: list assigned roles").then =>
109+
expect(@room.messages).to.eql [
110+
["alice", "hubot: alice has demo role"]
111+
["hubot", "@alice OK, alice has the 'demo' role."]
112+
["alice", "hubot: amy has test role"]
113+
["hubot", "@alice OK, amy has the 'test' role."]
114+
["alice", "hubot: alice has test role"]
115+
["hubot", "@alice OK, alice has the 'test' role."]
116+
["alice", "hubot: list assigned roles"]
117+
["hubot", "@alice The following roles are available: demo, test"]
118+
]

0 commit comments

Comments
 (0)