apitest.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const router = require('express').Router();
  2. const Mock = require();
  3. const wrapper = require('../wrapper');
  4. const { Random } = Mock;
  5. router.post('/create', (req, res) => {
  6. res.json(wrapper('success'));
  7. });
  8. router.get('/list', (req, res) => {
  9. res.json(wrapper(
  10. Mock.mock([
  11. {
  12. testId: 18,
  13. testName: Random.csentence(5, 20),
  14. projectId: 45,
  15. createTime: Random.datetime(),
  16. username: 'ZhaoXR',
  17. url: 'https://zhidao.baidu.com/question/1899892881196615220.html',
  18. params: [{}],
  19. 'method|1': ['get', 'post'],
  20. qps: 150,
  21. },
  22. {
  23. testId: 19,
  24. testName: Random.csentence(5, 20),
  25. projectId: 45,
  26. createTime: Random.datetime(),
  27. username: 'ZhaoXR',
  28. url: 'http://localhost:3000',
  29. params: [{}],
  30. 'method|1': ['get', 'post'],
  31. qps: 30,
  32. },
  33. {
  34. testId: 20,
  35. testName: Random.csentence(5, 20),
  36. projectId: 45,
  37. createTime: Random.datetime(),
  38. username: 'ZhaoXR',
  39. url: 'http://localhost:3000/project/1/apitest',
  40. params: [{}],
  41. 'method|1': ['get', 'post'],
  42. qps: 10,
  43. },
  44. {
  45. testId: 21,
  46. testName: Random.csentence(5, 20),
  47. projectId: 45,
  48. createTime: Random.datetime(),
  49. username: 'ZhaoXR',
  50. url: 'localhost:3000',
  51. params: [{}],
  52. 'method|1': ['get', 'post'],
  53. qps: 20,
  54. },
  55. ]),
  56. ));
  57. });
  58. router.get('/delete', (req, res) => {
  59. res.json(wrapper('success'));
  60. });
  61. router.get('/execute', (req, res) => {
  62. res.json(wrapper('success'));
  63. });
  64. router.get('/result', (req, res) => {
  65. res.json(wrapper(
  66. Mock.mock([
  67. {
  68. id: 11,
  69. testId: 18,
  70. executeTime: Random.datetime(),
  71. success: 20,
  72. failure: 0,
  73. timeList: [3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 2, 3, 3, 2, 4, 3, 2, 2, 4, 4],
  74. maxTime: 6,
  75. minTime: 2,
  76. averageTime: 3,
  77. pipelineRecordId: -1,
  78. },
  79. {
  80. id: 12,
  81. testId: 18,
  82. executeTime: Random.datetime(),
  83. success: 20,
  84. failure: 0,
  85. timeList: [2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 4, 4, 5, 5, 6, 6, 7, 4, 5, 5],
  86. maxTime: 7,
  87. minTime: 2,
  88. averageTime: 4,
  89. pipelineRecordId: -1,
  90. },
  91. ]),
  92. ));
  93. });
  94. router.get('/latest', (req, res) => {
  95. res.json(wrapper(
  96. Mock.mock([
  97. {
  98. id: 12,
  99. testId: 18,
  100. executeTime: Random.datetime(),
  101. success: 20,
  102. failure: 0,
  103. timeList: [2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 4, 4, 5, 5, 6, 6, 7, 4, 5, 5],
  104. maxTime: 7,
  105. minTime: 2,
  106. averageTime: 4,
  107. pipelineRecordId: -1,
  108. },
  109. ]),
  110. ));
  111. });
  112. module.exports = router;