prj_properties_test.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 rationLibId = 3;
  10. let randomPrjId = Math.round(Math.random() * 100);
  11. //let randomPrjId = 35;
  12. dbm.connect();
  13. /*
  14. test('测试 - 创建dummy项目属性: ', function (t) {
  15. let items = [];
  16. items.push({key: "contractNum", dispName: "合同号", value: "天字第一号"});
  17. items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
  18. items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
  19. items.push({key: "startDate", dispName: "开工日期", value: "2017-07-31"});
  20. items.push({key: "completeDate", dispName: "竣工日期", value: "2018-07-31"});
  21. items.push({key: "location", dispName: "工程地点", value: "珠海新香洲人民西路666号"});
  22. items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
  23. items.push({key: "designCompany", dispName: "设计单位", value: "珠海设计局"});
  24. items.push({key: "buildingCompany", dispName: "施工单位", value: "中建十局"});
  25. items.push({key: "superviseCompany", dispName: "监理单位", value: "珠海监理"});
  26. items.push({key: "auditCompany", dispName: "审核单位", value: "创新审核"});
  27. items.push({key: "author", dispName: "编制人", value: "张三"});
  28. items.push({key: "auditor", dispName: "审核人", value: "李四"});
  29. let results = ppFacade.createPrjProperties(randomPrjId, items);
  30. results.then(function(rst) {
  31. console.log('rst.projectID: ' + rst.projectID);
  32. for (let prop of rst.properties) {
  33. console.log('property ' + prop.dispName + ': ' + prop.value);
  34. }
  35. t.pass('just pass!');
  36. t.end();
  37. });
  38. });
  39. //*/
  40. /*
  41. test('测试 - 创建dummy标准项目属性: ', function (t) {
  42. let items = [];
  43. items.push({key: "contractNum", dispName: "合同号", value: "天字第一号"});
  44. items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
  45. items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
  46. items.push({key: "startDate", dispName: "开工日期", value: "2017-07-31"});
  47. items.push({key: "completeDate", dispName: "竣工日期", value: "2018-07-31"});
  48. items.push({key: "location", dispName: "工程地点", value: "珠海新香洲人民西路666号"});
  49. items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
  50. items.push({key: "designCompany", dispName: "设计单位", value: "珠海设计局"});
  51. items.push({key: "buildingCompany", dispName: "施工单位", value: "中建十局"});
  52. items.push({key: "superviseCompany", dispName: "监理单位", value: "珠海监理"});
  53. items.push({key: "auditCompany", dispName: "审核单位", value: "创新审核"});
  54. items.push({key: "author", dispName: "编制人", value: "张三"});
  55. items.push({key: "auditor", dispName: "审核人", value: "李四"});
  56. let results = ppFacade.createStdPrjProperties(rationLibId, items);
  57. results.then(function(rst) {
  58. console.log('rst.projectID: ' + rst.projectID);
  59. for (let prop of rst.properties) {
  60. console.log('property ' + prop.dispName + ': ' + prop.value);
  61. }
  62. t.pass('just pass!');
  63. t.end();
  64. });
  65. });
  66. //*/
  67. /*
  68. test('测试 - 整个更新项目属性: ', function (t) {
  69. let items = [];
  70. items.push({key: "contractNum", dispName: "合同号", value: "人字第三号"});
  71. items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
  72. items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
  73. items.push({key: "startDate", dispName: "建设日期", value: "2017-08-01"});
  74. items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
  75. items.push({key: "designCompany", dispName: "设计单位", value: "珠海设计局"});
  76. items.push({key: "buildingCompany", dispName: "施工单位", value: "中建十局"});
  77. let udtObj = {"projectID": 35, "properties": items};
  78. let rst = ppFacade.updateWhole(udtObj);
  79. if (rst) {
  80. rst.then(function(results){
  81. for (let prop in results) {
  82. console.log(prop + ': ' + results[prop]);
  83. }
  84. t.pass('just pass!');
  85. t.end();
  86. });
  87. } else {
  88. console.log('update failed!');
  89. t.pass('just pass!');
  90. t.end();
  91. }
  92. });
  93. //*/
  94. /*
  95. test('测试 - 新增项目属性: ', function (t) {
  96. let newItem = {key: "superviseCompany", dispName: "监理单位", value: "珠海德信"};
  97. let results = ppFacade.addOrChangeProperty(35, newItem);
  98. if (results instanceof Promise) {
  99. results.then(function (rst) {
  100. for (let prop in rst) {
  101. console.log("property " + prop + ' : ' + rst[prop]);
  102. }
  103. })
  104. } else {
  105. for (let prop in results) {
  106. console.log("property " + prop + ' : ' + results[prop]);
  107. }
  108. }
  109. t.pass('just pass!');
  110. t.end();
  111. });
  112. //*/
  113. /*
  114. test('测试 - 删除全体项目属性: ', function (t) {
  115. let rst = ppFacade.removePrjProperties(35);
  116. if (rst) {
  117. if (rst instanceof Promise) {
  118. rst.then(function(results){
  119. for (let prop in results) {
  120. console.log(prop + ': ' + results[prop]);
  121. }
  122. t.pass('just pass with remove1!');
  123. t.end();
  124. });
  125. } else {
  126. for (let prop in results) {
  127. console.log(prop + ': ' + results[prop]);
  128. }
  129. t.pass('just pass with remove2!');
  130. t.end();
  131. }
  132. } else {
  133. t.pass('just pass but not remove!');
  134. t.end();
  135. }
  136. });
  137. //*/
  138. /*
  139. test('测试 - 更新项目属性: ', function (t) {
  140. let rst = ppFacade.updateOneProperty(35, "buildingCompany", "中建十一局");
  141. if (rst) {
  142. rst.then(function(results){
  143. for (let prop in results) {
  144. console.log(prop + ': ' + results[prop]);
  145. }
  146. t.pass('just pass with update!');
  147. t.end();
  148. });
  149. } else {
  150. t.pass('just pass but not update!');
  151. t.end();
  152. }
  153. });
  154. //*/
  155. /*
  156. test('测试 - 获取项目属性: ', function (t) {
  157. let rst = ppFacade.getPrjProperty(35);
  158. if (rst) {
  159. rst.then(function(results){
  160. console.log(results.projectID);
  161. console.log(results.properties);
  162. t.pass('just pass with update!');
  163. t.end();
  164. });
  165. } else {
  166. t.pass('just pass but not update!');
  167. t.end();
  168. }
  169. });
  170. //*/
  171. /*
  172. test('测试 - 获取标准项目属性: ', function (t) {
  173. let rst = ppFacade.getStdPrjProperties(rationLibId);
  174. if (rst) {
  175. rst.then(function(results){
  176. // console.log(results.rationLibID);
  177. // console.log(results.properties);
  178. let rt = ppFacade.createPrjProperties(randomPrjId, results.properties);
  179. rt.then(function (rt1) {
  180. console.log('创建后ID: '+ rt1.projectID);
  181. })
  182. t.pass('just pass with update!');
  183. t.end();
  184. });
  185. } else {
  186. t.pass('just pass but not update!');
  187. t.end();
  188. }
  189. });
  190. //*/
  191. /*
  192. test('测试 - 移除一项属性: ', function (t) {
  193. let rst = ppFacade.removeOneProperty(35, "superviseCompany");
  194. if (rst) {
  195. rst.then(function(results){
  196. for (let prop in results) {
  197. console.log(prop + ': ' + results[prop]);
  198. }
  199. t.pass('just pass with remove!');
  200. t.end();
  201. });
  202. } else {
  203. t.pass('just pass but not remove!');
  204. t.end();
  205. }
  206. });
  207. //*/
  208. test('close the connection', function (t) {
  209. // setTimeout(function () {
  210. // mongoose.disconnect();
  211. // t.pass('closing db connection');
  212. // t.end();
  213. // }, 100);
  214. mongoose.disconnect();
  215. t.pass('closing db connection');
  216. t.end();
  217. })