test_cover_01.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. //config.setupCache();
  31. let cfgCacheUtil = require("../../../config/cacheCfg");
  32. cfgCacheUtil.setupDftCache();
  33. let fsUtil = require("../../../public/fsUtil");
  34. let prjMdl = require('../../../modules/pm/models/project_model');
  35. let projectDataMdl = require('../../../modules/main/models/project');
  36. let demoPrjId = - 1;
  37. let demoRptId = 223, pagesize = "A4";
  38. let userId_Leng = 1142; //小冷User Id
  39. demoPrjId = 1220; //QA:
  40. /*/
  41. let userId_Dft = userId_Leng;
  42. /*/
  43. let userId_Dft = 76075;
  44. //*/
  45. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  46. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  47. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  48. let fs = require('fs');
  49. //设置Date Format函数
  50. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  51. eval(data);
  52. });
  53. //*
  54. test('测试 - 打开模板: 封-1 ', function (t) {
  55. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  56. let rptDataUtil = new rptDataExtractor();
  57. rptDataUtil.initialize(rptTpl._doc);
  58. let filter = rptDataUtil.getDataRequestFilter();
  59. // console.log(filter);
  60. //正常应该根据报表模板定义的数据类型来请求数据
  61. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  62. if (!err) {
  63. try {
  64. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject.js");
  65. let tplData = rptDataUtil.assembleData(rawDataObj);
  66. //build the report
  67. let printCom = JpcEx.createNew();
  68. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  69. let defProperties = rpt_cfg;
  70. let dftOption = JV.PAGING_OPTION_NORMAL;
  71. printCom.initialize(rptTpl);
  72. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  73. let maxPages = printCom.totalPages;
  74. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  75. if (pageRst) {
  76. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.js");
  77. } else {
  78. console.log("oh! no pages were created!");
  79. }
  80. } catch (ex) {
  81. console.log(ex);
  82. t.pass('pass with exception!');
  83. t.end();
  84. }
  85. t.pass('pass succeeded!');
  86. t.end();
  87. } else {
  88. console.log(msg);
  89. t.pass('pass with error!');
  90. t.end();
  91. }
  92. })
  93. });
  94. });
  95. //*/
  96. test('close the connection', function (t) {
  97. setTimeout(function () {
  98. mongoose.disconnect();
  99. t.pass('closing db connection');
  100. t.end();
  101. }, 8000);
  102. // mongoose.disconnect();
  103. // t.pass('closing db connection');
  104. // t.end();
  105. });