test_cover_02.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Created by Tony on 2017/12/18.
  3. */
  4. let test = require('tape');
  5. const JpcEx = require("../../../modules/reports/rpt_component/jpc_ex");
  6. const JV = require("../../../modules/reports/rpt_component/jpc_value_define");
  7. let config = require("../../../config/config.js");
  8. config.setupDb(process.env.NODE_ENV);
  9. let mongoose = require("mongoose");
  10. let fileUtils = require("../../../modules/common/fileUtils");
  11. let path = require('path');
  12. let dbm = require("../../../config/db/db_manager");
  13. let rpt_cfg = require('./rpt_cfg');
  14. dbm.connect(process.env.NODE_ENV);
  15. //统一引用models
  16. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  17. require(path.resolve(modelPath));
  18. });
  19. let cfgCacheUtil = require("../../../config/cacheCfg");
  20. cfgCacheUtil.setupDftCache();
  21. let fsUtil = require("../../../public/fsUtil");
  22. let demoPrjId = - 1;
  23. let demoRptId = 229, pagesize = "A4";
  24. let userId_Leng = 1142; //小冷User Id
  25. demoPrjId = 1296; //QA:
  26. //*/
  27. let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
  28. /*/
  29. let userId_Dft = "595328da1934dc327cad08eb";
  30. //*/
  31. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  32. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  33. const rptDataExtractor = require("../../../modules/reports/util/rpt_construct_data_util");
  34. let fs = require('fs');
  35. //设置Date Format函数
  36. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  37. eval(data);
  38. });
  39. //*
  40. test('测试 - 打开模板: 封-1 ', function (t) {
  41. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  42. let rptDataUtil = new rptDataExtractor();
  43. rptDataUtil.initialize(rptTpl._doc);
  44. let filter = rptDataUtil.getDataRequestFilter();
  45. // console.log(filter);
  46. //正常应该根据报表模板定义的数据类型来请求数据
  47. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  48. if (!err) {
  49. try {
  50. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject.jsp");
  51. let tplData = rptDataUtil.assembleData(rawDataObj);
  52. //build the report
  53. let printCom = JpcEx.createNew();
  54. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  55. let defProperties = rpt_cfg;
  56. let dftOption = JV.PAGING_OPTION_NORMAL;
  57. printCom.initialize(rptTpl);
  58. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  59. let maxPages = printCom.totalPages;
  60. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  61. if (pageRst) {
  62. fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
  63. } else {
  64. console.log("oh! no pages were created!");
  65. }
  66. } catch (ex) {
  67. console.log(ex);
  68. t.pass('pass with exception!');
  69. t.end();
  70. }
  71. t.pass('pass succeeded!');
  72. t.end();
  73. } else {
  74. console.log(msg);
  75. t.pass('pass with error!');
  76. t.end();
  77. }
  78. })
  79. });
  80. });
  81. //*/
  82. test('close the connection', function (t) {
  83. setTimeout(function () {
  84. mongoose.disconnect();
  85. t.pass('closing db connection');
  86. t.end();
  87. }, 3000);
  88. // mongoose.disconnect();
  89. // t.pass('closing db connection');
  90. // t.end();
  91. });