mirror of
https://github.com/xuexb/github-bot.git
synced 2026-01-18 13:56:38 +00:00
test: add a test case (#47)
* test: update test code * feat: add autoLabel test case
This commit is contained in:
parent
9ff0a52c34
commit
4da5f41e4d
69
test/modules/issues/autoLabel.js
Normal file
69
test/modules/issues/autoLabel.js
Normal 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)
|
||||
})
|
||||
})
|
||||
@ -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'])
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user