report_memory.test.js 2.3 KB

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