refactor(接口测试): 接口存在多个版本时不能通过创建接口创建

--user=郭雨琦
This commit is contained in:
guoyuqi 2022-07-21 15:00:58 +08:00 committed by xiaomeinvG
parent f8a132e9b3
commit dda795dcc4
6 changed files with 76 additions and 65 deletions

View File

@ -65,4 +65,6 @@ public class SaveApiScenarioRequest {
private String environmentGroupId; private String environmentGroupId;
private String versionId; private String versionId;
private Boolean newCreate;
} }

View File

@ -83,4 +83,7 @@ public class SaveApiDefinitionRequest {
//发送信息给场景创建人 //发送信息给场景创建人
private Boolean scenarioCreator; private Boolean scenarioCreator;
//是否新建
private Boolean newCreate;
} }

View File

@ -270,6 +270,7 @@ public class ApiAutomationService {
msScenario.setHashTree(new LinkedList<>()); msScenario.setHashTree(new LinkedList<>());
request.setScenarioDefinition(msScenario); request.setScenarioDefinition(msScenario);
} }
request.setNewCreate(true);
checkNameExist(request, false); checkNameExist(request, false);
int nextNum = getNextNum(request.getProjectId()); int nextNum = getNextNum(request.getProjectId());
if (StringUtils.isBlank(request.getCustomNum())) { if (StringUtils.isBlank(request.getCustomNum())) {
@ -724,7 +725,7 @@ public class ApiAutomationService {
} else { } else {
criteria.andApiScenarioModuleIdEqualTo(request.getApiScenarioModuleId()); criteria.andApiScenarioModuleIdEqualTo(request.getApiScenarioModuleId());
} }
if (apiScenarioMapper.countByExample(example) > 0 && StringUtils.isBlank(request.getId())) { if (apiScenarioMapper.countByExample(example) > 0 && request.getNewCreate() != null && request.getNewCreate()) {
MSException.throwException(Translator.get("automation_versions_create")); MSException.throwException(Translator.get("automation_versions_create"));
} }
criteria.andVersionIdEqualTo(request.getVersionId()); criteria.andVersionIdEqualTo(request.getVersionId());

View File

@ -361,6 +361,7 @@ public class ApiDefinitionService {
} else { } else {
FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles); FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles);
} }
request.setNewCreate(true);
return createTest(request); return createTest(request);
} }
@ -634,7 +635,7 @@ public class ApiDefinitionService {
criteria.andModuleIdEqualTo(request.getModuleId()); criteria.andModuleIdEqualTo(request.getModuleId());
} }
criteria.andNameEqualTo(request.getName()); criteria.andNameEqualTo(request.getName());
if (apiDefinitionMapper.countByExample(example) > 0 && StringUtils.isBlank(request.getId())) { if (apiDefinitionMapper.countByExample(example) > 0 && request.getNewCreate() != null && request.getNewCreate()) {
MSException.throwException(Translator.get("api_versions_create")); MSException.throwException(Translator.get("api_versions_create"));
} }
criteria.andVersionIdEqualTo(request.getVersionId()); criteria.andVersionIdEqualTo(request.getVersionId());
@ -642,7 +643,7 @@ public class ApiDefinitionService {
MSException.throwException(Translator.get("api_definition_name_not_repeating") + " :" + Translator.get("api_definition_module") + ":" + request.getModulePath() + " ," + Translator.get("api_definition_name") + " :" + request.getName() + "-" + request.getPath()); MSException.throwException(Translator.get("api_definition_name_not_repeating") + " :" + Translator.get("api_definition_module") + ":" + request.getModulePath() + " ," + Translator.get("api_definition_name") + " :" + request.getName() + "-" + request.getPath());
} }
} else { } else {
if (apiDefinitionMapper.countByExample(example) > 0 && StringUtils.isBlank(request.getId())) { if (apiDefinitionMapper.countByExample(example) > 0 && request.getNewCreate() != null && request.getNewCreate()) {
MSException.throwException(Translator.get("api_versions_create")); MSException.throwException(Translator.get("api_versions_create"));
} }
criteria.andVersionIdEqualTo(request.getVersionId()); criteria.andVersionIdEqualTo(request.getVersionId());
@ -659,7 +660,7 @@ public class ApiDefinitionService {
} else { } else {
criteria.andModuleIdEqualTo(request.getModuleId()); criteria.andModuleIdEqualTo(request.getModuleId());
} }
if (apiDefinitionMapper.countByExample(example) > 0 && StringUtils.isBlank(request.getId())) { if (apiDefinitionMapper.countByExample(example) > 0 && request.getNewCreate() != null && request.getNewCreate()) {
MSException.throwException(Translator.get("api_versions_create")); MSException.throwException(Translator.get("api_versions_create"));
} }
criteria.andVersionIdEqualTo(request.getVersionId()); criteria.andVersionIdEqualTo(request.getVersionId());

View File

@ -419,6 +419,7 @@ export default {
} }
if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') { if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {
apiCase.request = JSON.parse(apiCase.request); apiCase.request = JSON.parse(apiCase.request);
if (apiCase.request.protocol === 'HTTP') {
if (!apiCase.request.body) { if (!apiCase.request.body) {
apiCase.request.body = new Body(); apiCase.request.body = new Body();
} }
@ -442,6 +443,7 @@ export default {
]; ];
} }
} }
}
if (!apiCase.request.hashTree) { if (!apiCase.request.hashTree) {
apiCase.request.hashTree = []; apiCase.request.hashTree = [];
} }

View File

@ -676,6 +676,7 @@ export default {
item.tags = JSON.parse(item.tags); item.tags = JSON.parse(item.tags);
} }
item.caseTotal = parseInt(item.caseTotal); item.caseTotal = parseInt(item.caseTotal);
if (item.protocol === 'HTTP') {
if (!item.response) { if (!item.response) {
let response = {headers: [], body: new Body(), statusCode: [], type: "HTTP"}; let response = {headers: [], body: new Body(), statusCode: [], type: "HTTP"};
item.response = JSON.stringify(response); item.response = JSON.stringify(response);
@ -720,6 +721,7 @@ export default {
} }
item.request = JSON.stringify(item.request); item.request = JSON.stringify(item.request);
} }
}
}); });
this.$emit('getTrashApi'); this.$emit('getTrashApi');
if (this.$refs.table) { if (this.$refs.table) {