fix(接口测试): 新增场景步骤所属资源查询接口

--bug=1038780 --user=陈建星 【接口测试】场景-添加步骤-导入系统请求-导入后修改原请求的名称-hover图标查看导入系统请求名称-名称显示undefined https://www.tapd.cn/55049933/s/1491298
This commit is contained in:
AgAngle 2024-04-09 12:50:52 +08:00 committed by 刘瑞斌
parent b1eabb9490
commit 4408222206
4 changed files with 81 additions and 23 deletions

View File

@ -14,7 +14,6 @@ import io.metersphere.api.service.ApiValidateService;
import io.metersphere.api.service.scenario.ApiScenarioLogService; import io.metersphere.api.service.scenario.ApiScenarioLogService;
import io.metersphere.api.service.scenario.ApiScenarioNoticeService; import io.metersphere.api.service.scenario.ApiScenarioNoticeService;
import io.metersphere.api.service.scenario.ApiScenarioService; import io.metersphere.api.service.scenario.ApiScenarioService;
import io.metersphere.project.domain.Project;
import io.metersphere.project.service.FileModuleService; import io.metersphere.project.service.FileModuleService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.api.task.TaskRequestDTO; import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
@ -142,11 +141,11 @@ public class ApiScenarioController {
return apiScenarioService.getStepDetail(stepId); return apiScenarioService.getStepDetail(stepId);
} }
@GetMapping("/step/project-ifo/{projectId}") @GetMapping("/step/resource-info/{resourceId}")
@Operation(summary = "接口测试-接口场景管理-获取步骤所属项目信息") @Operation(summary = "接口测试-接口场景管理-获取步骤关联资源的信息")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ) @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
public Project getStepResourceProjectInfo(@PathVariable String projectId) { public ApiStepResourceInfo getStepResourceInfo(@PathVariable String resourceId, @RequestParam String resourceType) {
return apiScenarioService.getStepResourceProjectInfo(projectId); return apiScenarioService.getStepResourceInfo(resourceId, resourceType);
} }
//需求补充回收站里的相关操作都不需要发通知 //需求补充回收站里的相关操作都不需要发通知

View File

@ -0,0 +1,18 @@
package io.metersphere.api.dto.scenario;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class ApiStepResourceInfo {
@Schema(description = "资源ID")
private String id;
@Schema(description = "资源编号")
private Long num;
@Schema(description = "资源名称")
private String name;
@Schema(description = "所属项目ID")
private String projectId;
@Schema(description = "所属项目名称")
private String projectName;
}

View File

@ -2738,14 +2738,41 @@ public class ApiScenarioService extends MoveNodeService {
return extApiDefinitionMapper.getReference(request); return extApiDefinitionMapper.getReference(request);
} }
public Project getStepResourceProjectInfo(String projectId) { public ApiStepResourceInfo getStepResourceInfo(String resourceId, String resourceType) {
Project project = projectMapper.selectByPrimaryKey(projectId); ApiResourceType apiResourceType = EnumValidator.validateEnum(ApiResourceType.class, resourceType);
if (project == null) { ApiStepResourceInfo apiStepResourceInfo = new ApiStepResourceInfo();
return null; apiStepResourceInfo.setId(resourceId);
String projectId;
switch (apiResourceType) {
case API_SCENARIO -> {
ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(resourceId);
apiStepResourceInfo.setId(apiScenario.getId());
apiStepResourceInfo.setNum(apiScenario.getNum());
apiStepResourceInfo.setName(apiScenario.getName());
projectId = apiScenario.getProjectId();
}
case API -> {
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(resourceId);
apiStepResourceInfo.setId(apiDefinition.getId());
apiStepResourceInfo.setNum(apiDefinition.getNum());
apiStepResourceInfo.setName(apiDefinition.getName());
projectId = apiDefinition.getProjectId();
}
case API_CASE -> {
ApiTestCase apiTestCase = apiTestCaseMapper.selectByPrimaryKey(resourceId);
apiStepResourceInfo.setId(apiTestCase.getId());
apiStepResourceInfo.setNum(apiTestCase.getNum());
apiStepResourceInfo.setName(apiTestCase.getName());
projectId = apiTestCase.getProjectId();
}
default -> {
return apiStepResourceInfo;
}
} }
Project projectInfo = new Project(); Project project = projectMapper.selectByPrimaryKey(projectId);
projectInfo.setId(project.getId()); apiStepResourceInfo.setProjectId(project.getId());
projectInfo.setName(project.getName()); apiStepResourceInfo.setProjectName(project.getName());
return projectInfo; return apiStepResourceInfo;
} }
} }

View File

@ -30,7 +30,6 @@ import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.api.assertion.MsResponseCodeAssertion; import io.metersphere.project.api.assertion.MsResponseCodeAssertion;
import io.metersphere.project.api.assertion.MsScriptAssertion; import io.metersphere.project.api.assertion.MsScriptAssertion;
import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectVersion; import io.metersphere.project.domain.ProjectVersion;
import io.metersphere.project.dto.environment.variables.CommonVariables; import io.metersphere.project.dto.environment.variables.CommonVariables;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest; import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
@ -100,7 +99,7 @@ public class ApiScenarioControllerTests extends BaseTest {
protected static final String UPLOAD_TEMP_FILE = "upload/temp/file"; protected static final String UPLOAD_TEMP_FILE = "upload/temp/file";
protected static final String DELETE_TO_GC = "delete-to-gc/{0}"; protected static final String DELETE_TO_GC = "delete-to-gc/{0}";
protected static final String STEP_GET = "step/get/{0}"; protected static final String STEP_GET = "step/get/{0}";
protected static final String STEP_PROJECT_INFO = "step/project-ifo/{0}"; protected static final String STEP_RESOURCE_INFO = "step/resource-info/{0}?resourceType={1}";
protected static final String DEBUG = "debug"; protected static final String DEBUG = "debug";
protected static final String RUN = "run/{0}"; protected static final String RUN = "run/{0}";
protected static final String RUN_REAL_TIME = "run/{0}?reportId={1}"; protected static final String RUN_REAL_TIME = "run/{0}?reportId={1}";
@ -634,6 +633,8 @@ public class ApiScenarioControllerTests extends BaseTest {
// 测试关联的文件更新 // 测试关联的文件更新
testHandleFileAssociationUpgrade(); testHandleFileAssociationUpgrade();
addApiScenario = apiScenarioMapper.selectByPrimaryKey(addApiScenario.getId());
// @@重名校验异常 // @@重名校验异常
request.setName(anOtherAddApiScenario.getName()); request.setName(anOtherAddApiScenario.getName());
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), API_SCENARIO_EXIST); assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), API_SCENARIO_EXIST);
@ -1218,17 +1219,30 @@ public class ApiScenarioControllerTests extends BaseTest {
@Test @Test
@Order(7) @Order(7)
public void getStepResourceProjectInfo() throws Exception { public void getStepResourceResourceInfo() throws Exception {
MvcResult mvcResult = this.requestGetAndReturn(STEP_PROJECT_INFO, DEFAULT_PROJECT_ID);
Project project = getResultData(mvcResult, Project.class);
Assertions.assertEquals(project.getName(), projectMapper.selectByPrimaryKey(project.getId()).getName());
mvcResult = this.requestGetAndReturn(STEP_PROJECT_INFO, "tyuio"); MvcResult mvcResult = this.requestGetAndReturn(STEP_RESOURCE_INFO, apiDefinition.getId(), ApiScenarioStepType.API.name());
project = getResultData(mvcResult, Project.class); ApiStepResourceInfo apiStepResourceInfo = getResultData(mvcResult, ApiStepResourceInfo.class);
Assertions.assertNull(project); Assertions.assertEquals(apiStepResourceInfo.getNum(), apiDefinition.getNum());
Assertions.assertEquals(apiStepResourceInfo.getName(), apiDefinition.getName());
Assertions.assertEquals(apiStepResourceInfo.getProjectName(), projectMapper.selectByPrimaryKey(apiDefinition.getProjectId()).getName());
mvcResult = this.requestGetAndReturn(STEP_RESOURCE_INFO, apiTestCase.getId(), ApiScenarioStepType.API_CASE.name());
apiStepResourceInfo = getResultData(mvcResult, ApiStepResourceInfo.class);
Assertions.assertEquals(apiStepResourceInfo.getNum(), apiTestCase.getNum());
Assertions.assertEquals(apiStepResourceInfo.getName(), apiTestCase.getName());
Assertions.assertEquals(apiStepResourceInfo.getProjectName(), projectMapper.selectByPrimaryKey(apiTestCase.getProjectId()).getName());
mvcResult = this.requestGetAndReturn(STEP_RESOURCE_INFO, addApiScenario.getId(), ApiScenarioStepType.API_SCENARIO.name());
apiStepResourceInfo = getResultData(mvcResult, ApiStepResourceInfo.class);
Assertions.assertEquals(apiStepResourceInfo.getNum(), addApiScenario.getNum());
Assertions.assertEquals(apiStepResourceInfo.getName(), addApiScenario.getName());
Assertions.assertEquals(apiStepResourceInfo.getProjectName(), projectMapper.selectByPrimaryKey(addApiScenario.getProjectId()).getName());
this.requestGetAndReturn(STEP_RESOURCE_INFO, addApiScenario.getId(), "AAA");
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_PROJECT_INFO, DEFAULT_PROJECT_ID); requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_RESOURCE_INFO, "aa", "bb");
} }
private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception { private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception {