-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: update test code * feat: add autoLabel test case
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters