'use strict'; /** * * * @author Mai * @date 2018/4/27 * @version */ const { app, assert } = require('egg-mock/bootstrap'); describe('test/app/service/index_calc.test.js', () => { it('calculate test', function* () { const ctx = app.mockContext(); const condition = { template_id: 1, node_id: 1, } const indexes = yield ctx.service.templateIndex.getAllDataByCondition({ where:condition }); const globalParams = yield ctx.service.templateParam.getAllDataByCondition({ where: {template_id: 1, node_id: 0,} }); const nodeParams = yield ctx.service.templateParam.getAllDataByCondition({ where: condition }); globalParams[0].calc_value = 100; globalParams[1].calc_value = 50; globalParams[2].calc_value = 20; ctx.service.indexCalc.calculate(indexes, globalParams, nodeParams); assert(ctx.service.indexCalc.updateArr[2].value === 0.5); }); });