MCPcopy
hub / github.com/YMFE/yapi / addCase

Method addCase

server/controllers/interfaceCol.js:304–362  ·  view source on GitHub ↗

* 增加一个测试用例 * @interface /col/add_case * @method POST * @category col * @foldnumber 10 * @param {String} casename * @param {Number} col_id * @param {Number} project_id * @param {String} domain * @param {String} path * @param {String} method * @param {Object

(ctx)

Source from the content-addressed store, hash-verified

302 */
303
304 async addCase(ctx) {
305 try {
306 let params = ctx.request.body;
307 params = yapi.commons.handleParams(params, {
308 casename: 'string',
309 project_id: 'number',
310 col_id: 'number',
311 interface_id: 'number',
312 case_env: 'string'
313 });
314
315 if (!params.project_id) {
316 return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'));
317 }
318
319 if (!params.interface_id) {
320 return (ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空'));
321 }
322
323 let auth = await this.checkAuth(params.project_id, 'project', 'edit');
324 if (!auth) {
325 return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限'));
326 }
327
328 if (!params.col_id) {
329 return (ctx.body = yapi.commons.resReturn(null, 400, '接口集id不能为空'));
330 }
331
332 if (!params.casename) {
333 return (ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空'));
334 }
335
336 params.uid = this.getUid();
337 params.index = 0;
338 params.add_time = yapi.commons.time();
339 params.up_time = yapi.commons.time();
340 let result = await this.caseModel.save(params);
341 let username = this.getUsername();
342
343 this.colModel.get(params.col_id).then(col => {
344 yapi.commons.saveLog({
345 content: `<a href="/user/profile/${this.getUid()}">${username}</a> 在接口集 <a href="/project/${
346 params.project_id
347 }/interface/col/${params.col_id}">${col.name}</a> 下添加了测试用例 <a href="/project/${
348 params.project_id
349 }/interface/case/${result._id}">${params.casename}</a>`,
350 type: 'project',
351 uid: this.getUid(),
352 username: username,
353 typeid: params.project_id
354 });
355 });
356 this.projectModel.up(params.project_id, { up_time: new Date().getTime() }).then();
357
358 ctx.body = yapi.commons.resReturn(result);
359 } catch (e) {
360 ctx.body = yapi.commons.resReturn(null, 402, e.message);
361 }

Callers

nothing calls this directly

Calls 7

handleParamsMethod · 0.80
getUsernameMethod · 0.80
checkAuthMethod · 0.45
getUidMethod · 0.45
saveMethod · 0.45
getMethod · 0.45
upMethod · 0.45

Tested by

no test coverage detected