'use strict'; /** * * * @author Mai * @date * @version */ const { app, assert } = require('egg-mock/bootstrap'); const mockData = {}; const path = require('path'); const reportDataAnalysis = require('../../../app/lib/rpt_data_analysis'); describe('test/app/service/report_memory.test.js', () => { // 准备测试数据 before(function* () { const ctx = app.mockContext(); // 模拟登录session // const postData = { // account: 'fuqingqing', // project: 'P0505', // project_password: '123456', // }; const postData = { account: '734406061@qq.com', project: 'T201711273363', project_password: 'mai654321', }; ctx.session = {}; const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2); assert(loginResult); mockData.session = ctx.session; }); // 数据 it('test changeSort', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['change', 'change_audit_list']; const data = yield ctx.service.report.getReportData(params, filters); reportDataAnalysis.analysisObj.changeSort.fun(ctx, data); assert(data.change[0].code === 'test7-BG-001'); assert(data.change[2].code === 'test7-BG-003'); const changeCid = ctx.helper._.map(data.change, 'cid'); const changeBillsCid = ctx.helper._.uniq(ctx.helper._.map(data.change_audit_list, 'cid')); assert(changeCid.length === changeBillsCid.length); changeCid.forEach(function (a, i) { assert(a === changeBillsCid[i]); }); }); it('test gatherGcl && sortGcl', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['mem_stage_bills']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price', 'deal_qty', 'deal_tp', 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2', 'drawing_code', 'memo', 'node_type', 'is_tp', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil', 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp', 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp', 'final_tp', 'final_ratio', 'qc_bgl_code', 'chapter', ] }); assert(data.mem_stage_bills.length === 216); reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, {field: 'name', table: 'mem_stage_bills'}, {field: 'unit', table: 'mem_stage_bills'}, {field: 'unit_price', table: 'mem_stage_bills'}, {field: 'is_leaf', table: 'mem_stage_bills'}, ]); assert(data.mem_stage_bills.length === 43); reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, ]); const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code'); const codeIndex100 = ['103-1', '103-2', '103-3-a', '103-3-b', '103-4', '104-1']; const codeIndex200 = [ '203-1-a', '203-1-b', '203-1-d', '204-1-b', '204-1-g-4', '204-1-j', '205-1-o-1', '206-2', '207-1-b', '207-2-a', '207-3-a', '207-4-a', '208-1-a', '208-3-a', '208-3-c', '208-4-b-1', '209-1-a', ]; const codeIndex400 = [ '403-1-a', '403-1-b', '403-2-a', '403-2-b', '403-3-a', '403-3-b', '403-4-a', '403-4-b', '405-1-b-5', '405-1-b-6', '410-1-b', '410-1-c', '410-2-b', '410-2-c', '410-6-c', '411-5', '411-7-a', '411-8-a', '413-1-a', '417-5-a' ]; let codeResult = codeIndex100.concat(codeIndex200, codeIndex400); codeIndex.forEach(function (a, i) { assert(a === codeResult[i]); }); }); it('test gatherChapter', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['mem_stage_bills', 'tender_info']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price', 'deal_qty', 'deal_tp', 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2', 'drawing_code', 'memo', 'node_type', 'is_tp', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil', 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp', 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp', 'final_tp', 'final_ratio', 'qc_bgl_code', 'chapter', ] }); const bills = data.mem_stage_bills.find(function (x) {return x.b_code === '103-3-a'}); reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, {field: 'is_leaf', table: 'mem_stage_bills'}, ]); const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'}); assert(chapter100.total_price === 1045756); const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'}); assert(chapter200.total_price.toFixed(0) == 3813369); assert(chapter200.contract_tp == 700.5); const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'}); assert(chapter400.total_price.toFixed(0) == 1231018); }); it('test analysisDefine', function() { const define = reportDataAnalysis.analysisDefine; assert(define.length === 4); assert(define[0].key === 'changeSort'); assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name); assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint); assert(define[1].key === 'gatherGcl'); assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name); assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint); assert(define[2].key === 'sortGcl'); assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name); assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint); }); });