jira.spec.coffee
21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
url = require 'url'
rewire = require 'rewire'
nodeJira = rewire '../lib/jira'
describe "Node Jira Tests", ->
makeUrl = (path, altBase) ->
base = 'rest/api/2/'
base = 'rest/greenhopper/2/' if altBase?
decodeURIComponent(
url.format
protocol: 'http:'
hostname: 'localhost'
port: 80
pathname: "#{base}#{path}")
beforeEach ->
OAuth = nodeJira.__get__ "OAuth"
OAuth.OAuth.prototype = jasmine.createSpyObj 'OAuth', ['getOAuthRequestToken', '_encodeData']
nodeJira.__set__ "OAuth", OAuth
@jira = new nodeJira.JiraApi 'http', 'localhost', 80, 'test', 'test', 2
spyOn @jira, 'request'
@cb = jasmine.createSpy 'callback'
it "Sets basic auth if oauth is not passed in", ->
options =
auth =
user: 'test'
pass: 'test'
@jira.doRequest options, @cb
expect(@jira.request)
.toHaveBeenCalledWith(options, jasmine.any(Function))
it "Sets OAuth oauth for the requests if oauth is passed in", ->
options =
oauth =
consumer_key: 'ck'
consumer_secret: 'cs'
access_token: 'ac'
access_token_secret: 'acs'
# oauth = new OAuth.OAuth(null, null, oauth.consumer_key, oauth.consumer_secret, null, null, "RSA-SHA1")
@jira = new nodeJira.JiraApi 'http', 'localhost', 80, 'test', 'test', 2, false, false, options.oauth
spyOn @jira, 'request'
@jira.doRequest options, @cb
expect(@jira.request)
.toHaveBeenCalledWith(options, jasmine.any(Function))
it "Sets strictSSL to false when passed in", ->
expected = false
jira = new nodeJira.JiraApi 'http', 'localhost', 80, 'test', 'test', 2, false, expected
expect(jira.strictSSL).toEqual(expected)
it "Sets strictSSL to true when passed in", ->
expected = true
jira = new nodeJira.JiraApi 'http', 'localhost', 80, 'test', 'test', 2, false, expected
expect(jira.strictSSL).toEqual(expected)
it "Sets strictSSL to true when not passed in", ->
expected = true
expect(@jira.strictSSL).toEqual(expected)
it "Finds an issue", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1"
method: 'GET'
auth:
user: 'test'
pass: 'test'
@jira.findIssue 1, @cb
expect(@jira.request)
.toHaveBeenCalledWith(options, jasmine.any(Function))
# Invalid issue number (different than unable to find??)
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid issue number.'
# Unable to find issue
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during findIssueStatus.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200, '{"body":"none"}'
expect(@cb).toHaveBeenCalledWith(null, body: 'none')
it "Gets the unresolved issue count", ->
options =
rejectUnauthorized: true
uri: makeUrl "version/1/unresolvedIssueCount"
method: 'GET'
auth:
user: 'test'
pass: 'test'
@jira.getUnresolvedIssueCount 1, @cb
expect(@jira.request)
.toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid Version
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid version.'
# Unable to connect
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during findIssueStatus.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200, '{"issuesUnresolvedCount":1}'
expect(@cb).toHaveBeenCalledWith null, 1
it "Gets the project from a key", ->
options =
rejectUnauthorized: true
uri: makeUrl "project/ABC"
method: 'GET'
auth:
user: 'test'
pass: 'test'
@jira.getProject 'ABC', @cb
expect(@jira.request)
.toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid Version
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid project.'
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200, '{"body":"none"}'
expect(@cb).toHaveBeenCalledWith null, body:"none"
it "Finds a Rapid View", ->
options =
rejectUnauthorized: true
uri: makeUrl("rapidviews/list", true)
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.findRapidView 'ABC', @cb
expect(@jira.request)
.toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid URL
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during rapidView search.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200,
body:
views: [name: 'ABC']
expect(@cb).toHaveBeenCalledWith null, name: 'ABC'
it "Gets the last sprint for a Rapid View", ->
options =
rejectUnauthorized: true
uri: makeUrl("sprintquery/1", true)
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.getLastSprintForRapidView 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid URL
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during sprints search.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200,
body:
sprints: [name: 'ABC']
expect(@cb).toHaveBeenCalledWith null, name: 'ABC'
it "Adds an issue to a sprint", ->
options =
rejectUnauthorized: true
uri: makeUrl("sprint/1/issues/add", true)
method: 'PUT'
json: true
followAllRedirects: true
body:
issueKeys: [2]
auth:
user: 'test'
pass: 'test'
@jira.addIssueToSprint 2, 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid URL
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA to add to sprint.')
it "Creates a Link Between two Issues", ->
options =
rejectUnauthorized: true
uri: makeUrl "issueLink"
method: 'POST'
json: true
body: 'test'
followAllRedirects: true
auth:
user: 'test'
pass: 'test'
@jira.issueLink 'test', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid Project
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid project.'
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during issueLink.')
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:200
expect(@cb).toHaveBeenCalledWith null
it "Gets versions for a project", ->
options =
rejectUnauthorized: true
uri: makeUrl "project/ABC/versions"
method: 'GET'
auth:
user: 'test'
pass: 'test'
@jira.getVersions 'ABC', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid Project
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid project.'
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during getVersions.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200, '{"body":"none"}'
expect(@cb).toHaveBeenCalledWith null, body:'none'
it "Creates a version for a project", ->
options =
rejectUnauthorized: true
uri: makeUrl "version"
method: 'POST'
json: true
body: 'ABC'
followAllRedirects: true
auth:
user: 'test'
pass: 'test'
@jira.createVersion 'ABC', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid Project
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Version does not exist or the
currently authenticated user does not have permission to view it'
@jira.request.mostRecentCall.args[1] null, statusCode:403, null
expect(@cb).toHaveBeenCalledWith(
'The currently authenticated user does not have
permission to edit the version')
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during createVersion.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:201, '{"body":"none"}'
expect(@cb).toHaveBeenCalledWith null, '{"body":"none"}'
it "Passes a search query to Jira, default options", ->
fields = ["summary", "status", "assignee", "description"]
options =
rejectUnauthorized: true
uri: makeUrl "search"
method: 'POST'
json: true
followAllRedirects: true
body:
jql: 'aJQLstring'
startAt: 0
maxResults: 50
fields: fields
auth:
user: 'test'
pass: 'test'
@jira.searchJira 'aJQLstring', {}, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid Project
@jira.request.mostRecentCall.args[1] null, statusCode:400, null
expect(@cb).toHaveBeenCalledWith 'Problem with the JQL query'
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during search.')
# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200, '{"body":"none"}'
expect(@cb).toHaveBeenCalledWith null, '{"body":"none"}'
it "Passes a search query to Jira, non-default options", ->
fields = ["assignee", "description", "test"]
options =
rejectUnauthorized: true
uri: makeUrl "search"
method: 'POST'
json: true
followAllRedirects: true
body:
jql: 'aJQLstring'
startAt: 200
maxResults: 100
fields: fields
auth:
user: 'test'
pass: 'test'
@jira.searchJira 'aJQLstring', { maxResults: 100, fields: fields, startAt: 200 }, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
it "Gets a specified User's OPEN Issues", ->
spyOn @jira, 'searchJira'
expected = "assignee = test AND status in (Open, \"In Progress\",
Reopened)"
@jira.getUsersIssues 'test', true, @cb
expect(@jira.searchJira).toHaveBeenCalledWith expected, {},
jasmine.any(Function)
it "Properly Escapes @'s in Usernames", ->
spyOn @jira, 'searchJira'
expected = "assignee = email\\u0040example.com AND status in (Open, \"In Progress\",
Reopened)"
@jira.getUsersIssues 'email@example.com', true, @cb
expect(@jira.searchJira).toHaveBeenCalledWith expected, {},
jasmine.any(Function)
it "Gets the sprint issues and information", ->
options =
rejectUnauthorized: true
uri: makeUrl("rapid/charts/sprintreport?rapidViewId=1&sprintId=1", true)
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.getSprintIssues 1, 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'
it "Gets ALL a specified User's Issues", ->
spyOn @jira, 'searchJira'
expected = "assignee = test"
@jira.getUsersIssues 'test', false, @cb
expect(@jira.searchJira).toHaveBeenCalledWith expected, {},
jasmine.any(Function)
it "Deletes an Issue", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1"
method: 'DELETE'
json: true
followAllRedirects: true
auth:
user: 'test'
pass: 'test'
@jira.deleteIssue 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith '401: Error while deleting'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:204
expect(@cb).toHaveBeenCalledWith null, 'Success'
it "Updates an Issue", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1"
body: 'updateGoesHere'
method: 'PUT'
json: true
followAllRedirects: true
auth:
user: 'test'
pass: 'test'
@jira.updateIssue 1, 'updateGoesHere', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while updating'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:200
expect(@cb).toHaveBeenCalledWith null, 'Success'
it "Lists Transitions", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1/transitions?expand=transitions.fields"
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.listTransitions 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Issue not found'
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while updating'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:200,
transitions:"someTransitions"
expect(@cb).toHaveBeenCalledWith null, {transitions:"someTransitions"}
it "Transitions an issue", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1/transitions"
body: 'someTransition'
method: 'POST'
followAllRedirects: true
json: true
auth:
user: 'test'
pass: 'test'
@jira.transitionIssue 1, 'someTransition', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while updating'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:204
expect(@cb).toHaveBeenCalledWith null, "Success"
it "Lists Projects", ->
options =
rejectUnauthorized: true
uri: makeUrl "project"
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.listProjects @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while updating'
@jira.request.mostRecentCall.args[1] null, statusCode:500
expect(@cb).toHaveBeenCalledWith '500: Error while retrieving list.'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:200, "body"
expect(@cb).toHaveBeenCalledWith null, "body"
it "Adds a comment to an issue", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1/comment"
body: {
'body': 'aComment'
}
method: 'POST'
followAllRedirects: true
json: true
auth:
user: 'test'
pass: 'test'
@jira.addComment 1, 'aComment', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:400,
'{"body:"none"}'
expect(@cb).toHaveBeenCalledWith 'Invalid Fields: "{\\"body:\\"none\\"}"'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:201
expect(@cb).toHaveBeenCalledWith null, "Success"
it "Adds a worklog to a project", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1/worklog"
body: 'aWorklog'
method: 'POST'
followAllRedirects: true
json: true
auth:
user: 'test'
pass: 'test'
@jira.addWorklog 1, 'aWorklog', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:400,
'{"body:"none"}'
expect(@cb).toHaveBeenCalledWith 'Invalid Fields: "{\\"body:\\"none\\"}"'
@jira.request.mostRecentCall.args[1] null, statusCode:403
expect(@cb).toHaveBeenCalledWith 'Insufficient Permissions'
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while updating'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:201
expect(@cb).toHaveBeenCalledWith null, "Success"
it "Adds a worklog to a project with remaining time set", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1/worklog?adjustEstimate=new&newEstimate=1h"
body: 'aWorklog'
method: 'POST'
followAllRedirects: true
json: true
auth:
user: 'test'
pass: 'test'
@jira.addWorklog 1, 'aWorklog', '1h', @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:400,
'{"body:"none"}'
expect(@cb).toHaveBeenCalledWith 'Invalid Fields: "{\\"body:\\"none\\"}"'
@jira.request.mostRecentCall.args[1] null, statusCode:403
expect(@cb).toHaveBeenCalledWith 'Insufficient Permissions'
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while updating'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:201
expect(@cb).toHaveBeenCalledWith null, "Success"
it "Lists Issue Types", ->
options =
rejectUnauthorized: true
uri: makeUrl "issuetype"
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.listIssueTypes @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:401
expect(@cb).toHaveBeenCalledWith '401: Error while retrieving issue types'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:200, "body"
expect(@cb).toHaveBeenCalledWith null, "body"
it "Retrieves a Rapid View Backlog", ->
options =
rejectUnauthorized: true
uri: makeUrl("xboard/plan/backlog/data?rapidViewId=123", true)
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'
@jira.getBacklogForRapidView 123, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
@jira.request.mostRecentCall.args[1] null, statusCode:500
expect(@cb).toHaveBeenCalledWith '500: Error while retrieving backlog'
# Successful Request
@jira.request.mostRecentCall.args[1] null, statusCode:200, body: issues: ['test']
expect(@cb).toHaveBeenCalledWith null, issues: ['test']