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 versionId;
private Boolean newCreate;
}

View File

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

View File

@ -270,6 +270,7 @@ public class ApiAutomationService {
msScenario.setHashTree(new LinkedList<>());
request.setScenarioDefinition(msScenario);
}
request.setNewCreate(true);
checkNameExist(request, false);
int nextNum = getNextNum(request.getProjectId());
if (StringUtils.isBlank(request.getCustomNum())) {
@ -724,7 +725,7 @@ public class ApiAutomationService {
} else {
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"));
}
criteria.andVersionIdEqualTo(request.getVersionId());

View File

@ -361,6 +361,7 @@ public class ApiDefinitionService {
} else {
FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles);
}
request.setNewCreate(true);
return createTest(request);
}
@ -634,7 +635,7 @@ public class ApiDefinitionService {
criteria.andModuleIdEqualTo(request.getModuleId());
}
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"));
}
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());
}
} 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"));
}
criteria.andVersionIdEqualTo(request.getVersionId());
@ -659,7 +660,7 @@ public class ApiDefinitionService {
} else {
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"));
}
criteria.andVersionIdEqualTo(request.getVersionId());

View File

@ -419,27 +419,29 @@ export default {
}
if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {
apiCase.request = JSON.parse(apiCase.request);
if (!apiCase.request.body) {
apiCase.request.body = new Body();
}
if (!apiCase.request.headers) {
apiCase.request.headers = [];
}
if (!apiCase.request.rest) {
apiCase.request.rest = [];
}
if (!apiCase.request.arguments) {
apiCase.request.arguments = [
{
contentType: "text/plain",
enable: true,
file: false,
required: false,
type: "text",
urlEncode: false,
valid: false
}
];
if (apiCase.request.protocol === 'HTTP') {
if (!apiCase.request.body) {
apiCase.request.body = new Body();
}
if (!apiCase.request.headers) {
apiCase.request.headers = [];
}
if (!apiCase.request.rest) {
apiCase.request.rest = [];
}
if (!apiCase.request.arguments) {
apiCase.request.arguments = [
{
contentType: "text/plain",
enable: true,
file: false,
required: false,
type: "text",
urlEncode: false,
valid: false
}
];
}
}
}
if (!apiCase.request.hashTree) {

View File

@ -676,49 +676,51 @@ export default {
item.tags = JSON.parse(item.tags);
}
item.caseTotal = parseInt(item.caseTotal);
if (!item.response) {
let response = {headers: [], body: new Body(), statusCode: [], type: "HTTP"};
item.response = JSON.stringify(response);
}
if (item.response) {
item.response = JSON.parse(item.response);
if (!item.response.body) {
item.response.body = new Body();
if (item.protocol === 'HTTP') {
if (!item.response) {
let response = {headers: [], body: new Body(), statusCode: [], type: "HTTP"};
item.response = JSON.stringify(response);
}
if (!item.response.headers) {
item.response.headers = [];
if (item.response) {
item.response = JSON.parse(item.response);
if (!item.response.body) {
item.response.body = new Body();
}
if (!item.response.headers) {
item.response.headers = [];
}
if (!item.response.statusCode) {
item.response.statusCode = [];
}
item.response = JSON.stringify(item.response);
}
if (!item.response.statusCode) {
item.response.statusCode = [];
//request
if (item.request) {
item.request = JSON.parse(item.request);
if (!item.request.body) {
item.request.body = new Body();
}
if (!item.request.headers) {
item.request.headers = [];
}
if (!item.request.rest) {
item.request.rest = [];
}
if (!item.request.arguments) {
item.request.arguments = [
{
contentType: "text/plain",
enable: true,
file: false,
required: false,
type: "text",
urlEncode: false,
valid: false
}
];
}
item.request = JSON.stringify(item.request);
}
item.response = JSON.stringify(item.response);
}
//request
if (item.request) {
item.request = JSON.parse(item.request);
if (!item.request.body) {
item.request.body = new Body();
}
if (!item.request.headers) {
item.request.headers = [];
}
if (!item.request.rest) {
item.request.rest = [];
}
if (!item.request.arguments) {
item.request.arguments = [
{
contentType: "text/plain",
enable: true,
file: false,
required: false,
type: "text",
urlEncode: false,
valid: false
}
];
}
item.request = JSON.stringify(item.request);
}
});
this.$emit('getTrashApi');