test_cover_02.js 3.6 KB

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