| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | 'use strict';/** * 标准清单 -- 工程量清单 模型 单元测试 * * @author Mai * @date * @version */'use strict';const { app, assert } = require('egg-mock/bootstrap');describe('test/app/service/std_bills.test.js', () => {    // 测试R类方法    it('test getData', function* () {        const ctx = app.mockContext();        // 查询前2层节点        const result1 = yield ctx.service.stdBills.getData(1);        assert(result1.length === 10);        // 查询前1层节点        const result2 = yield ctx.service.stdBills.getData(1, 1);        assert(result2.length === 1);    });    it('test getDataByDataId', function* () {        const ctx = app.mockContext();        // 查询节点101-1        const node = yield ctx.service.stdBills.getDataByDataId(1, 296);        assert(node);        assert(node.b_code === '101-1');        assert(node.full_path === '1.294.295.296');        assert(node.source === ctx.service.stdBills.stdType + '-' + node.list_id + '-' + node.bill_id);    });    it('test getDataByFullPath', function* () {        const ctx = app.mockContext();        // 查询节点102        const node = yield ctx.service.stdBills.getDataByCondition({            list_id: 1,            code: '102',        });        // 查询102及其子节点        const result = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '%');        assert(result.length === 6);        // 查询1-10-1的子孙节点        const result1 = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '-%');        assert(result1.length === 5);    });    it('test getFullLevelDataByFullPath', function* () {        const ctx = app.mockContext();        // 查询节点102-1        const node1 = yield ctx.service.stdBills.getDataByCondition({            list_id: 1,            code: '102-1',        });        // 查询102-1及其全部父节点        const result1 = yield ctx.service.stdBills.getFullLevelDataByFullPath(1, node1.full_path);        assert(result1.length === 4);        // 查询102-1/102-2及其全部父节点        const node2 = yield ctx.service.stdBills.getDataByCondition({            list_id: 1,            code: '102-2',        });        const result2 = yield ctx.service.stdBills.getFullLevelDataByFullPath(1, [node1.full_path, node2.full_path]);        assert(result2.length === 5);    });});
 |