| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | 'use strict';/** * * * @author Mai * @date * @version */const { app, assert } = require('egg-mock/bootstrap');const path = require('path');let savePath;const mockData = {};const dataType = {    int: 'int',    str: 'string',    double: 'double',    currency: 'currency',};const checkData = function (target, source) {    for (const prop in source) {        if (source[prop] !== target[prop]) return false;    }    return true;};describe('test/app/service/report_memory.test.js', () => {    // 准备测试数据    before(function* () {        const ctx = app.mockContext();        savePath = path.join(ctx.app.baseDir,'report_temp');        const postData = {            account: 'fuqingqing',            project: 'P0505',            project_password: '123456',        };        ctx.session = {};        const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);        assert(loginResult);        mockData.session = ctx.session;    });    // 材料调差 - 期列表    it('test getMaterial', function* () {        const ctx = app.mockContext(mockData);        const result = yield ctx.service.reportMemory.getMaterial(2418);        yield ctx.helper.saveBufferFile(JSON.stringify(result, "", "\t"), path.join(savePath, 'mem-material.json'));    });    // 材料调差 - 期 - 调差工料    it('test getMaterialGl Order1', function* () {        const ctx = app.mockContext(mockData);        const result = yield ctx.service.reportMemory.getMaterialGl(2418, 2);        //yield ctx.helper.saveBufferFile(JSON.stringify(result, "", "\t"), path.join(savePath, 'mem-material-gl.json'));        assert(result.length === 4);    });    it('test getMaterialGl Order2', function* () {        const ctx = app.mockContext(mockData);        const checkResult = [            {                "id": 131, "tid": 2418, "mid": 131,                "code": "101", "name": "光圆钢筋", "unit": "kg", "spec": null,                "t_type": 1, "m_type": 1, "t_type_str": "消耗量", "m_type_str": "分类",                "quantity": 145.635, "expr": null,                "basic_price": 4350, "basic_times": null,                "msg_tp": 5100, "msg_times": "2020-05-08", "msg_spread": 750,                "m_up_risk": 5, "m_down_risk": 5, "m_spread": 532.5,                "tp": 77550.64, "end_tp": 1060588.24, "pre_tp": 983037.6,                "remark": null, "in_time": "2020-05-08T08:09:33.000Z",            },            {                "id": 132, "tid": 2418, "mid": 131,                "t_type": 1, "m_type": 1, "t_type_str": "消耗量", "m_type_str": "分类",                "code": "102", "name": "带肋钢筋", "unit": "kg", "spec": null,                "quantity": 145.55, "expr": null,                "basic_price": 4620, "basic_times": null,                "msg_tp": 5500, "msg_times": "2020-05-09", "msg_spread": 880,                "m_up_risk": 5, "m_down_risk": 5, "m_spread": 649,                "tp": 94461.95, "end_tp": 1783456.95, "pre_tp": 1688995,                "remark": null, "in_time": "2020-05-08T08:09:33.000Z",            },            {                "id": 133,                "tid": 2418,                "mid": 131,                "t_type": 1,                "code": "103",                "name": "水泥",                "unit": "m3",                "spec": null,                "m_type": 1,                "quantity": 498.732,                "expr": null,                "basic_price": 236.98,                "basic_times": null,                "msg_tp": 200.69,                "msg_times": "2020-05-09",                "msg_spread": -36.29,                "m_up_risk": 5,                "m_down_risk": 5,                "m_spread": -24.441,                "pre_tp": -3770872.11,                "remark": null,                "in_time": "2020-05-08T08:09:34.000Z",                "tp": -12189.51,                "t_type_str": "消耗量",                "m_type_str": "分类",                "end_tp": -3783061.62            },            {                "id": 134,                "tid": 2418,                "mid": 131,                "t_type": 2,                "code": "985",                "name": "汽油",                "unit": "kg",                "spec": null,                "m_type": 1,                "quantity": 1170.1512,                "expr": "bqwc/10000*12",                "basic_price": 4.9,                "basic_times": null,                "msg_tp": 6.2,                "msg_times": "2020-05-08",                "msg_spread": 1.3,                "m_up_risk": 3,                "m_down_risk": 3,                "m_spread": 1.153,                "pre_tp": null,                "remark": null,                "in_time": "2020-05-08T08:09:36.000Z",                "tp": 1349.18,                "t_type_str": "费用",                "m_type_str": "分类",                "end_tp": 1349.18            }        ];        const result = yield ctx.service.reportMemory.getMaterialGl(2418, 2);        //yield ctx.helper.saveBufferFile(JSON.stringify(result, "", "\t"), path.join(savePath, 'mem-material-gl.json'));        assert(result.length === 4);        assert(checkData(result[0], checkResult[0]));        assert(checkData(result[1], checkResult[1]));        assert(checkData(result[2], checkResult[2]));        assert(checkData(result[3], checkResult[3]));    });});
 |