index_calc.test.js 985 B

1234567891011121314151617181920212223242526272829303132
  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. describe('test/app/service/index_calc.test.js', () => {
  11. it('calculate test', function* () {
  12. const ctx = app.mockContext();
  13. const condition = {
  14. template_id: 1,
  15. node_id: 1,
  16. }
  17. const indexes = yield ctx.service.templateIndex.getAllDataByCondition({ where:condition });
  18. const globalParams = yield ctx.service.templateParam.getAllDataByCondition({
  19. where: {template_id: 1, node_id: 0,}
  20. });
  21. const nodeParams = yield ctx.service.templateParam.getAllDataByCondition({ where: condition });
  22. globalParams[0].calc_value = 100;
  23. globalParams[1].calc_value = 50;
  24. globalParams[2].calc_value = 20;
  25. ctx.service.indexCalc.calculate(indexes, globalParams, nodeParams);
  26. assert(ctx.service.indexCalc.updateArr[2].value === 0.5);
  27. });
  28. });