log.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. /**
  3. * 日志模块单元测试
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/10/31
  7. * @version
  8. */
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. describe('test/app/service/log.test.js', () => {
  11. it('log list test', function* () {
  12. // 创建 ctx
  13. const ctx = app.mockContext({
  14. sort: [],
  15. page: 1,
  16. });
  17. ctx.service.log.searchFilter(ctx.request.query);
  18. const logList = yield ctx.service.log.getListWithBuilder();
  19. assert(logList instanceof Array);
  20. });
  21. it('add log test', function* () {
  22. // 创建 ctx
  23. const ctx = app.mockContext({
  24. session: {
  25. managerSession: {
  26. username: 'tester',
  27. },
  28. },
  29. });
  30. // 错误插入
  31. const errInsertData = {
  32. controller: '',
  33. action: 'test',
  34. operation: '',
  35. };
  36. const errInsertResult = yield ctx.service.log.addLog(errInsertData);
  37. assert(!errInsertResult);
  38. // 成功插入模拟
  39. const successInsertData = {
  40. controller: 'test',
  41. action: 'test',
  42. operation: '单元测试',
  43. type: 1,
  44. target_id: 0,
  45. };
  46. const result = yield ctx.service.log.addLog(successInsertData);
  47. assert(result);
  48. });
  49. });