test_cover_01.js 4.2 KB

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