/test/controller/api/preview.test.js

https://github.com/macacajs/macaca-datahub · JavaScript · 57 lines · 51 code · 6 blank · 0 comment · 0 complexity · f6a90c903b8406563a4c141ee473169a MD5 · raw file

  1. 'use strict';
  2. const {
  3. app,
  4. assert,
  5. } = require('egg-mock/bootstrap');
  6. describe('test/app/controller/api/preivew.test.js', () => {
  7. let ctx;
  8. beforeEach(async () => {
  9. ctx = app.mockContext();
  10. });
  11. it('GET /api/preview/scene preview scene data', async () => {
  12. const [{ uniqId: projectUniqId }] = await ctx.model.Project.bulkCreate([
  13. { projectName: 'baz', description: 'bazd' },
  14. ]);
  15. const [{ uniqId: interfaceUniqId }] = await ctx.model.Interface.bulkCreate([
  16. { projectUniqId, pathname: 'api/path', method: 'ALL', description: 'description' },
  17. ]);
  18. await app.httpRequest()
  19. .post('/api/scene/')
  20. .send({
  21. interfaceUniqId,
  22. sceneName: 'waldo',
  23. contextConfig: {},
  24. data: { success: true },
  25. });
  26. const { body: createBody } = await app.httpRequest()
  27. .get(`/api/preview/scene?interfaceUniqId=${interfaceUniqId}&sceneName=waldo`);
  28. assert.deepStrictEqual(createBody, {
  29. success: true,
  30. });
  31. });
  32. it('GET /api/preview/scene preview scene data fail', async () => {
  33. const [{ uniqId: projectUniqId }] = await ctx.model.Project.bulkCreate([
  34. { projectName: 'baz', description: 'bazd' },
  35. ]);
  36. const [{ uniqId: interfaceUniqId }] = await ctx.model.Interface.bulkCreate([
  37. { projectUniqId, pathname: 'api/path', method: 'ALL', description: 'description' },
  38. ]);
  39. await app.httpRequest()
  40. .post('/api/scene/')
  41. .send({
  42. interfaceUniqId,
  43. sceneName: 'waldo',
  44. contextConfig: {},
  45. data: { success: true },
  46. });
  47. const body = await app.httpRequest()
  48. .get(`/api/preview/scene?interfaceUniqId=${interfaceUniqId}&sceneName=waldo1`);
  49. assert(body.status === 204);
  50. });
  51. });