Skip to content

Commit

Permalink
test: add a test case (#47)
Browse files Browse the repository at this point in the history
* test: update test code

* feat: add autoLabel test case
  • Loading branch information
xuexb authored and yugasun committed Jan 19, 2018
1 parent 9ff0a52 commit 4da5f41
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/modules/issues/autoLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @file modules/issues/autoLabel.js test case
* @author xuexb <fe.xiaowu@gmail.com>
*/

const expect = require('chai').expect
const mock = require('mock-require')
mock.stopAll()
const clean = require('../../utils/clean')

describe('modules/issues/autoLabel.js', () => {
beforeEach('clear node cache', () => {
clean('src/github')
clean('src/modules/issues/autoLabel')

mock('../../../src/github', {
addLabelsToIssue() {
}
})
})

it('event name', () => {
const autoLabel = require('../../../src/modules/issues/autoLabel')
autoLabel(name => {
expect(name).to.equal('issues_opened')
})
})

it('get label success', (done) => {
mock('../../../src/github', {
addLabelsToIssue(payload, label) {
expect(payload).to.be.a('object').and.not.empty
expect(label).to.equal('github-bot')
done()
}
})

const autoLabel = require('../../../src/modules/issues/autoLabel')
autoLabel((name, callback) => {
callback({
payload: {
issue: {
body: '我是测试内容\n<!--label:github-bot--><!--label:bot-->测试'
}
}
})
})
})

it('get label error', (done) => {
mock('../../../src/github', {
addLabelsToIssue() {
done('error')
}
})

const autoLabel = require('../../../src/modules/issues/autoLabel')
autoLabel((name, callback) => {
callback({
payload: {
issue: {
body: '我是测试内容'
}
}
})
})
setTimeout(done)
})
})
1 change: 1 addition & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('utils.js', () => {
expect(utils.toArray(null)).to.be.null
})
it('should return array if not the empty string', () => {
expect(utils.toArray(['string'])).to.be.a('array').and.to.deep.equal(['string'])
expect(utils.toArray('string')).to.be.a('array').and.to.deep.equal(['string'])
})
})
Expand Down

0 comments on commit 4da5f41

Please sign in to comment.