Skip to content

Commit 6a8edac

Browse files
committed
Tests and documenation
1 parent e721fc4 commit 6a8edac

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,54 @@ or
2525
$ cd node-jira
2626
$ npm install
2727

28-
## Example ##
28+
## Examples ##
2929

30-
Find the status of an issue.
30+
### Create the JIRA client ###
3131

3232
JiraApi = require('jira').JiraApi;
33-
33+
3434
var jira = new JiraApi('https', config.host, config.port, config.user, config.password, '2.0.alpha1');
35+
36+
### Find the status of an issue ###
37+
3538
jira.findIssue(issueNumber, function(error, issue) {
3639
console.log('Status: ' + issue.fields.status.name);
3740
});
3841

42+
3943
Currently there is no explicit login call necessary as each API call uses Basic Authentication to authenticate.
4044

45+
### Get an issue remote links ###
46+
47+
Returns an array of remote links data.
48+
49+
jira.getRemoteLinks(issueKey, function(err, links) {
50+
if (!err) {
51+
console.log(issueKey + ' has ' + links.length + ' web links');
52+
}
53+
});
54+
55+
### Create a remote link on an issue ###
56+
57+
Returns an array of remote links data.
58+
59+
// create a web link to a GitHub issue
60+
var linkData = {
61+
"object": {
62+
"url" : "https://github.com/steves/node-jira/issues/1",
63+
"title": "Add getVersions and createVersion functions",
64+
"icon" : {
65+
"url16x16": "https://github.com/favicon.ico"
66+
}
67+
}
68+
};
69+
70+
jira.createRemoteLink(issueKey, linkData, function (err, link) {
71+
72+
});
73+
74+
More information can be found by checking [JIRA Developer documentation](https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+for+Remote+Issue+Links#JIRARESTAPIforRemoteIssueLinks-CreatingLinks).
75+
4176
## Options ##
4277

4378
JiraApi options:
@@ -84,6 +119,9 @@ JiraApi options:
84119
* Add a worklog
85120
* Add new estimate for worklog
86121
* Add a comment
122+
* Remote links (aka Web Links)
123+
* Create a remote link on an issue
124+
* Get all remote links of an issue
87125
* Transitions
88126
* List
89127
* Users

lib/jira.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
603603
/**
604604
* Retrieves the remote links associated with the given issue.
605605
*
606-
* @param issueNumber - The internal id (not the issue key) of the issue
606+
* @param issueNumber - The internal id or key of the issue
607607
* @param callback
608608
*/
609609
this.getRemoteLinks = function getRemoteLinks(issueNumber, callback) {
@@ -623,7 +623,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
623623
}
624624

625625
if (response.statusCode === 404) {
626-
callback('Invalid issue.');
626+
callback('Invalid issue number.');
627627
return;
628628
}
629629

spec/jira.spec.coffee

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,58 @@ describe "Node Jira Tests", ->
626626
# Successful Request
627627
@jira.request.mostRecentCall.args[1] null, statusCode:200, body: issues: ['test']
628628
expect(@cb).toHaveBeenCalledWith null, issues: ['test']
629+
630+
it "Finds the remote links of an issue", ->
631+
options =
632+
rejectUnauthorized: true
633+
uri: makeUrl "issue/1/remotelink"
634+
method: 'GET'
635+
json: true
636+
auth:
637+
user: 'test'
638+
pass: 'test'
639+
@jira.getRemoteLinks 1, @cb
640+
expect(@jira.request)
641+
.toHaveBeenCalledWith(options, jasmine.any(Function))
642+
643+
# Invalid issue number (different than unable to find??)
644+
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
645+
expect(@cb).toHaveBeenCalledWith 'Invalid issue number.'
646+
647+
# Unable to find issue
648+
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
649+
expect(@cb).toHaveBeenCalledWith(
650+
'401: Unable to connect to JIRA during request.')
651+
652+
# Successful Request
653+
@jira.request.mostRecentCall.args[1] null,
654+
statusCode:200, body:"none"
655+
expect(@cb).toHaveBeenCalledWith(null, 'none')
656+
657+
it "Creates a remote link", ->
658+
options =
659+
rejectUnauthorized: true
660+
uri: makeUrl "issue/1/remotelink"
661+
method: 'POST'
662+
json: true
663+
body: 'test'
664+
auth:
665+
user: 'test'
666+
pass: 'test'
667+
668+
@jira.createRemoteLink 1, 'test', @cb
669+
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
670+
671+
# Invalid Issue
672+
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
673+
expect(@cb).toHaveBeenCalledWith 'Cannot create remote link. Invalid issue.'
674+
675+
response =
676+
statusCode:400
677+
body:
678+
errors:
679+
title: 'test'
680+
@jira.request.mostRecentCall.args[1] null, response
681+
expect(@cb).toHaveBeenCalledWith(
682+
'Cannot create remote link. test')
683+

0 commit comments

Comments
 (0)