report_controller.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 sourceTypeConst = require('../const/source_type');
  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: 'fuqingqing',
  20. project: 'P0505',
  21. project_password: '123456',
  22. };
  23. // const postData = {
  24. // account: 'chente',
  25. // project: 'T201711273363',
  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: 12, order: 6});
  38. const params = {
  39. tender_id: stage.tid,
  40. stage_id: stage.id,
  41. };
  42. const filters = ['change', 'change_audit_list'];
  43. const result = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters);
  44. const savePath = path.join(ctx.app.baseDir, 'report_temp');
  45. yield ctx.helper.recursiveMkdirSync(savePath);
  46. for (const table in result) {
  47. yield ctx.helper.saveBufferFile(JSON.stringify(result[table],"","\t"), path.join(savePath, table + '.json'));
  48. }
  49. });
  50. });