fix(接口测试): 接口调试重命名校验有误

--bug=1037016 --user=陈建星 【接口测试】接口调试-新建请求-当前账号未创建过请求,却报错提示请求已存在 https://www.tapd.cn/55049933/s/1474547
This commit is contained in:
AgAngle 2024-03-14 15:35:04 +08:00 committed by Craftsman
parent 263317e3c4
commit 4053e5c206
7 changed files with 13 additions and 14 deletions

View File

@ -252,7 +252,7 @@ public class ApiTestCaseController {
} }
@GetMapping("/run/{id}/{reportId}") @GetMapping("/run/{id}/{reportId}")
@Operation(summary = "用例执行,获取获取执行结果") @Operation(summary = "用例执行,实时获取执行结果")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE)
public TaskRequestDTO run(@PathVariable String id, @PathVariable String reportId) { public TaskRequestDTO run(@PathVariable String id, @PathVariable String reportId) {
return apiTestCaseService.run(id, reportId, SessionUtils.getUserId()); return apiTestCaseService.run(id, reportId, SessionUtils.getUserId());

View File

@ -32,9 +32,4 @@ public class WWWFormKV extends KeyValueEnableParam {
* 最大长度 * 最大长度
*/ */
private Integer maxLength; private Integer maxLength;
/**
* 是否对参数进行编码
* 默认 false
*/
private Boolean encode = false;
} }

View File

@ -165,6 +165,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
/** /**
* 添加场景和环境变量 * 添加场景和环境变量
*
* @param msHTTPElement * @param msHTTPElement
* @param envInfo * @param envInfo
*/ */

View File

@ -51,7 +51,6 @@ public abstract class MsBodyConverter<T> {
value = StringUtils.EMPTY; value = StringUtils.EMPTY;
} }
HTTPArgument httpArgument = new HTTPArgument(kv.getKey(), value); HTTPArgument httpArgument = new HTTPArgument(kv.getKey(), value);
httpArgument.setAlwaysEncoded(kv.getEncode());
arguments.addArgument(httpArgument); arguments.addArgument(httpArgument);
if (kv instanceof FormDataKV formDataKV && formDataKV.getContentType() != null) { if (kv instanceof FormDataKV formDataKV && formDataKV.getContentType() != null) {
httpArgument.setContentType(formDataKV.getContentType()); httpArgument.setContentType(formDataKV.getContentType());

View File

@ -97,7 +97,7 @@ public class ApiDebugService extends MoveNodeService {
ApiDebug apiDebug = new ApiDebug(); ApiDebug apiDebug = new ApiDebug();
BeanUtils.copyBean(apiDebug, request); BeanUtils.copyBean(apiDebug, request);
apiDebug.setCreateUser(createUser); apiDebug.setCreateUser(createUser);
checkAddExist(apiDebug); checkAddExist(apiDebug, createUser);
apiDebug.setId(IDGenerator.nextStr()); apiDebug.setId(IDGenerator.nextStr());
apiDebug.setCreateTime(System.currentTimeMillis()); apiDebug.setCreateTime(System.currentTimeMillis());
apiDebug.setUpdateTime(System.currentTimeMillis()); apiDebug.setUpdateTime(System.currentTimeMillis());
@ -141,7 +141,7 @@ public class ApiDebugService extends MoveNodeService {
checkResourceExist(request.getId()); checkResourceExist(request.getId());
ApiDebug apiDebug = BeanUtils.copyBean(new ApiDebug(), request); ApiDebug apiDebug = BeanUtils.copyBean(new ApiDebug(), request);
ApiDebug originApiDebug = apiDebugMapper.selectByPrimaryKey(request.getId()); ApiDebug originApiDebug = apiDebugMapper.selectByPrimaryKey(request.getId());
checkUpdateExist(apiDebug, originApiDebug); checkUpdateExist(apiDebug, originApiDebug, updateUser);
apiDebug.setUpdateUser(updateUser); apiDebug.setUpdateUser(updateUser);
apiDebug.setUpdateTime(System.currentTimeMillis()); apiDebug.setUpdateTime(System.currentTimeMillis());
apiDebugMapper.updateByPrimaryKeySelective(apiDebug); apiDebugMapper.updateByPrimaryKeySelective(apiDebug);
@ -179,23 +179,25 @@ public class ApiDebugService extends MoveNodeService {
apiDebugBlobMapper.deleteByPrimaryKey(id); apiDebugBlobMapper.deleteByPrimaryKey(id);
} }
private void checkAddExist(ApiDebug apiDebug) { private void checkAddExist(ApiDebug apiDebug, String userId) {
ApiDebugExample example = new ApiDebugExample(); ApiDebugExample example = new ApiDebugExample();
example.createCriteria() example.createCriteria()
.andNameEqualTo(apiDebug.getName()) .andNameEqualTo(apiDebug.getName())
.andCreateUserEqualTo(userId)
.andModuleIdEqualTo(apiDebug.getModuleId()); .andModuleIdEqualTo(apiDebug.getModuleId());
if (CollectionUtils.isNotEmpty(apiDebugMapper.selectByExample(example))) { if (CollectionUtils.isNotEmpty(apiDebugMapper.selectByExample(example))) {
throw new MSException(API_DEBUG_EXIST); throw new MSException(API_DEBUG_EXIST);
} }
} }
private void checkUpdateExist(ApiDebug apiDebug, ApiDebug originApiDebug) { private void checkUpdateExist(ApiDebug apiDebug, ApiDebug originApiDebug, String userId) {
if (StringUtils.isBlank(apiDebug.getName())) { if (StringUtils.isBlank(apiDebug.getName())) {
return; return;
} }
ApiDebugExample example = new ApiDebugExample(); ApiDebugExample example = new ApiDebugExample();
example.createCriteria() example.createCriteria()
.andIdNotEqualTo(apiDebug.getId()) .andIdNotEqualTo(apiDebug.getId())
.andCreateUserEqualTo(userId)
.andModuleIdEqualTo(apiDebug.getModuleId() == null ? originApiDebug.getModuleId() : apiDebug.getModuleId()) .andModuleIdEqualTo(apiDebug.getModuleId() == null ? originApiDebug.getModuleId() : apiDebug.getModuleId())
.andNameEqualTo(apiDebug.getName()); .andNameEqualTo(apiDebug.getName());
if (CollectionUtils.isNotEmpty(apiDebugMapper.selectByExample(example))) { if (CollectionUtils.isNotEmpty(apiDebugMapper.selectByExample(example))) {
@ -238,7 +240,7 @@ public class ApiDebugService extends MoveNodeService {
if (!StringUtils.equals(request.getModuleId(), apiDebug.getModuleId())) { if (!StringUtils.equals(request.getModuleId(), apiDebug.getModuleId())) {
checkModuleExist(request.getModuleId()); checkModuleExist(request.getModuleId());
apiDebug.setModuleId(request.getModuleId()); apiDebug.setModuleId(request.getModuleId());
checkUpdateExist(apiDebug, apiDebug); checkUpdateExist(apiDebug, apiDebug, userId);
apiDebug.setUpdateUser(userId); apiDebug.setUpdateUser(userId);
apiDebug.setUpdateTime(System.currentTimeMillis()); apiDebug.setUpdateTime(System.currentTimeMillis());
apiDebugMapper.updateByPrimaryKeySelective(apiDebug); apiDebugMapper.updateByPrimaryKeySelective(apiDebug);

View File

@ -205,6 +205,9 @@ public class ApiDebugControllerTests extends BaseTest {
assertUploadFile(resultData.getId(), List.of(uploadFileId)); assertUploadFile(resultData.getId(), List.of(uploadFileId));
assertLinkFile(resultData.getId(), List.of(fileMetadataId)); assertLinkFile(resultData.getId(), List.of(fileMetadataId));
// 校验不同用户的重名校验
apiDebugService.add(request, "userA");
// 再插入一条数据便于修改时重名校验 // 再插入一条数据便于修改时重名校验
request.setName("test1"); request.setName("test1");
request.setUploadFileIds(null); request.setUploadFileIds(null);
@ -251,6 +254,7 @@ public class ApiDebugControllerTests extends BaseTest {
request.setUnLinkFileIds(List.of(fileMetadataId)); request.setUnLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(List.of(uploadFileId)); request.setDeleteFileIds(List.of(uploadFileId));
this.requestPostWithOk(DEFAULT_UPDATE, request); this.requestPostWithOk(DEFAULT_UPDATE, request);
// 校验请求成功数据 // 校验请求成功数据
assertUpdateApiDebug(request, msHttpElement, request.getId()); assertUpdateApiDebug(request, msHttpElement, request.getId());
assertUploadFile(addApiDebug.getId(), List.of()); assertUploadFile(addApiDebug.getId(), List.of());

View File

@ -15,7 +15,6 @@ import io.metersphere.api.parser.TestElementParserFactory;
import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.dto.ParameterConfig;
import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.api.KeyValueEnableParam;
import io.metersphere.project.api.KeyValueParam; import io.metersphere.project.api.KeyValueParam;
import io.metersphere.project.api.assertion.*; import io.metersphere.project.api.assertion.*;
import io.metersphere.project.api.assertion.body.*; import io.metersphere.project.api.assertion.body.*;
@ -61,7 +60,6 @@ public class MsHTTPElementTest {
FormDataKV formDataKV = new FormDataKV(); FormDataKV formDataKV = new FormDataKV();
formDataKV.setEnable(false); formDataKV.setEnable(false);
formDataKV.setContentType("text/plain"); formDataKV.setContentType("text/plain");
formDataKV.setEncode(true);
formDataKV.setMaxLength(10); formDataKV.setMaxLength(10);
formDataKV.setMinLength(8); formDataKV.setMinLength(8);
formDataKV.setDescription("test"); formDataKV.setDescription("test");