|
| 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