Skip to content

Commit

Permalink
Allow for globally configured intermediatePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Anson Wayman authored and Anson Wayman committed Mar 22, 2017
1 parent ad70c17 commit fe6b095
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class JiraApi {
this.port = options.port || null;
this.apiVersion = options.apiVersion || '2';
this.base = options.base || '';
this.intermediatePath = options.intermediatePath;
this.strictSSL = options.hasOwnProperty('strictSSL') ? options.strictSSL : true;
// This is so we can fake during unit tests
this.request = options.request || request;
Expand Down Expand Up @@ -63,6 +64,8 @@ export default class JiraApi {
* tool is connecting to?
* @property {string} [base] - What other url parts exist, if any, before the rest/api/
* section?
* @property {string} [intermediatePath] - If specified, overwrites the default rest/api/version
* section of the uri
* @property {boolean} [strictSSL=true] - Does this tool require each request to be
* authenticated? Defaults to true.
* @property {function} [request] - What method does this tool use to make its requests?
Expand Down Expand Up @@ -121,7 +124,8 @@ export default class JiraApi {
* @param {object} [options] - an object containing path information
*/
makeUri({ pathname, query, intermediatePath }) {
const tempPath = intermediatePath || `/rest/api/${this.apiVersion}`;
const intermediateToUse = this.intermediatePath || intermediatePath;
const tempPath = intermediateToUse || `/rest/api/${this.apiVersion}`;
const uri = url.format({
protocol: this.protocol,
hostname: this.host,
Expand All @@ -147,7 +151,8 @@ export default class JiraApi {
* @param {object} [options] - An options object specifying uri information
*/
makeWebhookUri({ pathname, intermediatePath }) {
const tempPath = intermediatePath || `/rest/webhooks/${this.webhookVersion}`;
const intermediateToUse = this.intermediatePath || intermediatePath;
const tempPath = intermediateToUse || `/rest/webhooks/${this.webhookVersion}`;
const uri = url.format({
protocol: this.protocol,
hostname: this.host,
Expand All @@ -171,7 +176,8 @@ export default class JiraApi {
* @param {object} [options] - The url after the /rest/
*/
makeSprintQueryUri({ pathname, query, intermediatePath }) {
const tempPath = intermediatePath || `/rest/greenhopper/${this.greenhopperVersion}`;
const intermediateToUse = this.intermediatePath || intermediatePath;
const tempPath = intermediateToUse || `/rest/greenhopper/${this.greenhopperVersion}`;
const uri = url.format({
protocol: this.protocol,
hostname: this.host,
Expand Down
10 changes: 10 additions & 0 deletions test/jira-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function getOptions(options) {
strictSSL: actualOptions.hasOwnProperty('strictSSL') ? actualOptions.strictSSL : true,
request: actualOptions.request,
oauth: actualOptions.oauth || null,
intermediatePath: actualOptions.intermediatePath,
};
}

Expand Down Expand Up @@ -124,6 +125,15 @@ describe('Jira API Tests', () => {
.to.eql('http://jira.somehost.com:8080/intermediatePath/somePathName');
});

it('builds url with globally specified intermediatePath', () => {
const jira = new JiraApi(getOptions({
intermediatePath: 'intermediatePath',
}));

expect(jira.makeUri({ pathname: '/somePathName' }))
.to.eql('http://jira.somehost.com:8080/intermediatePath/somePathName');
});

it('builds url with query string parameters', () => {
const jira = new JiraApi(getOptions());

Expand Down

0 comments on commit fe6b095

Please sign in to comment.