diff --git a/test/modules/issues/autoLabel.js b/test/modules/issues/autoLabel.js new file mode 100644 index 0000000..b292689 --- /dev/null +++ b/test/modules/issues/autoLabel.js @@ -0,0 +1,69 @@ +/** + * @file modules/issues/autoLabel.js test case + * @author xuexb + */ + +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测试' + } + } + }) + }) + }) + + 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) + }) +}) diff --git a/test/utils.js b/test/utils.js index d0afd79..226bb3f 100644 --- a/test/utils.js +++ b/test/utils.js @@ -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']) }) })