From 0a03545fc387e89787589a3c20aedce9f6ea2fd0 Mon Sep 17 00:00:00 2001 From: Dao Lam Date: Thu, 20 Oct 2016 17:07:16 -0700 Subject: [PATCH] Add json:true option for request --- index.js | 21 ++++++++++++++------- test/index.test.js | 36 ++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index b57029f..ae867ff 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,8 @@ class BitbucketScm extends Scm { `/refs/branches/${repoInfo.branch}?access_key=${config.token}`; const options = { url: branchUrl, - method: 'GET' + method: 'GET', + json: true }; return this.breaker.runCommand(options) @@ -164,7 +165,8 @@ class BitbucketScm extends Scm { _decorateAuthor(config) { const options = { url: `${USER_URL}/${config.username}?access_key=${config.token}`, - method: 'GET' + method: 'GET', + json: true }; return this.breaker.runCommand(options) @@ -198,7 +200,8 @@ class BitbucketScm extends Scm { const scm = getScmUriParts(config.scmUri); const options = { url: `${REPO_URL}/${scm.repoId}?access_key=${config.token}`, - method: 'GET' + method: 'GET', + json: true }; return this.breaker.runCommand(options) @@ -230,7 +233,8 @@ class BitbucketScm extends Scm { const scm = getScmUriParts(config.scmUri); const options = { url: `${REPO_URL}/${scm.repoId}/commit/${config.sha}?access_key=${config.token}`, - method: 'GET' + method: 'GET', + json: true }; return this.breaker.runCommand(options) @@ -267,7 +271,8 @@ class BitbucketScm extends Scm { `${REPO_URL}/${scm.repoId}/refs/branches/${scm.branch}?access_key=${config.token}`; const options = { url: branchUrl, - method: 'GET' + method: 'GET', + json: true }; return this.breaker.runCommand(options) @@ -298,7 +303,8 @@ class BitbucketScm extends Scm { const fileUrl = `${urlRoot}/${urlSuffix}?${urlParameters}`; const options = { url: fileUrl, - method: 'GET' + method: 'GET', + json: true }; return this.breaker.runCommand(options) @@ -325,7 +331,8 @@ class BitbucketScm extends Scm { const [owner, uuid] = repoId.split('/'); const options = { url: `${API_URL_V2}/repositories/${owner}`, - method: 'GET' + method: 'GET', + json: true }; if (desiredAccess === 'admin') { diff --git a/test/index.test.js b/test/index.test.js index a1cd6a8..01505b7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -69,7 +69,8 @@ describe('index', () => { }; expectedOptions = { url: `${apiUrl}/mynewbranch?access_key=myAccessToken`, - method: 'GET' + method: 'GET', + json: true }; requestMock.yieldsAsync(null, fakeResponse, fakeResponse.body); }); @@ -80,7 +81,8 @@ describe('index', () => { expectedOptions = { url: `${apiUrl}/master?access_key=myAccessToken`, - method: 'GET' + method: 'GET', + json: true }; return scm.parseUrl({ @@ -246,7 +248,8 @@ describe('index', () => { const apiUrl = `${API_URL_V2}/users/batman?access_key=${token}`; const expectedOptions = { url: apiUrl, - method: 'GET' + method: 'GET', + json: true }; let fakeResponse; @@ -333,7 +336,8 @@ describe('index', () => { const selfLink = 'https://bitbucket.org/d2lam2/test'; const repoOptions = { url: apiUrl, - method: 'GET' + method: 'GET', + json: true }; let fakeResponse; let expectedOptions; @@ -352,7 +356,8 @@ describe('index', () => { }; expectedOptions = { url: apiUrl, - method: 'GET' + method: 'GET', + json: true }; requestMock.withArgs(repoOptions) .yieldsAsync(null, fakeResponse, fakeResponse.body); @@ -422,11 +427,13 @@ describe('index', () => { const selfLink = 'https://bitbucket.org/batman/test/commits/40171b678527'; const repoOptions = { url: repoUrl, - method: 'GET' + method: 'GET', + json: true }; const authorOptions = { url: authorUrl, - method: 'GET' + method: 'GET', + json: true }; let fakeResponse; let fakeAuthorResponse; @@ -541,7 +548,8 @@ describe('index', () => { const scmUri = 'bitbucket.org:batman/{1234}:mybranch'; const expectedOptions = { url: apiUrl, - method: 'GET' + method: 'GET', + json: true }; let fakeResponse; @@ -620,7 +628,8 @@ describe('index', () => { }; const expectedOptions = { url: apiUrl, - method: 'GET' + method: 'GET', + json: true }; let fakeResponse; @@ -682,15 +691,18 @@ describe('index', () => { describe('getPermissions', () => { const pull = { url: `${API_URL_V2}/repositories/batman?access_key=${token}`, - method: 'GET' + method: 'GET', + json: true }; const push = { url: `${API_URL_V2}/repositories/batman?role=contributor&access_key=${token}`, - method: 'GET' + method: 'GET', + json: true }; const admin = { url: `${API_URL_V2}/repositories/batman?role=admin&access_key=${token}`, - method: 'GET' + method: 'GET', + json: true }; const readResponse = { statusCode: 200,