report_memory.test.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. });