report_memory.test.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. const mockData = {};
  11. describe('test/app/service/report_memory.test.js', () => {
  12. // 准备测试数据
  13. before(function* () {
  14. const ctx = app.mockContext();
  15. // 模拟登录session
  16. const postData = {
  17. account: '734406061@qq.com',
  18. project: 'T201711273363',
  19. project_password: 'mai654321',
  20. };
  21. // const postData = {
  22. // account: 'chente',
  23. // project: 'T201711273363',
  24. // project_password: '123456',
  25. // };
  26. ctx.session = {};
  27. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  28. assert(loginResult);
  29. mockData.session = ctx.session;
  30. });
  31. // 中间计量表数据 - 台账
  32. it('test getStageImTzData & getStageImTzBillsData', function* () {
  33. const ctx = app.mockContext(mockData);
  34. // test12 - 第6期
  35. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  36. const mainData = yield ctx.service.reportMemory.getStageImTzData(12, stage.id);
  37. const billsData = yield ctx.service.reportMemory.getStageImTzBillsData(12, stage.id);
  38. if (mainData instanceof Array) {
  39. console.log('mem_stage_im_tz.length:' + mainData.length);
  40. yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz.json');
  41. }
  42. if (billsData instanceof Array) {
  43. console.log('mem_stage_im_tz_bills.length:' + billsData.length);
  44. yield ctx.helper.saveBufferFile(JSON.stringify(billsData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz_bills.json');
  45. }
  46. });
  47. // 中间计量表数据 - 总量
  48. it('test getStageImZlData', function* () {
  49. const ctx = app.mockContext(mockData);
  50. // test12 - 第6期
  51. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  52. const mainData = yield ctx.service.reportMemory.getStageImZlData(12, stage.id);
  53. if (mainData instanceof Array) {
  54. yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_im_zl.json');
  55. }
  56. });
  57. // 月进度数据
  58. it('test getMonthProgress', function* () {
  59. const ctx = app.mockContext(mockData);
  60. // test12
  61. const mainData = yield ctx.service.reportMemory.getMonthProgress(12);
  62. if (mainData instanceof Array) {
  63. yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_month_progress.json');
  64. }
  65. });
  66. // 月进度数据
  67. it('test getStageBills', function* () {
  68. const ctx = app.mockContext(mockData);
  69. // test12 - 第6期
  70. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  71. const mainData = yield ctx.service.reportMemory.getStageBillsData(12, stage.id);
  72. if (mainData instanceof Array) {
  73. yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_bills.json');
  74. }
  75. });
  76. // 月进度数据
  77. it('test getStagePos', function* () {
  78. const ctx = app.mockContext(mockData);
  79. // test12 - 第6期
  80. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  81. const mainData = yield ctx.service.reportMemory.getStagePosData(12, stage.id);
  82. if (mainData instanceof Array) {
  83. yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_pos.json');
  84. }
  85. });
  86. });