Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage to builds #38

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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()
)
}

Expand Down
166 changes: 147 additions & 19 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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'
])
})
})