refactor(接口测试): 优化接口导入

This commit is contained in:
wxg0103 2024-03-14 15:40:26 +08:00 committed by Craftsman
parent 4053e5c206
commit 9488fa681d
4 changed files with 15 additions and 5 deletions

View File

@ -152,15 +152,22 @@ public class ApiDefinitionImportUtilService {
if (StringUtils.isNotBlank(request.getModuleId())) {
BaseTreeNode baseTreeNode = idModuleMap.get(request.getModuleId());
String modulePath = baseTreeNode.getPath();
importData.forEach(t -> {
t.setModulePath(modulePath + t.getModulePath());
});
//如果选择了未规划模块 导入的数据的模块清空 只导入数据不处理模块信息
if ("root".equals(request.getModuleId())) {
importData.forEach(t -> {
t.setModulePath(modulePath);
});
} else {
importData.forEach(t -> {
t.setModulePath(modulePath + t.getModulePath());
});
}
}
//去掉apiLists中不存在的模块数据
apiLists = apiLists.stream().filter(t -> modulePathMap.containsKey(t.getModulePath())).toList();
apiLists.forEach(t -> {
t.setModulePath(idModuleMap.get(t.getModuleId()) != null ? idModuleMap.get(t.getModuleId()).getPath() : StringUtils.EMPTY);
});
apiLists = apiLists.stream().filter(t -> modulePathMap.containsKey(t.getModulePath())).toList();
ApiDetailWithData apiDealWithData = new ApiDetailWithData();
//判断数据是否是唯一的
checkApiDataOnly(request, importData, apiLists, apiDealWithData);
@ -419,7 +426,7 @@ public class ApiDefinitionImportUtilService {
//判断模块是否一样
if (!StringUtils.equals(apiDefinitionDTO.getModulePath(), importDTO.getModulePath())) {
//不一样的模块需要更
apiDefinitionDTO.setModulePath(apiDefinitionDTO.getModulePath());
apiDefinitionDTO.setModulePath(importDTO.getModulePath());
updateModuleData.add(apiDefinitionDTO);
logMap.put(apiDefinitionDTO.getId(), importDTO);
}

View File

@ -1539,6 +1539,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
.getPath()));
file = new MockMultipartFile("file", "openapi1.json", MediaType.APPLICATION_OCTET_STREAM_VALUE, inputStream);
paramMap.add("file", file);
request.setModuleId("root");
request.setCoverModule(true);
request.setCoverData(true);
paramMap.add("request", JSON.toJSONString(request));

View File

@ -46,6 +46,7 @@
class="w-[436px]"
:field-names="{ title: 'name', key: 'id', children: 'children' }"
allow-search
allow-clear
/>
</a-form-item>
<a-form-item>

View File

@ -409,6 +409,7 @@
label: 'common.delete',
eventTag: 'delete',
danger: true,
permission: ['PROJECT_API_DEFINITION:READ+DELETE'],
},
],
};