std_bills.test.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. /**
  3. * 标准清单 -- 工程量清单 模型 单元测试
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. 'use strict';
  10. const { app, assert } = require('egg-mock/bootstrap');
  11. describe('test/app/service/std_bills.test.js', () => {
  12. // 测试R类方法
  13. it('test getData', function* () {
  14. const ctx = app.mockContext();
  15. // 查询前2层节点
  16. const result1 = yield ctx.service.stdBills.getData(1);
  17. assert(result1.length === 10);
  18. // 查询前1层节点
  19. const result2 = yield ctx.service.stdBills.getData(1, 1);
  20. assert(result2.length === 1);
  21. });
  22. it('test getDataByDataId', function* () {
  23. const ctx = app.mockContext();
  24. // 查询节点101-1
  25. const node = yield ctx.service.stdBills.getDataByDataId(1, 296);
  26. assert(node);
  27. assert(node.b_code === '101-1');
  28. assert(node.full_path === '1.294.295.296');
  29. assert(node.source === ctx.service.stdBills.stdType + '-' + node.list_id + '-' + node.bill_id);
  30. });
  31. it('test getDataByFullPath', function* () {
  32. const ctx = app.mockContext();
  33. // 查询节点102
  34. const node = yield ctx.service.stdBills.getDataByCondition({
  35. list_id: 1,
  36. code: '102',
  37. });
  38. // 查询102及其子节点
  39. const result = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '%');
  40. assert(result.length === 6);
  41. // 查询1-10-1的子孙节点
  42. const result1 = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '-%');
  43. assert(result1.length === 5);
  44. });
  45. it('test getFullLevelDataByFullPath', function* () {
  46. const ctx = app.mockContext();
  47. // 查询节点102-1
  48. const node1 = yield ctx.service.stdBills.getDataByCondition({
  49. list_id: 1,
  50. code: '102-1',
  51. });
  52. // 查询102-1及其全部父节点
  53. const result1 = yield ctx.service.stdBills.getFullLevelDataByFullPath(1, node1.full_path);
  54. assert(result1.length === 4);
  55. // 查询102-1/102-2及其全部父节点
  56. const node2 = yield ctx.service.stdBills.getDataByCondition({
  57. list_id: 1,
  58. code: '102-2',
  59. });
  60. const result2 = yield ctx.service.stdBills.getFullLevelDataByFullPath(1, [node1.full_path, node2.full_path]);
  61. assert(result2.length === 5);
  62. });
  63. });