Skip to content

Commit 4da5f41

Browse files
xuexbyugasun
authored andcommitted
test: add a test case (#47)
* test: update test code * feat: add autoLabel test case
1 parent 9ff0a52 commit 4da5f41

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

test/modules/issues/autoLabel.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
})

test/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('utils.js', () => {
1414
expect(utils.toArray(null)).to.be.null
1515
})
1616
it('should return array if not the empty string', () => {
17+
expect(utils.toArray(['string'])).to.be.a('array').and.to.deep.equal(['string'])
1718
expect(utils.toArray('string')).to.be.a('array').and.to.deep.equal(['string'])
1819
})
1920
})

0 commit comments

Comments
 (0)