12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 'use strict';
- /**
- * 日志模块单元测试
- *
- * @author CaiAoLin
- * @date 2017/10/31
- * @version
- */
- const { app, assert } = require('egg-mock/bootstrap');
- describe('test/app/service/log.test.js', () => {
- it('log list test', function* () {
- // 创建 ctx
- const ctx = app.mockContext({
- sort: [],
- page: 1,
- });
- ctx.service.log.searchFilter(ctx.request.query);
- const logList = yield ctx.service.log.getListWithBuilder();
- assert(logList instanceof Array);
- });
- it('add log test', function* () {
- // 创建 ctx
- const ctx = app.mockContext({
- session: {
- managerSession: {
- username: 'tester',
- },
- },
- });
- // 错误插入
- const errInsertData = {
- controller: '',
- action: 'test',
- operation: '',
- };
- const errInsertResult = yield ctx.service.log.addLog(errInsertData);
- assert(!errInsertResult);
- // 成功插入模拟
- const successInsertData = {
- controller: 'test',
- action: 'test',
- operation: '单元测试',
- type: 1,
- target_id: 0,
- };
- const result = yield ctx.service.log.addLog(successInsertData);
- assert(result);
- });
- });
|