Repository: jira-node/node-jira-client
Pull request #19 (2016-01-24 14:51:55)

Changed makeUri to account for query string parameters
__NOTE__: This is a small breaking change to the existing API

/cc @KanoYugoro 


Patch:
diff --git a/src/jira.js b/src/jira.js
index 26b1be9..7211786 100644
--- a/src/jira.js
+++ b/src/jira.js
@@ -69,30 +69,40 @@ export default class JiraApi {
    * @function
    * Creates a requestOptions object based on the default template for one
    * @param {string} uri
-   * @param {object} otherOptions - an object containing fields and formatting how the
+   * @param {object} [options] - an object containing fields and formatting how the
    */
-  makeRequestHeader(uri, otherOptions = {}) {
+  makeRequestHeader(pathname, options = {}) {
     return {
       rejectUnauthorized: this.strictSSL,
-      uri: this.makeUri(uri),
-      method: otherOptions.method || 'GET',
+      uri: this.makeUri({
+        pathname,
+        query: options.query
+      }),
+      method: options.method || 'GET',
       json: true,
-      ...otherOptions
+      ...options
     };
   }
 
+  /**
+   * @typedef makeRequestHeaderOptions
+   * @type {object}
+   * @property {string} [method] - HTTP Request Method. ie GET, POST, PUT, DELETE
+   */
+
   /**
    * @name makeUri
    * @function
    * Creates a URI object for a given pathName
    * @param {string} pathName - The url after the /rest/api/version
    */
-  makeUri(pathName) {
+  makeUri({ pathname, query }) {
     const uri = url.format({
       protocol: this.protocol,
       hostname: this.host,
       port: this.port,
-      pathname: `${this.base}/rest/api/${this.apiVersion}${pathName}`
+      pathname: `${this.base}/rest/api/${this.apiVersion}${pathname}`,
+      query
     });
     return decodeURIComponent(uri);
   }
@@ -339,16 +349,20 @@ export default class JiraApi {
   /** Get all users in group on Jira
    * @name getUsersInGroup
    * @function
-   * @param {string} groupName - A query string used to search users in group
+   * @param {string} groupname - A query string used to search users in group
    * @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).
    */
-  getUsersInGroup(groupName, startAt = 0, maxResults = 50) {
+  getUsersInGroup(groupname, startAt = 0, maxResults = 50) {
     return this.doRequest(
-      this.makeRequestHeader(
-        `/group?groupname=${groupName}&expand=users[${startAt}:${maxResults}]`, {
-          followAllRedirects: true
-        }));
+      this.makeRequestHeader('/group', {
+        query: {
+          groupname,
+          expand: `users[${startAt}:${maxResults}]`
+        },
+        followAllRedirects: true
+      })
+    );
   }
 
   /** Get issues related to a user


Test patch:
diff --git a/test/jira-tests.js b/test/jira-tests.js
index b739fe4..e05bb8e 100644
--- a/test/jira-tests.js
+++ b/test/jira-tests.js
@@ -74,13 +74,30 @@ describe('Jira API Tests', () => {
     });
   });
 
-  describe('makeUri Tests', () => {
-    it('makeUri functions properly in the average case', () => {
+  describe('makeUri', () => {
+    it('builds url with pathname and default host, protocol, port, and base api', () => {
       const jira = new JiraApi(getOptions());
 
-      expect(jira.makeUri('/somePathName'))
+      expect(jira.makeUri({ pathname: '/somePathName' }))
         .to.eql('http://jira.somehost.com:8080/rest/api/2.0/somePathName');
     });
+
+    it('builds url with query string parameters', () => {
+      const jira = new JiraApi(getOptions());
+
+      const url = jira.makeUri({
+        pathname: '/path',
+        query: {
+          fields: [
+            'one',
+            'two'
+          ],
+          expand: 'three'
+        }
+      });
+
+      url.should.eql('http://jira.somehost.com:8080/rest/api/2.0/path?fields=one&fields=two&expand=three');
+    });
   });
 
   describe('doRequest Tests', () => {