github-bot/test/utils.js
前端小武 9ff0a52c34 feat: add test cases (#46)
* feat: add test command

* feat: add a test case

* feat: add coverage report

* docs: add coverage badge

* fix: 优化代码

* test: 添加单元测试

* test: 修复测试用命代码格式

* fix: eslint errors

* fix: disable camelcase

* fix: disable camelcase for src/github.js
2018-01-15 11:14:04 +08:00

48 lines
1.3 KiB
JavaScript

/**
* @file utils.js test case
* @author xuexb <fe.xiaowu@gmail.com>
*/
require('mock-require').stopAll()
const utils = require('../src/utils')
const expect = require('chai').expect
describe('utils.js', () => {
describe('.toArray', () => {
it('should return self if empty', () => {
expect(utils.toArray()).to.be.undefined
expect(utils.toArray('')).to.equal('')
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'])
})
})
describe('.getPkgConfig', () => {
it('should return object', () => {
expect(utils.getPkgConfig()).to.be.a('object').and.to.not.empty
})
})
describe('.getPkgCommitPrefix', () => {
it('should return array', () => {
expect(utils.getPkgCommitPrefix()).to.be.a('array').and.to.not.empty
})
})
it('.verifySignature', () => {
const GITHUB_SECRET_TOKEN = process.env['GITHUB_SECRET_TOKEN']
process.env['GITHUB_SECRET_TOKEN'] = 'test'
const flag = utils.verifySignature({
rawBody: 'test',
headers: {
'x-hub-signature': 'test'
}
})
process.env['GITHUB_SECRET_TOKEN'] = GITHUB_SECRET_TOKEN
expect(flag).to.be.false
})
})