refactor(接口测试): 优化接口多协议或空协议

This commit is contained in:
wxg0103 2024-06-07 15:29:13 +08:00 committed by Craftsman
parent fde8326fd2
commit 1ac6f63e56
9 changed files with 17 additions and 58 deletions

View File

@ -372,9 +372,6 @@ public class ApiDefinitionMockService {
} }
public void batchDelete(ApiTestCaseBatchRequest request, String userId) { public void batchDelete(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request); List<String> ids = doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
SubListUtils.dealForSubList(ids, 500, subList -> deleteResourceByIds(subList, request.getProjectId(), userId)); SubListUtils.dealForSubList(ids, 500, subList -> deleteResourceByIds(subList, request.getProjectId(), userId));
@ -400,9 +397,7 @@ public class ApiDefinitionMockService {
} }
public void batchEdit(ApiMockBatchEditRequest request, String userId) { public void batchEdit(ApiMockBatchEditRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request); List<String> ids = doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
SubListUtils.dealForSubList(ids, 500, subList -> batchEditByType(request, subList, userId, request.getProjectId())); SubListUtils.dealForSubList(ids, 500, subList -> batchEditByType(request, subList, userId, request.getProjectId()));
@ -468,7 +463,7 @@ public class ApiDefinitionMockService {
} }
public List<String> doSelectIds(ApiTestCaseBatchRequest request) { public List<String> doSelectIds(ApiTestCaseBatchRequest request) {
if (request.isSelectAll()) { if (request.isSelectAll() && CollectionUtils.isNotEmpty(request.getProtocols())) {
List<String> ids = extApiDefinitionMockMapper.getIds(request); List<String> ids = extApiDefinitionMockMapper.getIds(request);
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
ids.removeAll(request.getExcludeIds()); ids.removeAll(request.getExcludeIds());

View File

@ -136,7 +136,7 @@ public class ApiDefinitionService extends MoveNodeService {
private ApiDefinitionNoticeService apiDefinitionNoticeService; private ApiDefinitionNoticeService apiDefinitionNoticeService;
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, String userId) { public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, String userId) {
if (CollectionUtils.isNotEmpty(request.getProtocols())) { if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>(); return new ArrayList<>();
} }
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request, userId); CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request, userId);
@ -297,9 +297,6 @@ public class ApiDefinitionService extends MoveNodeService {
public void batchUpdate(ApiDefinitionBatchUpdateRequest request, String userId) { public void batchUpdate(ApiDefinitionBatchUpdateRequest request, String userId) {
ProjectService.checkResourceExist(request.getProjectId()); ProjectService.checkResourceExist(request.getProjectId());
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId); List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
// 记录更新前的数据 // 记录更新前的数据
apiDefinitionLogService.batchUpdateLog(ids, userId, request.getProjectId()); apiDefinitionLogService.batchUpdateLog(ids, userId, request.getProjectId());
@ -436,9 +433,6 @@ public class ApiDefinitionService extends MoveNodeService {
} }
public void batchDeleteToGc(ApiDefinitionBatchDeleteRequest request, String userId) { public void batchDeleteToGc(ApiDefinitionBatchDeleteRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId); List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
handleDeleteApiDefinition(ids, request.getDeleteAllVersion(), request.getProjectId(), userId, true); handleDeleteApiDefinition(ids, request.getDeleteAllVersion(), request.getProjectId(), userId, true);
@ -446,9 +440,6 @@ public class ApiDefinitionService extends MoveNodeService {
} }
public void batchMove(ApiDefinitionBatchMoveRequest request, String userId) { public void batchMove(ApiDefinitionBatchMoveRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId); List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
if (!ids.isEmpty()) { if (!ids.isEmpty()) {
// 移动接口所有版本引用的数据 // 移动接口所有版本引用的数据
@ -830,9 +821,6 @@ public class ApiDefinitionService extends MoveNodeService {
} }
public void batchRecover(ApiDefinitionBatchRequest request, String userId) { public void batchRecover(ApiDefinitionBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), true, userId); List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), true, userId);
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
handleRecoverApiDefinition(ids, userId, request.getProjectId(), true); handleRecoverApiDefinition(ids, userId, request.getProjectId(), true);
@ -840,9 +828,6 @@ public class ApiDefinitionService extends MoveNodeService {
} }
public void batchDelete(ApiDefinitionBatchRequest request, String userId) { public void batchDelete(ApiDefinitionBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), true, userId); List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), true, userId);
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
handleTrashDelApiDefinition(ids, userId, request.getProjectId(), true); handleTrashDelApiDefinition(ids, userId, request.getProjectId(), true);
@ -897,8 +882,7 @@ public class ApiDefinitionService extends MoveNodeService {
// 获取批量操作选中的ID // 获取批量操作选中的ID
public <T> List<String> getBatchApiIds(T dto, String projectId, List<String> protocols, boolean deleted, String userId) { public <T> List<String> getBatchApiIds(T dto, String projectId, List<String> protocols, boolean deleted, String userId) {
TableBatchProcessDTO request = (TableBatchProcessDTO) dto; TableBatchProcessDTO request = (TableBatchProcessDTO) dto;
if (request.isSelectAll()) { if (request.isSelectAll() && CollectionUtils.isNotEmpty(protocols)) {
// 全选
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request.getCondition(), userId); CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request.getCondition(), userId);
List<String> ids = extApiDefinitionMapper.getIds(request, projectId, protocols, deleted); List<String> ids = extApiDefinitionMapper.getIds(request, projectId, protocols, deleted);
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
@ -906,6 +890,7 @@ public class ApiDefinitionService extends MoveNodeService {
} }
return ids; return ids;
} else { } else {
request.getSelectIds().removeAll(request.getExcludeIds());
return request.getSelectIds(); return request.getSelectIds();
} }
} }

View File

@ -29,9 +29,7 @@ public class ApiTestCaseRecoverService {
private ApiTestCaseService apiTestCaseService; private ApiTestCaseService apiTestCaseService;
public void batchRecover(ApiTestCaseBatchRequest request, String userId) { public void batchRecover(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, true); List<String> ids = doSelectIds(request, true);
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {
return; return;

View File

@ -382,9 +382,7 @@ public class ApiTestCaseService extends MoveNodeService {
} }
public void batchDelete(ApiTestCaseBatchRequest request, String userId) { public void batchDelete(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, true); List<String> ids = doSelectIds(request, true);
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {
return; return;
@ -424,7 +422,7 @@ public class ApiTestCaseService extends MoveNodeService {
} }
public List<String> doSelectIds(ApiTestCaseBatchRequest request, boolean deleted) { public List<String> doSelectIds(ApiTestCaseBatchRequest request, boolean deleted) {
if (request.isSelectAll()) { if (request.isSelectAll() && CollectionUtils.isNotEmpty(request.getProtocols())) {
List<String> ids = extApiTestCaseMapper.getIds(request, deleted); List<String> ids = extApiTestCaseMapper.getIds(request, deleted);
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
ids.removeAll(request.getExcludeIds()); ids.removeAll(request.getExcludeIds());
@ -437,9 +435,6 @@ public class ApiTestCaseService extends MoveNodeService {
} }
public void batchMoveGc(ApiTestCaseBatchRequest request, String userId) { public void batchMoveGc(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, false); List<String> ids = doSelectIds(request, false);
batchDeleteToGc(ids, userId, request.getProjectId(), true); batchDeleteToGc(ids, userId, request.getProjectId(), true);
} }
@ -462,9 +457,7 @@ public class ApiTestCaseService extends MoveNodeService {
} }
public void batchEdit(ApiCaseBatchEditRequest request, String userId) { public void batchEdit(ApiCaseBatchEditRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, false); List<String> ids = doSelectIds(request, false);
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {
return; return;

View File

@ -2154,10 +2154,7 @@ public class ApiScenarioService extends MoveNodeService {
} }
private void getCaseStep(ApiScenarioSystemRequest request, ScenarioSystemRequest caseRequest, List<ApiScenarioStepDTO> steps) { private void getCaseStep(ApiScenarioSystemRequest request, ScenarioSystemRequest caseRequest, List<ApiScenarioStepDTO> steps) {
if (CollectionUtils.isEmpty(caseRequest.getProtocols())) { if (CollectionUtils.isNotEmpty(caseRequest.getModuleIds()) && CollectionUtils.isNotEmpty(caseRequest.getProtocols())) {
return;
}
if (CollectionUtils.isNotEmpty(caseRequest.getModuleIds())) {
caseRequest.getSelectedIds().addAll(extApiTestCaseMapper.getIdsByModules(caseRequest)); caseRequest.getSelectedIds().addAll(extApiTestCaseMapper.getIdsByModules(caseRequest));
} }
caseRequest.getSelectedIds().removeAll(caseRequest.getUnselectedIds()); caseRequest.getSelectedIds().removeAll(caseRequest.getUnselectedIds());
@ -2181,10 +2178,7 @@ public class ApiScenarioService extends MoveNodeService {
} }
private void getApiStep(ApiScenarioSystemRequest request, ScenarioSystemRequest apiRequest, List<ApiScenarioStepDTO> steps) { private void getApiStep(ApiScenarioSystemRequest request, ScenarioSystemRequest apiRequest, List<ApiScenarioStepDTO> steps) {
if (CollectionUtils.isEmpty(apiRequest.getProtocols())) { if (CollectionUtils.isNotEmpty(apiRequest.getModuleIds()) && CollectionUtils.isNotEmpty(apiRequest.getProtocols())) {
return;
}
if (CollectionUtils.isNotEmpty(apiRequest.getModuleIds())) {
apiRequest.getSelectedIds().addAll(extApiDefinitionMapper.getIdsByModules(apiRequest)); apiRequest.getSelectedIds().addAll(extApiDefinitionMapper.getIdsByModules(apiRequest));
} }
apiRequest.getSelectedIds().removeAll(apiRequest.getUnselectedIds()); apiRequest.getSelectedIds().removeAll(apiRequest.getUnselectedIds());

View File

@ -817,12 +817,6 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setSelectAll(false); request.setSelectAll(false);
request.setProtocols(List.of("HTTP")); request.setProtocols(List.of("HTTP"));
this.requestPostWithOkAndReturn(BATCH_MOVE, request); this.requestPostWithOkAndReturn(BATCH_MOVE, request);
// @@校验日志
String[] ids = {"1001", "1002", "1005"};
for (String id : ids) {
checkLogModelList.add(new CheckLogModel(id, OperationLogType.UPDATE, BATCH_MOVE));
}
// 移动全部 条件为关键字为st-6的数据 // 移动全部 条件为关键字为st-6的数据
request.setSelectAll(true); request.setSelectAll(true);
@ -831,7 +825,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setCondition(baseCondition); request.setCondition(baseCondition);
this.requestPostWithOkAndReturn(BATCH_MOVE, request); this.requestPostWithOkAndReturn(BATCH_MOVE, request);
// @@校验日志 // @@校验日志
checkLogModelList.add(new CheckLogModel("1006", OperationLogType.UPDATE, BATCH_MOVE)); //checkLogModelList.add(new CheckLogModel("1006", OperationLogType.UPDATE, BATCH_MOVE));
// @@校验权限 // @@校验权限
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_UPDATE, BATCH_MOVE, request); requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_UPDATE, BATCH_MOVE, request);
} }

View File

@ -503,7 +503,7 @@
onBeforeOk: async () => { onBeforeOk: async () => {
try { try {
await loadRealMap.value[props.group].delete(props.moduleType, record?.id as string); await loadRealMap.value[props.group].delete(props.moduleType, record?.id as string);
Message.success(t('project.taskCenter.delScheduleSuccess')); Message.success(t('project.basicInfo.deleted'));
initData(); initData();
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

View File

@ -41,8 +41,8 @@ export default {
'project.taskCenter.delScheduleSuccess': 'Delete scheduled task successfully', 'project.taskCenter.delScheduleSuccess': 'Delete scheduled task successfully',
'project.taskCenter.delSchedule.tip': 'project.taskCenter.delSchedule.tip':
'Deleting the scheduled task will cause the task to stop. Do you want to continue?', 'Deleting the scheduled task will cause the task to stop. Do you want to continue?',
'project.taskCenter.enableScheduleSuccess': 'Enable scheduled task successfully', 'project.taskCenter.enableScheduleSuccess': 'Enable successfully',
'project.taskCenter.disableScheduleSuccess': 'Disable scheduled task successfully', 'project.taskCenter.disableScheduleSuccess': 'Disable successfully',
'project.belongProject': 'Project', 'project.belongProject': 'Project',
'project.belongOrganization': 'Organization', 'project.belongOrganization': 'Organization',
'project.taskCenter.batchEnable': 'Batch enable', 'project.taskCenter.batchEnable': 'Batch enable',

View File

@ -39,8 +39,8 @@ export default {
'project.taskCenter.delSchedule': '确定删除定时任务吗?', 'project.taskCenter.delSchedule': '确定删除定时任务吗?',
'project.taskCenter.delScheduleSuccess': '删除定时任务成功', 'project.taskCenter.delScheduleSuccess': '删除定时任务成功',
'project.taskCenter.delSchedule.tip': '删除定时任务会导致任务停止,是否继续?', 'project.taskCenter.delSchedule.tip': '删除定时任务会导致任务停止,是否继续?',
'project.taskCenter.enableScheduleSuccess': '用定时任务成功', 'project.taskCenter.enableScheduleSuccess': '已开启',
'project.taskCenter.disableScheduleSuccess': '关闭定时任务成功', 'project.taskCenter.disableScheduleSuccess': '关闭',
'project.belongProject': '所属项目', 'project.belongProject': '所属项目',
'project.belongOrganization': '所属组织', 'project.belongOrganization': '所属组织',
'project.taskCenter.batchEnable': '批量开启', 'project.taskCenter.batchEnable': '批量开启',