/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
- 'use strict';
- const {
- app,
- assert,
- } = require('egg-mock/bootstrap');
- describe('test/app/controller/api/preivew.test.js', () => {
- let ctx;
- beforeEach(async () => {
- ctx = app.mockContext();
- });
- it('GET /api/preview/scene preview scene data', async () => {
- const [{ uniqId: projectUniqId }] = await ctx.model.Project.bulkCreate([
- { projectName: 'baz', description: 'bazd' },
- ]);
- const [{ uniqId: interfaceUniqId }] = await ctx.model.Interface.bulkCreate([
- { projectUniqId, pathname: 'api/path', method: 'ALL', description: 'description' },
- ]);
- await app.httpRequest()
- .post('/api/scene/')
- .send({
- interfaceUniqId,
- sceneName: 'waldo',
- contextConfig: {},
- data: { success: true },
- });
- const { body: createBody } = await app.httpRequest()
- .get(`/api/preview/scene?interfaceUniqId=${interfaceUniqId}&sceneName=waldo`);
- assert.deepStrictEqual(createBody, {
- success: true,
- });
- });
- it('GET /api/preview/scene preview scene data fail', async () => {
- const [{ uniqId: projectUniqId }] = await ctx.model.Project.bulkCreate([
- { projectName: 'baz', description: 'bazd' },
- ]);
- const [{ uniqId: interfaceUniqId }] = await ctx.model.Interface.bulkCreate([
- { projectUniqId, pathname: 'api/path', method: 'ALL', description: 'description' },
- ]);
- await app.httpRequest()
- .post('/api/scene/')
- .send({
- interfaceUniqId,
- sceneName: 'waldo',
- contextConfig: {},
- data: { success: true },
- });
- const body = await app.httpRequest()
- .get(`/api/preview/scene?interfaceUniqId=${interfaceUniqId}&sceneName=waldo1`);
- assert(body.status === 204);
- });
- });