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

Method upCase

server/controllers/interfaceCol.js:559–608  ·  view source on GitHub ↗

* 更新一个测试用例 * @interface /col/up_case * @method POST * @category col * @foldnumber 10 * @param {number} id * @param {String} casename * @param {String} domain * @param {String} path * @param {String} method * @param {Object} req_query * @param {Object} req_

(ctx)

Source from the content-addressed store, hash-verified

557 */
558
559 async upCase(ctx) {
560 try {
561 let params = ctx.request.body;
562 params = yapi.commons.handleParams(params, {
563 id: 'number',
564 casename: 'string'
565 });
566
567 if (!params.id) {
568 return (ctx.body = yapi.commons.resReturn(null, 400, '用例id不能为空'));
569 }
570
571 // if (!params.casename) {
572 // return (ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空'));
573 // }
574
575 let caseData = await this.caseModel.get(params.id);
576 let auth = await this.checkAuth(caseData.project_id, 'project', 'edit');
577 if (!auth) {
578 return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限'));
579 }
580
581 params.uid = this.getUid();
582
583 //不允许修改接口id和项目id
584 delete params.interface_id;
585 delete params.project_id;
586 let result = await this.caseModel.up(params.id, params);
587 let username = this.getUsername();
588 this.colModel.get(caseData.col_id).then(col => {
589 yapi.commons.saveLog({
590 content: `<a href="/user/profile/${this.getUid()}">${username}</a> 在接口集 <a href="/project/${
591 caseData.project_id
592 }/interface/col/${caseData.col_id}">${col.name}</a> 更新了测试用例 <a href="/project/${
593 caseData.project_id
594 }/interface/case/${params.id}">${params.casename || caseData.casename}</a>`,
595 type: 'project',
596 uid: this.getUid(),
597 username: username,
598 typeid: caseData.project_id
599 });
600 });
601
602 this.projectModel.up(caseData.project_id, { up_time: new Date().getTime() }).then();
603
604 ctx.body = yapi.commons.resReturn(result);
605 } catch (e) {
606 ctx.body = yapi.commons.resReturn(null, 402, e.message);
607 }
608 }
609
610 /**
611 * 获取一个测试用例详情

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected