'use strict';

/**
 *
 *
 * @author Mai
 * @date 2018/4/27
 * @version
 */

const { app, assert } = require('egg-mock/bootstrap');
// excel解析
const excel = require('node-xlsx');

describe('test/app/service/index_calc.test.js', () => {
    it('calculate test', function* () {
        const ctx = app.mockContext();

        // 初始化测试用指标模板
        const fileName = app.baseDir + '/test/app/service/test_template.xls';
        const sheets = excel.parse(fileName), templateId = 0;
        yield ctx.service.templateNode.importData(sheets, templateId);

        // 测试计算
        const condition = {
            template_id: templateId,
            node_id: 1,
        }
        const indexes = yield ctx.service.templateIndex.getAllDataByCondition({ where:condition });
        const globalParams = yield ctx.service.templateParam.getAllDataByCondition({
            where: {template_id: templateId, node_id: ctx.app.paramConst.globalParamNodeId,}
        });
        const nodeParams = yield ctx.service.templateParam.getAllDataByCondition({ where: condition });
        // 公路基本造价 = 100
        globalParams[0].calc_value = 100;
        // 建安费 = 50
        globalParams[1].calc_value = 50;
        ctx.service.indexCalc.calculate(indexes, globalParams, nodeParams);
        const index = ctx.helper.findObj(ctx.service.indexCalc.updateArr, 'code', 'z-3');
        // 建安费/公路基本造价 = 0.5
        assert(index.value === 0.5);
    });

});