report.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. const path = require('path');
  12. const reportDataAnalysis = require('../../../app/lib/rpt_data_analysis');
  13. describe('test/app/service/report_memory.test.js', () => {
  14. // 准备测试数据
  15. before(function* () {
  16. const ctx = app.mockContext();
  17. // 模拟登录session
  18. // const postData = {
  19. // account: '734406061@qq.com',
  20. // project: 'T201711273363',
  21. // project_password: 'mai654321',
  22. // };
  23. const postData = {
  24. account: 'fuqingqing',
  25. project: 'P0505',
  26. project_password: '123456',
  27. };
  28. ctx.session = {};
  29. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  30. assert(loginResult);
  31. mockData.session = ctx.session;
  32. });
  33. // 数据
  34. it('test getReportData', function* () {
  35. const ctx = app.mockContext(mockData);
  36. // test12 - 第6期
  37. //const stage = yield ctx.service.stage.getDataByCondition({tid: 2076, order: 2});
  38. const params = {
  39. tender_id: 1977
  40. };
  41. const filters = ['change', 'mem_change_bills'];
  42. const fields = {
  43. change: [],
  44. mem_stage_bills: [],
  45. };
  46. const result = yield ctx.service.report.getReportData(params, filters, fields);
  47. reportDataAnalysis.analysisObj.changeSort.fun(ctx, result, [], {change: "change", changeBills: 'mem_change_bills'});
  48. const savePath = path.join(ctx.app.baseDir, 'report_temp');
  49. yield ctx.helper.recursiveMkdirSync(savePath);
  50. for (const table in result) {
  51. yield ctx.helper.saveBufferFile(JSON.stringify(result[table],"","\t"), path.join(savePath, table + '.json'));
  52. }
  53. });
  54. });