Repository: jira-node/node-jira-client
Pull request #275 (2020-02-25 13:27:18)

Add getUser and getUsers functions


Patch:
diff --git a/package.json b/package.json
index 338d446..250a97e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "jira-client",
-  "version": "6.14.0",
+  "version": "6.13.0",
   "description": "Wrapper for the JIRA API",
   "author": "Steven Surowiec <steven.surowiec@gmail.com>",
   "contributors": [
diff --git a/src/jira.js b/src/jira.js
index 49a7e9d..d5cd620 100644
--- a/src/jira.js
+++ b/src/jira.js
@@ -524,7 +524,7 @@ export default class JiraApi {
    * [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id288232)
    * @name createVersion
    * @function
-   * @param {object} version - an object of the new version
+   * @param {string} version - an object of the new version
    */
   createVersion(version) {
     return this.doRequest(this.makeRequestHeader(this.makeUri({
@@ -705,6 +705,40 @@ export default class JiraApi {
     );
   }
 
+  /** Returns a user.
+   * [Jira Doc](https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-user-get)
+   * @name getUser
+   * @function
+   * @param {string} accountId - The accountId of user to search for
+   * @param {string} expand - The expand for additional info (groups,applicationRoles)
+   */
+  getUser(accountId, expand) {
+    return this.doRequest(this.makeRequestHeader(this.makeUri({
+      pathname: '/user',
+      query: {
+        accountId,
+        expand,
+      },
+    })));
+  }
+
+  /** Returns a list of all (active and inactive) users.
+   * [Jira Doc](https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-users-search-get)
+   * @name getUsers
+   * @function
+   * @param {integer} [startAt=0] - The index of the first user to return (0-based)
+   * @param {integer} [maxResults=50] - The maximum number of users to return (defaults to 50).
+   */
+  getUsers(startAt = 0, maxResults = 100) {
+    return this.doRequest(this.makeRequestHeader(this.makeUri({
+      pathname: '/users',
+      query: {
+        startAt,
+        maxResults,
+      },
+    })));
+  }
+
   /** Add issue to Jira
    * [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290028)
    * @name addNewIssue
@@ -773,7 +807,7 @@ export default class JiraApi {
    * [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290878)
    * @name updateIssue
    * @function
-   * @param {string} issueId - the Id of the issue to update
+   * @param {string} issueId - the Id of the issue to delete
    * @param {object} issueUpdate - update Object as specified by the rest api
    * @param {object} query - adds parameters to the query string
    */


Test patch:
diff --git a/test/jira-tests.js b/test/jira-tests.js
index b151fbe..240c930 100644
--- a/test/jira-tests.js
+++ b/test/jira-tests.js
@@ -552,6 +552,16 @@ describe('Jira API Tests', () => {
       result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/search');
     });
 
+    it('getUser hits proper url', async () => {
+      const result = await dummyURLCall('getUser', ['some-account-Id', 'groups,applicationRoles']);
+      result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/user?accountId=some-account-Id&expand=groups,applicationRoles');
+    });
+
+    it('getUsers hits proper url', async () => {
+      const result = await dummyURLCall('getUsers', [0, 50]);
+      result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/users?startAt=0&maxResults=50');
+    });
+
     it('addNewIssue hits proper url', async () => {
       const result = await dummyURLCall('addNewIssue', ['someIssue']);
       result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue');