test: add a test case (#47)

* test: update test code

* feat: add autoLabel test case
This commit is contained in:
前端小武 2018-01-19 17:34:32 +08:00 committed by Yuga Sun
parent 9ff0a52c34
commit 4da5f41e4d
2 changed files with 70 additions and 0 deletions

View File

@ -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)
})
})

View File

@ -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'])
})
})