index_calc.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/4/27
  7. * @version
  8. */
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. // excel解析
  11. const excel = require('node-xlsx');
  12. describe('test/app/service/index_calc.test.js', () => {
  13. it('calculate test', function* () {
  14. const ctx = app.mockContext();
  15. // 初始化测试用指标模板
  16. const fileName = app.baseDir + '/test/app/service/test_template.xls';
  17. const sheets = excel.parse(fileName), templateId = 0;
  18. yield ctx.service.templateNode.importData(sheets, templateId);
  19. // 测试计算
  20. const condition = {
  21. template_id: templateId,
  22. node_id: 1,
  23. }
  24. const indexes = yield ctx.service.templateIndex.getAllDataByCondition({ where:condition });
  25. const globalParams = yield ctx.service.templateParam.getAllDataByCondition({
  26. where: {template_id: templateId, node_id: ctx.app.paramConst.globalParamNodeId,}
  27. });
  28. const nodeParams = yield ctx.service.templateParam.getAllDataByCondition({ where: condition });
  29. // 公路基本造价 = 100
  30. globalParams[0].calc_value = 100;
  31. // 建安费 = 50
  32. globalParams[1].calc_value = 50;
  33. ctx.service.indexCalc.calculate(indexes, globalParams, nodeParams);
  34. const index = ctx.helper.findObj(ctx.service.indexCalc.updateArr, 'code', 'z-3');
  35. // 建安费/公路基本造价 = 0.5
  36. assert(index.value === 0.5);
  37. });
  38. });