fix(接口测试): 未规划模块下的接口详情没有展示模块名称

--bug=1045008 --user=陈建星 【接口测试】定义-预览-基本信息-所属模块显示错误,一直显示- https://www.tapd.cn/55049933/s/1564079
This commit is contained in:
AgAngle 2024-08-16 15:21:29 +08:00 committed by Craftsman
parent cbbe0c9bdc
commit ed115767c3
2 changed files with 16 additions and 6 deletions

View File

@ -921,6 +921,8 @@ public class ApiDefinitionService extends MoveNodeService {
ApiDefinitionModule apiDefinitionModule = apiDefinitionModuleMapper.selectByPrimaryKey(apiDefinitionDTO.getModuleId()); ApiDefinitionModule apiDefinitionModule = apiDefinitionModuleMapper.selectByPrimaryKey(apiDefinitionDTO.getModuleId());
if (apiDefinitionModule != null) { if (apiDefinitionModule != null) {
apiDefinitionDTO.setModuleName(apiDefinitionModule.getName()); apiDefinitionDTO.setModuleName(apiDefinitionModule.getName());
} else {
apiDefinitionDTO.setModuleName(Translator.get("api_unplanned_request"));
} }
return apiDefinitionDTO; return apiDefinitionDTO;
} }

View File

@ -450,6 +450,9 @@ public class ApiDefinitionControllerTests extends BaseTest {
Assertions.assertEquals(msHTTPElement.getModuleId(), apiDefinition.getModuleId()); Assertions.assertEquals(msHTTPElement.getModuleId(), apiDefinition.getModuleId());
Assertions.assertEquals(msHTTPElement.getNum(), apiDefinition.getNum()); Assertions.assertEquals(msHTTPElement.getNum(), apiDefinition.getNum());
assertionModuleName(apiDefinitionDTO);
copyApiDefinitionDTO.setModuleName(apiDefinitionDTO.getModuleName());
Assertions.assertEquals(apiDefinitionDTO, copyApiDefinitionDTO); Assertions.assertEquals(apiDefinitionDTO, copyApiDefinitionDTO);
assertErrorCode(this.requestGet(GET + "111"), ApiResultCode.API_DEFINITION_NOT_EXIST); assertErrorCode(this.requestGet(GET + "111"), ApiResultCode.API_DEFINITION_NOT_EXIST);
@ -458,6 +461,16 @@ public class ApiDefinitionControllerTests extends BaseTest {
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, GET + apiDefinition.getId()); requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, GET + apiDefinition.getId());
} }
private void assertionModuleName(ApiDefinitionDTO apiDefinitionDTO) {
// 判断模块名是否正确
ApiDefinitionModule apiDefinitionModule = apiDefinitionModuleMapper.selectByPrimaryKey(apiDefinitionDTO.getModuleId());
if (apiDefinitionModule == null) {
Assertions.assertEquals(apiDefinitionDTO.getModuleName(), Translator.get("api_unplanned_request"));
} else {
Assertions.assertEquals(apiDefinitionDTO.getModuleName(), apiDefinitionModule.getName());
}
}
@Test @Test
@Order(3) @Order(3)
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
@ -924,12 +937,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example); List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
Assertions.assertEquals(apiDefinitionDTO.getCaseTotal(), apiTestCases.size()); Assertions.assertEquals(apiDefinitionDTO.getCaseTotal(), apiTestCases.size());
// 判断模块名是否正确 // 判断模块名是否正确
ApiDefinitionModule apiDefinitionModule = apiDefinitionModuleMapper.selectByPrimaryKey(apiDefinitionDTO.getModuleId()); assertionModuleName(apiDefinitionDTO);
if (apiDefinitionModule == null) {
Assertions.assertEquals(apiDefinitionDTO.getModuleName(), Translator.get("api_unplanned_request"));
} else {
Assertions.assertEquals(apiDefinitionDTO.getModuleName(), apiDefinitionModule.getName());
}
} }
} }