diff --git a/lib/index.js b/lib/index.js index 7799ceb..56d75a6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -211,6 +211,7 @@ class Client { /** * Incomplete builds + * Ref: https://github.com/harness/drone/blob/v2.11.1/handler/api/builds/builds.go */ incompleteBuilds () { return this._axios.get( @@ -244,6 +245,7 @@ class Client { * @param {string} owner Owner of the repo * @param {string} repo Name of the repo * @param {integer} before Purge before build + * Ref: https://github.com/harness/drone/blob/v2.11.1/handler/api/repos/builds/purge.go */ purgeBuilds (owner, repo, before) { Joi.assert(owner, Joi.string().required(), 'Must specify owner') @@ -280,6 +282,7 @@ class Client { * @param {string} owner Owner of the repo * @param {string} repo Name of the repo * @param {integer} number Number of the build + * Ref: https://github.com/harness/drone/blob/v2.11.1/handler/api/repos/builds/find.go */ getBuild (owner, repo, number) { Joi.assert(owner, Joi.string().required(), 'Must specify owner') @@ -297,6 +300,7 @@ class Client { * @param {string} repo Name of the repo * @param {integer} number Number of the build * @param {RetryBuild} params Build parameters + * Ref: https://github.com/harness/drone/blob/v2.11.1/handler/api/repos/builds/retry.go */ retryBuild (owner, repo, number, params) { Joi.assert(owner, Joi.string().required(), 'Must specify owner') @@ -315,6 +319,7 @@ class Client { * @param {string} owner Owner of the repo * @param {string} repo Name of the repo * @param {integer} number Number of the build + * Ref: https://github.com/harness/drone/blob/v2.11.1/handler/api/repos/builds/cancel.go */ cancelBuild (owner, repo, number) { Joi.assert(owner, Joi.string().required(), 'Must specify owner') @@ -333,6 +338,7 @@ class Client { * @param {integer} number Number of the build * @param {string} target Promote target * @param {object} params Build parameters + * Ref: https://github.com/harness/drone/blob/v2.11.1/handler/api/repos/builds/promote.go */ promoteBuild (owner, repo, number, target, params) { Joi.assert(owner, Joi.string().required(), 'Must specify owner') @@ -343,12 +349,12 @@ class Client { return this._axios.post( `/api/repos/${owner}/${repo}/builds/${number}/promote`, - Querystring.stringify( + new URLSearchParams( Object.assign( { target: target }, params ) - ) + ).toString() ) } diff --git a/test/client.js b/test/client.js index 529ec70..12b50df 100644 --- a/test/client.js +++ b/test/client.js @@ -57,25 +57,6 @@ experiment('getRepos', () => { }) }) -experiment('getBuilds', () => { - beforeEach(() => { - sinon.replace(client._axios, 'get', sinon.fake.returns('fake')) - }) - - itValidatesRepoIdentification('getBuilds') - - it('sends proper params to server', () => { - client.getBuilds('drone', 'drone-node', 2, 42) - - expect( - client._axios.get.lastCall.args - ).to.equal([ - '/api/repos/drone/drone-node/builds', - { params: { page: 2, per_page: 42 } } - ]) - }) -}) - experiment('selfRepos', () => { beforeEach(() => { sinon.replace(client._axios, 'get', sinon.fake.returns('fake')) @@ -240,3 +221,150 @@ experiment('updateRepo', () => { ]) }) }) + +experiment('incompleteBuilds', () => { + beforeEach(() => { + sinon.replace(client._axios, 'get', sinon.fake.returns('fake')) + }) + + it('sends proper params to server', () => { + client.incompleteBuilds() + + expect( + client._axios.get.lastCall.args + ).to.equal([ + '/api/builds/incomplete' + ]) + }) +}) + +experiment('getBuilds', () => { + beforeEach(() => { + sinon.replace(client._axios, 'get', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('getBuilds') + + it('sends proper params to server', () => { + client.getBuilds('drone', 'drone-node', 2, 42) + + expect( + client._axios.get.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds', + { params: { page: 2, per_page: 42 } } + ]) + }) +}) + +experiment('purgeBuilds', () => { + beforeEach(() => { + sinon.replace(client._axios, 'delete', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('purgeBuilds') + + it('sends proper params to server', () => { + client.purgeBuilds('drone', 'drone-node', 42) + + expect( + client._axios.delete.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds', + { params: { before: 42 } } + ]) + }) +}) + +experiment('latestBuild', () => { + beforeEach(() => { + sinon.replace(client._axios, 'get', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('latestBuild') + + it('sends proper params to server', () => { + client.latestBuild('drone', 'drone-node', { ref: 'abc123', branch: 'feature-branch' }) + + expect( + client._axios.get.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds/latest', + { params: { ref: 'abc123', branch: 'feature-branch' } } + ]) + }) +}) + +experiment('getBuild', () => { + beforeEach(() => { + sinon.replace(client._axios, 'get', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('getBuild') + + it('sends proper params to server', () => { + client.getBuild('drone', 'drone-node', 42) + + expect( + client._axios.get.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds/42' + ]) + }) +}) + +experiment('retryBuild', () => { + beforeEach(() => { + sinon.replace(client._axios, 'post', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('retryBuild') + + it('sends proper params to server', () => { + client.retryBuild('drone', 'drone-node', 42, { thing: 'mybuild' }) + + expect( + client._axios.post.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds/42', + 'thing=mybuild' + ]) + }) +}) + +experiment('cancelBuild', () => { + beforeEach(() => { + sinon.replace(client._axios, 'delete', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('cancelBuild') + + it('sends proper params to server', () => { + client.cancelBuild('drone', 'drone-node', 42) + + expect( + client._axios.delete.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds/42' + ]) + }) +}) + +experiment('promoteBuild', () => { + beforeEach(() => { + sinon.replace(client._axios, 'post', sinon.fake.returns('fake')) + }) + + itValidatesRepoIdentification('promoteBuild') + + it('sends proper params to server', () => { + client.promoteBuild('drone', 'drone-node', 42, 'production', { owner: 'octocat' }) + + expect( + client._axios.post.lastCall.args + ).to.equal([ + '/api/repos/drone/drone-node/builds/42/promote', + 'target=production&owner=octocat' + ]) + }) +})