forked from Imfdj/egg-beehive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenus.test.js
100 lines (93 loc) · 2.9 KB
/
menus.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
const { assert, app } = require('egg-mock/bootstrap');
describe('test/app/controller/menus.test.js', () => {
const createMenuName = 'menuName' + Math.random();
let createMenuData = {};
before(async () => {});
describe('POST /api/v1/menus', () => {
it('should work', async () => {
app.mockCsrf();
app.mockCookies({ EGG_SESS: app.__cookies });
const res = await app.httpRequest()
.post('/api/v1/menus')
.set('authorization', app.__authorization)
.send({
name: createMenuName,
parent_id: 0,
component: createMenuName,
});
assert(res.status === 201);
assert(res.body.code === 0);
});
});
describe('GET /api/v1/menus/list', () => {
it('should work', async () => {
app.mockCookies({ EGG_SESS: app.__cookies });
const res = await app.httpRequest()
.get('/api/v1/menus/list')
.query({ limit: 2, name: createMenuName })
.set('authorization', app.__authorization);
assert(res.status === 200);
assert(res.body.data);
createMenuData = res.body.data.rows[0];
assert(res.body.code === 0);
});
});
describe('GET /api/v1/menus', () => {
it('should work', async () => {
app.mockCookies({ EGG_SESS: app.__cookies });
const res = await app.httpRequest()
.get('/api/v1/menus')
.query({ id: createMenuData.id })
.set('authorization', app.__authorization);
assert(res.status === 200);
assert(res.body.data);
createMenuData = res.body.data;
assert(res.body.code === 0);
});
});
describe('PUT /api/v1/menus', () => {
it('should work', async () => {
app.mockCsrf();
app.mockCookies({ EGG_SESS: app.__cookies });
const res = await app
.httpRequest()
.put('/api/v1/menus')
.set('authorization', app.__authorization)
.send({
id: createMenuData.id,
name: createMenuData.name + 1,
parent_id: 0,
component: createMenuName,
});
assert(res.status === 201);
assert(res.body.code === 0);
});
});
describe('GET /api/v1/menus/user_menus', () => {
it('should work', async () => {
app.mockCookies({ EGG_SESS: app.__cookies });
const res = await app.httpRequest()
.get('/api/v1/menus/user_menus')
.query({})
.set('authorization', app.__authorization);
assert(res.status === 200);
assert(res.body.data);
assert(res.body.code === 0);
});
});
describe('DELETE /api/v1/menus', () => {
it('should work', async () => {
app.mockCsrf();
app.mockCookies({ EGG_SESS: app.__cookies });
const res = await app
.httpRequest()
.delete('/api/v1/menus')
.set('authorization', app.__authorization)
.send({
ids: [createMenuData.id],
});
assert(res.status === 204);
});
});
});