Skip to content

Commit fe49581

Browse files
committed
Add "tell me about my team"
1 parent b14a133 commit fe49581

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

bootstrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
export HACK24API_URL=http://localhost:5000
4+
export HACKBOT_PASSWORD=h4c6b07
5+
6+
./bin/hubot

scripts/hack24api.coffee

+15-1
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,18 @@ module.exports = (robot) ->
190190
if res.statusCode is 404
191191
robot.hack24client.createUser(otherUser.id, otherUser.name, emailAddress)
192192
.then (res) ->
193-
return addUserToTeam teamId, otherUser.id, emailAddress
193+
return addUserToTeam teamId, otherUser.id, emailAddress
194+
195+
196+
robot.respond /tell me about my team/i, (response) ->
197+
userId = response.message.user.id
198+
199+
robot.hack24client.getUser(userId)
200+
.then (res) ->
201+
memberList = res.user.team.members.map((member) => member.name)
202+
203+
noun = if res.user.team.members.length == 1 then 'member' else 'members'
204+
205+
response.reply "\"#{res.user.team.name}\" has #{res.user.team.members.length} #{noun}: #{memberList.join(', ')}"
206+
.catch (err) ->
207+
response.reply 'I\'m sorry Sir, there appears to be a big problem!'

test/tell_me_about_my_team.coffee

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
chai = require 'chai'
2+
expect = chai.expect
3+
sinon = require 'sinon'
4+
chai.use require 'sinon-chai'
5+
6+
Helper = require 'hubot-test-helper'
7+
helper = new Helper('../scripts/hack24api.coffee')
8+
9+
describe '@hubot tell me about my team', ->
10+
11+
describe 'when in a team', ->
12+
13+
before (done) ->
14+
@room = helper.createRoom()
15+
16+
@userId = 'jerry'
17+
@teamName = 'Pointy Wizards'
18+
@firstTeamMember = 'Jerry'
19+
@secondTeamMember = 'Bob'
20+
@thirdTeamMember = 'Perry'
21+
22+
@getUserStub = sinon.stub().returns Promise.resolve
23+
ok: true
24+
user:
25+
id: @userId
26+
team: {
27+
name: @teamName
28+
members: [{
29+
name: @firstTeamMember
30+
},{
31+
name: @secondTeamMember
32+
},{
33+
name: @thirdTeamMember
34+
}]
35+
}
36+
37+
@room.robot.hack24client =
38+
getUser: @getUserStub
39+
40+
@room.user.say(@userId, "@hubot tell me about my team").then done
41+
42+
it 'should fetch the user', ->
43+
expect(@getUserStub).to.have.been.calledWith(@userId)
44+
45+
it 'should tell the user the team information', ->
46+
expect(@room.messages).to.eql [
47+
[@userId, "@hubot tell me about my team"],
48+
['hubot', "@#{@userId} \"#{@teamName}\" has 3 members: #{@firstTeamMember}, #{@secondTeamMember}, #{@thirdTeamMember}"]
49+
]
50+
51+
after ->
52+
@room.destroy()
53+
54+
describe 'when getUser errors', ->
55+
56+
before (done) ->
57+
@room = helper.createRoom()
58+
59+
@userId = 'jerry'
60+
61+
@room.robot.hack24client =
62+
getUser: ->
63+
Promise.reject new Error('unknown')
64+
65+
@room.user.say(@userId, "@hubot tell me about my team").then done
66+
67+
it 'should tell the user that there is a problem', ->
68+
expect(@room.messages).to.eql [
69+
[@userId, "@hubot tell me about my team"],
70+
['hubot', "@#{@userId} I'm sorry Sir, there appears to be a big problem!"]
71+
]
72+
73+
after ->
74+
@room.destroy()

0 commit comments

Comments
 (0)