test_cover_01.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Created by Tony on 2017/11/21.
  3. */
  4. let test = require('tape');
  5. import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
  6. import JV from "../../../modules/reports/rpt_component/jpc_value_define";
  7. let mongoose = require("mongoose");
  8. let fileUtils = require("../../../modules/common/fileUtils");
  9. let path = require('path');
  10. let dbm = require("../../../config/db/db_manager");
  11. let rpt_cfg = require('./rpt_cfg');
  12. dbm.connect();
  13. let consts = require('../../../modules/main/models/project_consts');
  14. let projectConsts = consts.projectConst;
  15. fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
  16. require(path.resolve(modelPath));
  17. });
  18. fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
  19. require(path.resolve(modelPath));
  20. });
  21. //引入报表模块
  22. fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
  23. require(path.resolve(modelPath));
  24. })
  25. //暂时引入其它模块的model
  26. require('../../../modules/fee_rates/models/fee_rates');
  27. // 引入人工系数模块
  28. require('../../../modules/main/models/labour_coe_model');
  29. require('../../../modules/main/models/calc_program_model');
  30. let fsUtil = require("../../../public/fsUtil");
  31. let prjMdl = require('../../../modules/pm/models/project_model');
  32. let projectDataMdl = require('../../../modules/main/models/project');
  33. let demoPrjId = - 1;
  34. let demoRptId = 223, pagesize = "A4";
  35. let userId_Leng = 1142; //小冷User Id
  36. // demoPrjId = 720; //QA: DW3
  37. demoPrjId = 838; //QA:
  38. /*/
  39. let userId_Dft = userId_Leng;
  40. /*/
  41. let userId_Dft = 76075;
  42. //*/
  43. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  44. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  45. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  46. let fs = require('fs');
  47. //设置Date Format函数
  48. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  49. eval(data);
  50. });
  51. //*
  52. test('测试 - 打开模板: 封-1 ', function (t) {
  53. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  54. let rptDataUtil = new rptDataExtractor();
  55. rptDataUtil.initialize(rptTpl._doc);
  56. let filter = rptDataUtil.getDataRequestFilter();
  57. // console.log(filter);
  58. //正常应该根据报表模板定义的数据类型来请求数据
  59. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  60. if (!err) {
  61. try {
  62. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject.js");
  63. let tplData = rptDataUtil.assembleData(rawDataObj);
  64. //build the report
  65. let printCom = JpcEx.createNew();
  66. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  67. let defProperties = rpt_cfg;
  68. let dftOption = JV.PAGING_OPTION_NORMAL;
  69. printCom.initialize(rptTpl);
  70. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  71. let maxPages = printCom.totalPages;
  72. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  73. if (pageRst) {
  74. fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.js");
  75. } else {
  76. console.log("oh! no pages were created!");
  77. }
  78. } catch (ex) {
  79. console.log(ex);
  80. t.pass('pass with exception!');
  81. t.end();
  82. }
  83. t.pass('pass succeeded!');
  84. t.end();
  85. } else {
  86. console.log(msg);
  87. t.pass('pass with error!');
  88. t.end();
  89. }
  90. })
  91. });
  92. });
  93. //*/
  94. test('close the connection', function (t) {
  95. setTimeout(function () {
  96. mongoose.disconnect();
  97. t.pass('closing db connection');
  98. t.end();
  99. }, 8000);
  100. // mongoose.disconnect();
  101. // t.pass('closing db connection');
  102. // t.end();
  103. });