|
| 1 | +/** |
| 2 | + * @file modules/issues/autoLabel.js test case |
| 3 | + * @author xuexb <[email protected]> |
| 4 | + */ |
| 5 | + |
| 6 | +const expect = require('chai').expect |
| 7 | +const mock = require('mock-require') |
| 8 | +mock.stopAll() |
| 9 | +const clean = require('../../utils/clean') |
| 10 | + |
| 11 | +describe('modules/issues/autoLabel.js', () => { |
| 12 | + beforeEach('clear node cache', () => { |
| 13 | + clean('src/github') |
| 14 | + clean('src/modules/issues/autoLabel') |
| 15 | + |
| 16 | + mock('../../../src/github', { |
| 17 | + addLabelsToIssue() { |
| 18 | + } |
| 19 | + }) |
| 20 | + }) |
| 21 | + |
| 22 | + it('event name', () => { |
| 23 | + const autoLabel = require('../../../src/modules/issues/autoLabel') |
| 24 | + autoLabel(name => { |
| 25 | + expect(name).to.equal('issues_opened') |
| 26 | + }) |
| 27 | + }) |
| 28 | + |
| 29 | + it('get label success', (done) => { |
| 30 | + mock('../../../src/github', { |
| 31 | + addLabelsToIssue(payload, label) { |
| 32 | + expect(payload).to.be.a('object').and.not.empty |
| 33 | + expect(label).to.equal('github-bot') |
| 34 | + done() |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + const autoLabel = require('../../../src/modules/issues/autoLabel') |
| 39 | + autoLabel((name, callback) => { |
| 40 | + callback({ |
| 41 | + payload: { |
| 42 | + issue: { |
| 43 | + body: '我是测试内容\n<!--label:github-bot--><!--label:bot-->测试' |
| 44 | + } |
| 45 | + } |
| 46 | + }) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + it('get label error', (done) => { |
| 51 | + mock('../../../src/github', { |
| 52 | + addLabelsToIssue() { |
| 53 | + done('error') |
| 54 | + } |
| 55 | + }) |
| 56 | + |
| 57 | + const autoLabel = require('../../../src/modules/issues/autoLabel') |
| 58 | + autoLabel((name, callback) => { |
| 59 | + callback({ |
| 60 | + payload: { |
| 61 | + issue: { |
| 62 | + body: '我是测试内容' |
| 63 | + } |
| 64 | + } |
| 65 | + }) |
| 66 | + }) |
| 67 | + setTimeout(done) |
| 68 | + }) |
| 69 | +}) |
0 commit comments