std_chapter.test.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * 标准清单 -- 项目节 模型 单元测试
  3. *
  4. * @author Mai
  5. * @date 2018/3/15
  6. * @version
  7. */
  8. 'use strict';
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. describe('test/app/service/std_chapter.test.js', () => {
  11. // 测试R类方法
  12. it('test getData', function* () {
  13. const ctx = app.mockContext();
  14. // 查询前2层节点
  15. const result1 = yield ctx.service.stdChapter.getData(1);
  16. assert(result1.length === 32);
  17. // 查询前1层节点
  18. const result2 = yield ctx.service.stdChapter.getData(1, 1);
  19. assert(result2.length === 6);
  20. });
  21. it('test getDataByDataId', function* () {
  22. const ctx = app.mockContext();
  23. // 查询节点1-10-2
  24. const node = yield ctx.service.stdChapter.getDataByDataId(1, 47);
  25. assert(node);
  26. assert(node.code === '1-10-2');
  27. assert(node.full_path === '1.210.47');
  28. assert(node.source === ctx.service.stdChapter.stdType + '-' + node.list_id + '-' + node.chapter_id);
  29. });
  30. it('test getDataByFullPath', function* () {
  31. const ctx = app.mockContext();
  32. // 查询节点1-10-1及其子节点
  33. const result = yield ctx.service.stdChapter.getDataByFullPath(1, '1.210.3002%');
  34. assert(result.length === 9);
  35. // 查询1-10-1的子孙节点
  36. const result1 = yield ctx.service.stdChapter.getDataByFullPath(1, '1.210.3002.%');
  37. assert(result1.length === 8);
  38. });
  39. it('test getFullLevelDataByFullPath', function* () {
  40. const ctx = app.mockContext();
  41. // 查询1-10-1及其全部父节点
  42. const result1 = yield ctx.service.stdChapter.getFullLevelDataByFullPath(1, '1.210.3002');
  43. assert(result1.length === 3);
  44. // 查询1-10-2/1-10-3及其全部父节点
  45. const result2 = yield ctx.service.stdChapter.getFullLevelDataByFullPath(1, ['1.210.47', '1.210.48']);
  46. assert(result2.length === 4);
  47. });
  48. });