Skip to content

Commit 0a84bb7

Browse files
authored
Merge pull request #4 from Lu17301156525/develop
Add new unit test
2 parents 95992c4 + 793a274 commit 0a84bb7

7 files changed

Lines changed: 1068 additions & 0 deletions

File tree

config/config.unittest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import { EggAppConfig, PowerPartial } from 'egg';
1313
export default () => {
1414
const config = {} as PowerPartial<EggAppConfig>;
15+
config.dataCenter = {
16+
host: process.env.DATA_CENTER_URL || 'http://localhost:1337',
17+
sessionKeyPrefix: 'lowcode:data:'
18+
};
1519

1620
return config;
1721
};
Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
import assert from 'power-assert';
2+
import { E_ErrorCode } from '../../../../app/lib/enum';
3+
import { get, post } from '../../utils/request';
4+
5+
let tempPageId = 0;
6+
const appId = 918;
7+
const tempPageRoute = `page-${Date.now()}`;
8+
let tempFolderId = 0;
9+
describe('test/app/controller/app-center/pages.test.ts', () => {
10+
describe('test page create', () => {
11+
it('should created page success', async () => {
12+
const mockData = {
13+
name: `ut_page_${Date.now()}`,
14+
app: appId,
15+
route: tempPageRoute,
16+
isPage: true,
17+
parentId: 1,
18+
group: 'staticPages',
19+
isDefault: false,
20+
isHome: false,
21+
isBody: false,
22+
message: 'create',
23+
page_content: {},
24+
}
25+
return post('/app-center/api/pages/create')
26+
.send(mockData)
27+
.expect(200)
28+
.expect('Content-Type', /json/)
29+
.then((response) => {
30+
const { id, name } = response.body.data;
31+
assert.ok(!response.body.error, 'response.body.error should not be exist');
32+
assert.equal(name, mockData.name);
33+
tempPageId = id;
34+
});
35+
});
36+
37+
it('should created page failed', async () => {
38+
const mockData = {
39+
name: `ut_page_${Date.now()}`,
40+
app: appId,
41+
isPage: true,
42+
parentId: 1,
43+
group: 'staticPages',
44+
isDefault: false,
45+
isHome: false,
46+
isBody: false,
47+
message: 'create',
48+
page_content: {},
49+
}
50+
return post('/app-center/api/pages/create')
51+
.send(mockData)
52+
.expect(200)
53+
.expect('Content-Type', /json/)
54+
.then((response) => {
55+
const { code } = response.body.error;
56+
assert.ok(response.body.error, 'response.body.error should be exist');
57+
assert.equal(code, E_ErrorCode.CM002);
58+
});
59+
});
60+
61+
//创建页面分支测试,isHome为true
62+
it('should created page success', async () => {
63+
const mockData = {
64+
name: `ut_page_${Date.now()}`,
65+
app: appId,
66+
route: tempPageRoute,
67+
isPage: true,
68+
parentId: 1,
69+
group: 'staticPages',
70+
isDefault: false,
71+
isHome: true,
72+
isBody: false,
73+
message: 'create',
74+
page_content: {},
75+
}
76+
return post('/app-center/api/pages/create')
77+
.send(mockData)
78+
.expect(200)
79+
.expect('Content-Type', /json/)
80+
.then((response) => {
81+
const { code } = response.body.error;
82+
assert.ok(response.body.error, 'response.body.error should not be exist');
83+
assert.equal(code, E_ErrorCode.CM002);
84+
});
85+
});
86+
87+
//创建页面分支测试,isHome为true且parentId为0
88+
it('should created page success', async () => {
89+
const mockData = {
90+
name: `ut_page_${Date.now()}`,
91+
app: appId,
92+
route: tempPageRoute,
93+
isPage: true,
94+
parentId: 0,
95+
group: 'staticPages',
96+
isDefault: false,
97+
isHome: true,
98+
isBody: false,
99+
message: 'create',
100+
page_content: {},
101+
}
102+
return post('/app-center/api/pages/create')
103+
.send(mockData)
104+
.expect(200)
105+
.expect('Content-Type', /json/)
106+
.then((response) => {
107+
const { route } = response.body.data;
108+
assert.ok(!response.body.error, 'response.body.error should not be exist');
109+
assert.equal(route, mockData.route);
110+
});
111+
});
112+
113+
it('should created folder success', async () => {
114+
const mockData = {
115+
name: `ut_folder_${Date.now()}`,
116+
app: appId,
117+
route: `ut_route_${Date.now()}`,
118+
isPage: false,
119+
parentId: 0,
120+
}
121+
return post('/app-center/api/pages/create')
122+
.send(mockData)
123+
.expect(200)
124+
.expect('Content-Type', /json/)
125+
.then((response) => {
126+
const { id, name } = response.body.data;
127+
assert.ok(!response.body.error, 'response.body.error should not be exist');
128+
assert.equal(name, mockData.name);
129+
tempFolderId = id;
130+
});
131+
})
132+
133+
it('should created folder failed', async () => {
134+
const mockData = {
135+
name: `ut_folder_${Date.now()}`,
136+
app: appId,
137+
isPage: false,
138+
parentId: 0,
139+
}
140+
return post('/app-center/api/pages/create')
141+
.send(mockData)
142+
.expect(200)
143+
.expect('Content-Type', /json/)
144+
.then((response) => {
145+
const { code } = response.body.error;
146+
assert.ok(response.body.error, 'response.body.error should be exist');
147+
assert.equal(code, E_ErrorCode.CM002);
148+
});
149+
});
150+
})
151+
152+
describe('test code|metadata|schema2code', () => {
153+
// 获取页面或者区块代码
154+
it('should get dslcode success', async () => {
155+
return get(`/app-center/api/code?id=${tempPageId}&app=${appId}&type=Page`)
156+
.expect(200)
157+
.expect('Content-Type', /json/)
158+
.then((response) => {
159+
const { panelType } = response.body.data[0];
160+
assert.ok(!response.body.error, 'response.body.error should not be exist');
161+
assert.equal(panelType, 'vue');
162+
});
163+
})
164+
165+
it('should get dslcode failed', async () => {
166+
return get(`/app-center/api/code?id=${tempPageId}&app=abc&type=Page`)
167+
.expect(200)
168+
.expect('Content-Type', /json/)
169+
.then((response) => {
170+
const { code } = response.body.error;
171+
assert.ok(response.body.error, 'response.body.error should be exist');
172+
assert.equal(code, E_ErrorCode.CM002);
173+
});
174+
})
175+
176+
// 获取预览元数据
177+
it('should get preview metadata success', async () => {
178+
return get(`/app-center/api/preview/metadata?id=${tempPageId}&app=${appId}&type=Page`)
179+
.expect(200)
180+
.expect('Content-Type', /json/)
181+
.then((response) => {
182+
assert.ok(!response.body.error, 'response.body.error should not be exist');
183+
assert.ok(response.body.data, 'response.body.data should be exist');
184+
});
185+
})
186+
187+
it('should get preview metadata failed', async () => {
188+
return get(`/app-center/api/preview/metadata?id=${tempPageId}&app=abc&type=Page`)
189+
.expect(200)
190+
.expect('Content-Type', /json/)
191+
.then((response) => {
192+
const { code } = response.body.error;
193+
assert.ok(response.body.error, 'response.body.error should be exist');
194+
assert.equal(code, E_ErrorCode.CM009);
195+
});
196+
})
197+
198+
// 获取页面代码
199+
it('should get schema2code success', async () => {
200+
const mockData = {
201+
app: appId,
202+
pageInfo: {
203+
schema: {},
204+
name: 'createVm',
205+
},
206+
}
207+
return post('/app-center/api/schema2code')
208+
.send(mockData)
209+
.expect(200)
210+
.expect('Content-Type', /json/)
211+
.then((response) => {
212+
const { panelType } = response.body.data[0];
213+
assert.ok(!response.body.error, 'response.body.error should not be exist');
214+
assert.equal(panelType, 'vue');
215+
});
216+
})
217+
218+
it('should get schema2code failed', async () => {
219+
const mockData = {
220+
app: appId,
221+
pageInfo: 'test',
222+
}
223+
return post('/app-center/api/schema2code')
224+
.send(mockData)
225+
.expect(200)
226+
.expect('Content-Type', /json/)
227+
.then((response) => {
228+
const { code } = response.body.error;
229+
assert.ok(response.body.error, 'response.body.error should be exist');
230+
assert.equal(code, E_ErrorCode.CM002);
231+
});
232+
})
233+
})
234+
235+
describe('test list|detail|update|delete', () => {
236+
const updateBody = {
237+
route: `ut_route${Date.now()}`
238+
};
239+
it('should get page list success', async () => {
240+
return get(`/app-center/api/pages/list/${appId}`)
241+
.expect(200)
242+
.expect('Content-Type', /json/)
243+
.then((response) => {
244+
const { data } = response.body;
245+
assert.ok(!response.body.error, 'response.body.error should not be exist');
246+
assert.equal(Array.isArray(data), true);
247+
});
248+
})
249+
250+
it('should get page list failed', async () => {
251+
return get('/app-center/api/pages/list/abc')
252+
.expect(200)
253+
.expect('Content-Type', /json/)
254+
.then((response) => {
255+
const { code } = response.body.error;
256+
assert.ok(response.body.error, 'response.body.error should be exist');
257+
assert.equal(code, E_ErrorCode.CM002);
258+
});
259+
})
260+
261+
it('should update page success', async () => {
262+
return post(`/app-center/api/pages/update/${tempPageId}`)
263+
.send(updateBody)
264+
.expect(200)
265+
.expect('Content-Type', /json/)
266+
.then((response) => {
267+
const { route } = response.body.data;
268+
assert.ok(!response.body.error, 'response.body.error should not be exist');
269+
assert.equal(route, updateBody.route);
270+
});
271+
})
272+
273+
it('should update page failed', async () => {
274+
return post('/app-center/api/pages/update/abc')
275+
.send(updateBody)
276+
.expect(200)
277+
.expect('Content-Type', /json/)
278+
.then((response) => {
279+
const { code } = response.body.error;
280+
assert.ok(response.body.error, 'response.body.error should be exist');
281+
assert.equal(code, E_ErrorCode.CM002);
282+
});
283+
})
284+
285+
it('should update folder success', async () => {
286+
return post(`/app-center/api/pages/update/${tempFolderId}`)
287+
.send(updateBody)
288+
.expect(200)
289+
.expect('Content-Type', /json/)
290+
.then((response) => {
291+
const { route } = response.body.data;
292+
assert.ok(!response.body.error, 'response.body.error should not be exist');
293+
assert.equal(route, updateBody.route);
294+
});
295+
})
296+
297+
it('shoud get page detail success', async () => {
298+
return get(`/app-center/api/pages/detail/${tempPageId}`)
299+
.expect(200)
300+
.expect('Content-Type', /json/)
301+
.then((response) => {
302+
const { id } = response.body.data;
303+
assert.ok(!response.body.error, 'response.body.error should not be exist');
304+
assert.equal(id, tempPageId);
305+
});
306+
})
307+
308+
it('shoud get page detail failed', async () => {
309+
return get('/app-center/api/pages/detail/abc')
310+
.expect(200)
311+
.expect('Content-Type', /json/)
312+
.then((response) => {
313+
const { code } = response.body.error;
314+
assert.ok(response.body.error, 'response.body.error should be exist');
315+
assert.equal(code, E_ErrorCode.CM002);
316+
});
317+
})
318+
319+
it('shoud deleted page success', async () => {
320+
return get(`/app-center/api/pages/delete/${tempPageId}`)
321+
.expect(200)
322+
.expect('Content-Type', /json/)
323+
.then((response) => {
324+
const { id } = response.body.data;
325+
assert.ok(!response.body.error, 'response.body.error should not be exist');
326+
assert.equal(id, tempPageId);
327+
});
328+
})
329+
330+
it('shoud deleted page failed', async () => {
331+
return get('/app-center/api/pages/delete/abc')
332+
.expect(200)
333+
.expect('Content-Type', /json/)
334+
.then((response) => {
335+
const { code } = response.body.error;
336+
assert.ok(response.body.error, 'response.body.error should be exist');
337+
assert.equal(code, E_ErrorCode.CM002);
338+
});
339+
})
340+
})
341+
342+
})

0 commit comments

Comments
 (0)