1 | chai = require 'chai'
|
2 | sinon = require 'sinon'
|
3 | chai.use require 'sinon-chai'
|
4 | Hubot = require('hubot')
|
5 |
|
6 | expect = chai.expect
|
7 |
|
8 | CURRENT_LABEL = 'todo_current'
|
9 | UPCOMING_LABEL = 'todo_upcoming'
|
10 | SHELF_LABEL = 'hold'
|
11 |
|
12 | describe 'github-todos', ->
|
13 | beforeEach ->
|
14 | @robot = new Hubot.Robot(null, "mock-adapter", false, "Hubot")
|
15 | @user = @robot.brain.userForId('1', name: "adam", room: "#room")
|
16 |
|
17 | require('../scripts/github-todos')(@robot)
|
18 |
|
19 | @robot.githubTodosSender =
|
20 | addIssue: sinon.spy()
|
21 | moveIssue: sinon.spy()
|
22 | assignIssue: sinon.spy()
|
23 | showIssues: sinon.spy()
|
24 | showMilestones: sinon.spy()
|
25 | commentOnIssue: sinon.spy()
|
26 |
|
27 | @sendCommand = (x) ->
|
28 | @robot.adapter.receive(new Hubot.TextMessage(@user, "Hubot #{x}"))
|
29 |
|
30 | @expectCommand = (commandName, args...) ->
|
31 | args.unshift(sinon.match.any)
|
32 | expect(@robot.githubTodosSender[commandName]).to.have.been.calledWith(args...)
|
33 |
|
34 | @expectNoCommand = (commandName) ->
|
35 | expect(@robot.githubTodosSender[commandName]).to.not.have.been.called
|
36 |
|
37 | describe "hubot add task <text>", ->
|
38 | it 'works', ->
|
39 | @sendCommand 'add task foo'
|
40 | @expectCommand('addIssue', 'foo', 'adam')
|
41 |
|
42 | describe "hubot add task with hyphen in text", ->
|
43 | it 'works', ->
|
44 | @sendCommand 'add task do a flim-flam to the blip-blop'
|
45 | @expectCommand('addIssue', 'do a flim-flam to the blip-blop', 'adam')
|
46 |
|
47 | describe "hubot ask <user> to <text>", ->
|
48 | it 'works', ->
|
49 | @sendCommand 'ask adam to foo'
|
50 | @expectCommand('addIssue', 'foo', 'adam')
|
51 |
|
52 | describe "hubot assign <id> to <user>", ->
|
53 | it 'works', ->
|
54 | @sendCommand 'assign 11 to adam'
|
55 | @expectCommand('assignIssue', '11', 'adam')
|
56 |
|
57 | describe "hubot assign <user> to <id>", ->
|
58 | it 'works', ->
|
59 | @sendCommand 'assign adam to 11'
|
60 | @expectCommand('assignIssue', '11', 'adam')
|
61 |
|
62 | describe "hubot finish <id>", ->
|
63 | it 'works', ->
|
64 | @sendCommand 'finish 11'
|
65 | @expectCommand('moveIssue', '11', 'done')
|
66 | @expectNoCommand('commentOnIssue')
|
67 |
|
68 | describe "hubot finish <id> with body", ->
|
69 | it 'works', ->
|
70 | @sendCommand 'finish 11 body: i finished dat ting. it was tough!'
|
71 | @expectCommand('moveIssue', '11', 'done')
|
72 | @expectCommand('commentOnIssue', '11', "i finished dat ting. it was tough!")
|
73 |
|
74 | it 'strips quotes', ->
|
75 | @sendCommand 'finish 11 body: "i finished dat ting. it was tough!"'
|
76 | @expectCommand('moveIssue', '11', 'done')
|
77 | @expectCommand('commentOnIssue', '11', "i finished dat ting. it was tough!")
|
78 |
|
79 | it 'strips smart double quotes', ->
|
80 | @sendCommand 'finish 11 body: “i finished dat ting. it was tough!”'
|
81 | @expectCommand('moveIssue', '11', 'done')
|
82 | @expectCommand('commentOnIssue', '11', "i finished dat ting. it was tough!")
|
83 |
|
84 | it 'strips smart single quotes', ->
|
85 | @sendCommand 'finish 11 body: ‘i finished dat ting. it was tough!’'
|
86 | @expectCommand('moveIssue', '11', 'done')
|
87 | @expectCommand('commentOnIssue', '11', "i finished dat ting. it was tough!")
|
88 |
|
89 | describe "hubot i'll work on <id>", ->
|
90 | it 'works', ->
|
91 | @sendCommand "i'll work on 11"
|
92 | @expectCommand('assignIssue', '11', 'adam')
|
93 |
|
94 | it 'works without apostrophe', ->
|
95 | @sendCommand "ill work on 11"
|
96 | @expectCommand('assignIssue', '11', 'adam')
|
97 |
|
98 | describe "hubot move <id> to <done|current|upcoming|shelf>", ->
|
99 | it 'works', ->
|
100 | @sendCommand "move 11 to todo_upcoming"
|
101 | @expectCommand('moveIssue', '11', UPCOMING_LABEL)
|
102 |
|
103 | describe "specifying a repo", ->
|
104 | it 'works with a simple repo name', ->
|
105 | @sendCommand "move foobar#11 to todo_upcoming"
|
106 | @expectCommand('moveIssue', 'foobar#11', UPCOMING_LABEL)
|
107 |
|
108 | it 'works with a more complex repo name', ->
|
109 | @sendCommand "move screendoor-v2#11 to todo_upcoming"
|
110 | @expectCommand('moveIssue', 'screendoor-v2#11', UPCOMING_LABEL)
|
111 |
|
112 | describe "hubot what am i working on", ->
|
113 | it 'works', ->
|
114 | @sendCommand "what am i working on"
|
115 | @expectCommand('showIssues', 'adam', CURRENT_LABEL)
|
116 |
|
117 | describe "hubot what's <user|everyone> working on", ->
|
118 | it 'works', ->
|
119 | @sendCommand "what's clay working on?"
|
120 | @expectCommand('showIssues', 'clay', CURRENT_LABEL)
|
121 |
|
122 | it 'works without apostrophe', ->
|
123 | @sendCommand "whats clay working on?"
|
124 | @expectCommand('showIssues', 'clay', CURRENT_LABEL)
|
125 |
|
126 | describe "hubot what's next", ->
|
127 | it 'works', ->
|
128 | @sendCommand "what's next?"
|
129 | @expectCommand('showIssues', 'adam', UPCOMING_LABEL)
|
130 |
|
131 | it 'works without apostrophe', ->
|
132 | @sendCommand "whats next?"
|
133 | @expectCommand('showIssues', 'adam', UPCOMING_LABEL)
|
134 |
|
135 | describe "hubot what's next for <user|everyone>", ->
|
136 | it 'works', ->
|
137 | @sendCommand "what's next for clay?"
|
138 | @expectCommand('showIssues', 'clay', UPCOMING_LABEL)
|
139 |
|
140 | it 'works without apostrophe', ->
|
141 | @sendCommand "whats next for clay?"
|
142 | @expectCommand('showIssues', 'clay', UPCOMING_LABEL)
|
143 |
|
144 | describe "hubot what's on <user|everyone>'s shelf", ->
|
145 | it 'works', ->
|
146 | @sendCommand "what's on everyone's shelf?"
|
147 | @expectCommand('showIssues', 'everyone', SHELF_LABEL)
|
148 |
|
149 | it 'works without apostrophe', ->
|
150 | @sendCommand "whats on everyone's shelf?"
|
151 | @expectCommand('showIssues', 'everyone', SHELF_LABEL)
|
152 |
|
153 | it 'handles smart quotes', ->
|
154 | @sendCommand "what’s on everyone's shelf?"
|
155 | @expectCommand('showIssues', 'everyone', SHELF_LABEL)
|
156 |
|
157 | describe "hubot what's on my shelf", ->
|
158 | it 'works', ->
|
159 | @sendCommand "what's on my shelf?"
|
160 | @expectCommand('showIssues', 'adam', SHELF_LABEL)
|
161 |
|
162 | it 'works without apostrophe', ->
|
163 | @sendCommand "whats on my shelf?"
|
164 | @expectCommand('showIssues', 'adam', SHELF_LABEL)
|
165 |
|
166 | describe "hubot work on <id>", ->
|
167 | it 'works', ->
|
168 | @sendCommand "work on 12"
|
169 | @expectCommand('moveIssue', '12', CURRENT_LABEL)
|
170 |
|
171 | it 'handles spaces', ->
|
172 | @sendCommand "work on 12 "
|
173 | @expectCommand('moveIssue', ' 12 ', CURRENT_LABEL)
|
174 |
|
175 | it 'handles pound sign', ->
|
176 | @sendCommand "work on #12"
|
177 | @expectCommand('moveIssue', '#12', CURRENT_LABEL)
|
178 |
|
179 | it 'parses complex repo name', ->
|
180 | @sendCommand "work on screendoor-v2#12"
|
181 | @expectCommand('moveIssue', 'screendoor-v2#12', CURRENT_LABEL)
|
182 | @expectNoCommand('addIssue')
|
183 |
|
184 | it 'adds a new task', ->
|
185 | @sendCommand "work on doing the thing with 12 peanuts, y'all"
|
186 | @expectCommand(
|
187 | 'addIssue',
|
188 | "doing the thing with 12 peanuts, y'all",
|
189 | 'adam',
|
190 | label: CURRENT_LABEL
|
191 | )
|
192 | @expectNoCommand('moveIssue')
|
193 |
|
194 | describe "hubot show milestones", ->
|
195 | it 'works', ->
|
196 | @sendCommand "show milestones"
|
197 | @expectCommand('showMilestones', 'all')
|
198 |
|
199 | it 'specifies due date only', ->
|
200 | @sendCommand "show milestones with a due date"
|
201 | @expectCommand('showMilestones', 'all', dueDate: true)
|
202 |
|
203 | it 'specifies due date only v2', ->
|
204 | @sendCommand "show milestones with due dates"
|
205 | @expectCommand('showMilestones', 'all', dueDate: true)
|
206 |
|
207 | describe "hubot show milestones for <repo>", ->
|
208 | it 'works', ->
|
209 | @sendCommand "show milestones for screendoor-v2"
|
210 | @expectCommand('showMilestones', 'screendoor-v2', dueDate: false)
|
211 |
|
212 | it 'specifies due date only', ->
|
213 | @sendCommand "show milestones for screendoor-v2 with a due date"
|
214 | @expectCommand('showMilestones', 'screendoor-v2', dueDate: true)
|
215 |
|
216 | it 'specifies due date only v2', ->
|
217 | @sendCommand "show milestones for screendoor-v2 with due dates"
|
218 | @expectCommand('showMilestones', 'screendoor-v2', dueDate: true)
|