report_memory_material.test.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. const path = require('path');
  11. let savePath;
  12. const mockData = {};
  13. const dataType = {
  14. int: 'int',
  15. str: 'string',
  16. double: 'double',
  17. currency: 'currency',
  18. };
  19. const checkData = function (target, source) {
  20. for (const prop in source) {
  21. if (source[prop] !== target[prop]) return false;
  22. }
  23. return true;
  24. };
  25. describe('test/app/service/report_memory.test.js', () => {
  26. // 准备测试数据
  27. before(function* () {
  28. const ctx = app.mockContext();
  29. savePath = path.join(ctx.app.baseDir,'report_temp');
  30. const postData = {
  31. account: 'fuqingqing',
  32. project: 'P0505',
  33. project_password: '123456',
  34. };
  35. ctx.session = {};
  36. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  37. assert(loginResult);
  38. mockData.session = ctx.session;
  39. });
  40. // 材料调差 - 期列表
  41. it('test getMaterial', function* () {
  42. const ctx = app.mockContext(mockData);
  43. const result = yield ctx.service.reportMemory.getMaterial(2418);
  44. yield ctx.helper.saveBufferFile(JSON.stringify(result, "", "\t"), path.join(savePath, 'mem-material.json'));
  45. });
  46. // 材料调差 - 期 - 调差工料
  47. it('test getMaterialGl Order1', function* () {
  48. const ctx = app.mockContext(mockData);
  49. const result = yield ctx.service.reportMemory.getMaterialGl(2418, 2);
  50. //yield ctx.helper.saveBufferFile(JSON.stringify(result, "", "\t"), path.join(savePath, 'mem-material-gl.json'));
  51. assert(result.length === 4);
  52. });
  53. it('test getMaterialGl Order2', function* () {
  54. const ctx = app.mockContext(mockData);
  55. const checkResult = [
  56. {
  57. "id": 131, "tid": 2418, "mid": 131,
  58. "code": "101", "name": "光圆钢筋", "unit": "kg", "spec": null,
  59. "t_type": 1, "m_type": 1, "t_type_str": "消耗量", "m_type_str": "分类",
  60. "quantity": 145.635, "expr": null,
  61. "basic_price": 4350, "basic_times": null,
  62. "msg_tp": 5100, "msg_times": "2020-05-08", "msg_spread": 750,
  63. "m_up_risk": 5, "m_down_risk": 5, "m_spread": 532.5,
  64. "tp": 77550.64, "end_tp": 1060588.24, "pre_tp": 983037.6,
  65. "remark": null, "in_time": "2020-05-08T08:09:33.000Z",
  66. },
  67. {
  68. "id": 132, "tid": 2418, "mid": 131,
  69. "t_type": 1, "m_type": 1, "t_type_str": "消耗量", "m_type_str": "分类",
  70. "code": "102", "name": "带肋钢筋", "unit": "kg", "spec": null,
  71. "quantity": 145.55, "expr": null,
  72. "basic_price": 4620, "basic_times": null,
  73. "msg_tp": 5500, "msg_times": "2020-05-09", "msg_spread": 880,
  74. "m_up_risk": 5, "m_down_risk": 5, "m_spread": 649,
  75. "tp": 94461.95, "end_tp": 1783456.95, "pre_tp": 1688995,
  76. "remark": null, "in_time": "2020-05-08T08:09:33.000Z",
  77. },
  78. {
  79. "id": 133,
  80. "tid": 2418,
  81. "mid": 131,
  82. "t_type": 1,
  83. "code": "103",
  84. "name": "水泥",
  85. "unit": "m3",
  86. "spec": null,
  87. "m_type": 1,
  88. "quantity": 498.732,
  89. "expr": null,
  90. "basic_price": 236.98,
  91. "basic_times": null,
  92. "msg_tp": 200.69,
  93. "msg_times": "2020-05-09",
  94. "msg_spread": -36.29,
  95. "m_up_risk": 5,
  96. "m_down_risk": 5,
  97. "m_spread": -24.441,
  98. "pre_tp": -3770872.11,
  99. "remark": null,
  100. "in_time": "2020-05-08T08:09:34.000Z",
  101. "tp": -12189.51,
  102. "t_type_str": "消耗量",
  103. "m_type_str": "分类",
  104. "end_tp": -3783061.62
  105. },
  106. {
  107. "id": 134,
  108. "tid": 2418,
  109. "mid": 131,
  110. "t_type": 2,
  111. "code": "985",
  112. "name": "汽油",
  113. "unit": "kg",
  114. "spec": null,
  115. "m_type": 1,
  116. "quantity": 1170.1512,
  117. "expr": "bqwc/10000*12",
  118. "basic_price": 4.9,
  119. "basic_times": null,
  120. "msg_tp": 6.2,
  121. "msg_times": "2020-05-08",
  122. "msg_spread": 1.3,
  123. "m_up_risk": 3,
  124. "m_down_risk": 3,
  125. "m_spread": 1.153,
  126. "pre_tp": null,
  127. "remark": null,
  128. "in_time": "2020-05-08T08:09:36.000Z",
  129. "tp": 1349.18,
  130. "t_type_str": "费用",
  131. "m_type_str": "分类",
  132. "end_tp": 1349.18
  133. }
  134. ];
  135. const result = yield ctx.service.reportMemory.getMaterialGl(2418, 2);
  136. //yield ctx.helper.saveBufferFile(JSON.stringify(result, "", "\t"), path.join(savePath, 'mem-material-gl.json'));
  137. assert(result.length === 4);
  138. assert(checkData(result[0], checkResult[0]));
  139. assert(checkData(result[1], checkResult[1]));
  140. assert(checkData(result[2], checkResult[2]));
  141. assert(checkData(result[3], checkResult[3]));
  142. });
  143. });