prj_properties_test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Created by Tony on 2017/8/4.
  3. */
  4. let test = require('tape');
  5. let mongoose = require("mongoose");
  6. let dbm = require("../../../config/db/db_manager");
  7. require('../../../modules/main/models/prj_properties');
  8. let ppFacade = require('../../../modules/main/facade/prj_properties_facade');
  9. //let randomPrjId = Math.round(Math.random() * 100);
  10. let randomPrjId = 35;
  11. dbm.connect();
  12. // test('测试 - 创建dummy项目属性: ', function (t) {
  13. // let items = [];
  14. // items.push({key: "contractNum", dispName: "合同号", value: "天字第一号"});
  15. // items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
  16. // items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
  17. // items.push({key: "startDate", dispName: "建设日期", value: "2017-07-31"});
  18. // items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
  19. // items.push({key: "designer", dispName: "设计单位", value: "珠海设计局"});
  20. // items.push({key: "builder", dispName: "施工单位", value: "中建十局"});
  21. //
  22. // let results = ppFacade.createPrjProperties(randomPrjId, items);
  23. // results.then(function(rst) {
  24. // console.log('rst.projectID: ' + rst.projectID);
  25. // for (let prop of rst.properties) {
  26. // console.log('property ' + prop.dispName + ': ' + prop.value);
  27. // }
  28. // t.pass('just pass!');
  29. // t.end();
  30. // });
  31. // });
  32. // test('测试 - 整个更新项目属性: ', function (t) {
  33. // let items = [];
  34. // items.push({key: "contractNum", dispName: "合同号", value: "人字第三号"});
  35. // items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
  36. // items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
  37. // items.push({key: "startDate", dispName: "建设日期", value: "2017-08-01"});
  38. // items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
  39. // items.push({key: "designer", dispName: "设计单位", value: "珠海设计局"});
  40. // items.push({key: "builder", dispName: "施工单位", value: "中建十局"});
  41. //
  42. // let udtObj = {"projectID": 35, "properties": items};
  43. //
  44. // let rst = ppFacade.updateWhole(udtObj);
  45. // if (rst) {
  46. // rst.then(function(results){
  47. // for (let prop in results) {
  48. // console.log(prop + ': ' + results[prop]);
  49. // }
  50. // t.pass('just pass!');
  51. // t.end();
  52. // });
  53. // } else {
  54. // console.log('update failed!');
  55. // t.pass('just pass!');
  56. // t.end();
  57. // }
  58. // });
  59. // test('测试 - 新增项目属性: ', function (t) {
  60. // let newItem = {key: "auditor", dispName: "监理单位", value: "珠海德信"};
  61. // let results = ppFacade.addOrChangeProperty(35, newItem);
  62. // if (results instanceof Promise) {
  63. // results.then(function (rst) {
  64. // for (let prop in rst) {
  65. // console.log("property " + prop + ' : ' + rst[prop]);
  66. // }
  67. // })
  68. // } else {
  69. // for (let prop in results) {
  70. // console.log("property " + prop + ' : ' + results[prop]);
  71. // }
  72. // }
  73. //
  74. // t.pass('just pass!');
  75. // t.end();
  76. //
  77. // });
  78. // test('测试 - 删除全体项目属性: ', function (t) {
  79. // let rst = ppFacade.removeProperty(35);
  80. // if (rst) {
  81. // if (rst instanceof Promise) {
  82. // rst.then(function(results){
  83. // for (let prop in results) {
  84. // console.log(prop + ': ' + results[prop]);
  85. // }
  86. // t.pass('just pass with remove1!');
  87. // t.end();
  88. // });
  89. // } else {
  90. // for (let prop in results) {
  91. // console.log(prop + ': ' + results[prop]);
  92. // }
  93. // t.pass('just pass with remove2!');
  94. // t.end();
  95. // }
  96. // } else {
  97. // t.pass('just pass but not remove!');
  98. // t.end();
  99. // }
  100. // });
  101. // test('测试 - 更新项目属性: ', function (t) {
  102. // let rst = ppFacade.updateOneProperty(35, "builder", "中建十一局");
  103. // if (rst) {
  104. // rst.then(function(results){
  105. // for (let prop in results) {
  106. // console.log(prop + ': ' + results[prop]);
  107. // }
  108. // t.pass('just pass with update!');
  109. // t.end();
  110. // });
  111. // } else {
  112. // t.pass('just pass but not update!');
  113. // t.end();
  114. // }
  115. // });
  116. // test('测试 - 移除一项属性: ', function (t) {
  117. // let rst = ppFacade.removeOneProperty(35, "auditor");
  118. // if (rst) {
  119. // rst.then(function(results){
  120. // for (let prop in results) {
  121. // console.log(prop + ': ' + results[prop]);
  122. // }
  123. // t.pass('just pass with remove!');
  124. // t.end();
  125. // });
  126. // } else {
  127. // t.pass('just pass but not remove!');
  128. // t.end();
  129. // }
  130. // });
  131. test('close the connection', function (t) {
  132. setTimeout(function () {
  133. mongoose.disconnect();
  134. t.pass('closing db connection');
  135. t.end();
  136. }, 1500);
  137. })