1
1
url = require ' url'
2
2
3
- nodeJira = require ' ../lib/jira'
3
+ rewire = require ' rewire'
4
+ nodeJira = rewire ' ../lib/jira'
4
5
5
6
describe " Node Jira Tests" , ->
6
7
makeUrl = (path , altBase ) ->
@@ -15,10 +16,38 @@ describe "Node Jira Tests", ->
15
16
16
17
17
18
beforeEach ->
19
+ OAuth = nodeJira .__get__ " OAuth"
20
+ OAuth .OAuth .prototype = jasmine .createSpyObj ' OAuth' , [' getOAuthRequestToken' , ' _encodeData' ]
21
+ nodeJira .__set__ " OAuth" , OAuth
22
+
18
23
@jira = new nodeJira.JiraApi ' http' , ' localhost' , 80 , ' test' , ' test' , 2
19
24
spyOn @jira , ' request'
20
25
@cb = jasmine .createSpy ' callback'
21
26
27
+ it " Sets basic auth if oauth is not passed in" , ->
28
+ options =
29
+ auth =
30
+ user : ' test'
31
+ pass : ' test'
32
+ @jira .doRequest options, @cb
33
+ expect (@jira .request )
34
+ .toHaveBeenCalledWith (options, jasmine .any (Function ))
35
+
36
+ it " Sets OAuth oauth for the requests if oauth is passed in" , ->
37
+ options =
38
+ oauth =
39
+ consumer_key : ' ck'
40
+ consumer_secret : ' cs'
41
+ access_token : ' ac'
42
+ access_token_secret : ' acs'
43
+ # oauth = new OAuth.OAuth(null, null, oauth.consumer_key, oauth.consumer_secret, null, null, "RSA-SHA1")
44
+ @jira = new nodeJira.JiraApi ' http' , ' localhost' , 80 , ' test' , ' test' , 2 , false , false , options .oauth
45
+ spyOn @jira , ' request'
46
+
47
+ @jira .doRequest options, @cb
48
+ expect (@jira .request )
49
+ .toHaveBeenCalledWith (options, jasmine .any (Function ))
50
+
22
51
it " Sets strictSSL to false when passed in" , ->
23
52
expected = false
24
53
jira = new nodeJira.JiraApi ' http' , ' localhost' , 80 , ' test' , ' test' , 2 , false , expected
@@ -529,6 +558,35 @@ describe "Node Jira Tests", ->
529
558
@jira .request .mostRecentCall .args [1 ] null , statusCode : 201
530
559
expect (@cb ).toHaveBeenCalledWith null , " Success"
531
560
561
+ it " Adds a worklog to a project with remaining time set" , ->
562
+ options =
563
+ rejectUnauthorized : true
564
+ uri : makeUrl " issue/1/worklog?adjustEstimate=new&newEstimate=1h"
565
+ body : ' aWorklog'
566
+ method : ' POST'
567
+ followAllRedirects : true
568
+ json : true
569
+ auth :
570
+ user : ' test'
571
+ pass : ' test'
572
+
573
+ @jira .addWorklog 1 , ' aWorklog' , ' 1h' , @cb
574
+ expect (@jira .request ).toHaveBeenCalledWith options, jasmine .any (Function )
575
+
576
+ @jira .request .mostRecentCall .args [1 ] null , statusCode : 400 ,
577
+ ' {"body:"none"}'
578
+ expect (@cb ).toHaveBeenCalledWith ' Invalid Fields: "{\\ "body:\\ "none\\ "}"'
579
+
580
+ @jira .request .mostRecentCall .args [1 ] null , statusCode : 403
581
+ expect (@cb ).toHaveBeenCalledWith ' Insufficient Permissions'
582
+
583
+ @jira .request .mostRecentCall .args [1 ] null , statusCode : 401
584
+ expect (@cb ).toHaveBeenCalledWith ' 401: Error while updating'
585
+
586
+ # Successful Request
587
+ @jira .request .mostRecentCall .args [1 ] null , statusCode : 201
588
+ expect (@cb ).toHaveBeenCalledWith null , " Success"
589
+
532
590
it " Lists Issue Types" , ->
533
591
options =
534
592
rejectUnauthorized : true
0 commit comments