refactor(接口测试): 优化获取场景步骤接口

This commit is contained in:
AgAngle 2024-03-24 18:21:16 +08:00 committed by Craftsman
parent ff316eac16
commit 8833f0e934
4 changed files with 9 additions and 55 deletions

View File

@ -134,11 +134,11 @@ public class ApiScenarioController {
return apiScenarioService.get(scenarioId); return apiScenarioService.get(scenarioId);
} }
@PostMapping("/step/get") @GetMapping("/step/get/{stepId}")
@Operation(summary = "接口测试-接口场景管理-获取场景步骤详情") @Operation(summary = "接口测试-接口场景管理-获取场景步骤详情")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ) @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
public Object getStepDetail(@Validated @RequestBody StepRequest request) { public Object getStepDetail(@PathVariable String stepId) {
return apiScenarioService.getStepDetail(request); return apiScenarioService.getStepDetail(stepId);
} }

View File

@ -1,27 +0,0 @@
package io.metersphere.api.dto.scenario;
import io.metersphere.api.constants.ApiScenarioStepType;
import io.metersphere.system.valid.EnumValue;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class StepRequest {
@Schema(description = "步骤id", requiredMode = Schema.RequiredMode.REQUIRED)
@Size(max = 50, message = "{api_scenario_step.id.length_range}")
@NotBlank
private String stepId;
@Schema(description = "资源id", requiredMode = Schema.RequiredMode.REQUIRED)
@Size(max = 50, message = "{api_scenario_step.resource_id.length_range}")
@NotBlank
private String resourceId;
@Schema(description = "步骤类型 API:接口 API_CASE:用例 API_SCENARIO:场景", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
@EnumValue(enumClass = ApiScenarioStepType.class)
private String stepType;
}

View File

@ -1846,14 +1846,8 @@ public class ApiScenarioService extends MoveNodeService {
return extApiScenarioStepMapper.getStepDTOByScenarioIds(scenarioIds); return extApiScenarioStepMapper.getStepDTOByScenarioIds(scenarioIds);
} }
public Object getStepDetail(StepRequest request) { public Object getStepDetail(String stepId) {
ApiScenarioStep step = apiScenarioStepMapper.selectByPrimaryKey(request.getStepId()); ApiScenarioStep step = apiScenarioStepMapper.selectByPrimaryKey(stepId);
if (step == null) {
step = new ApiScenarioStep();
step.setStepType(request.getStepType());
step.setResourceId(request.getResourceId());
step.setRefType(ApiScenarioStepRefType.REF.name());
}
StepParser stepParser = StepParserFactory.getStepParser(step.getStepType()); StepParser stepParser = StepParserFactory.getStepParser(step.getStepType());
Object stepDetail = stepParser.parseDetail(step); Object stepDetail = stepParser.parseDetail(step);
if (stepDetail instanceof AbstractMsTestElement msTestElement) { if (stepDetail instanceof AbstractMsTestElement msTestElement) {

View File

@ -95,7 +95,7 @@ public class ApiScenarioControllerTests extends BaseTest {
private static final String FOLLOW = "follow/"; private static final String FOLLOW = "follow/";
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"; protected static final String STEP_GET = "step/get/{0}";
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}";
@ -1125,12 +1125,8 @@ public class ApiScenarioControllerTests extends BaseTest {
steps = apiScenarioDetail.getSteps(); steps = apiScenarioDetail.getSteps();
requestGetStepDetail(steps); requestGetStepDetail(steps);
StepRequest stepRequest = new StepRequest();
stepRequest.setStepId(addApiScenario.getId());
stepRequest.setStepType("API_SCENARIO");
stepRequest.setResourceId(addApiScenario.getId());
// @@校验权限 // @@校验权限
requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_GET, stepRequest); requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_GET, addApiScenario.getId());
} }
private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception { private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception {
@ -1138,11 +1134,7 @@ public class ApiScenarioControllerTests extends BaseTest {
return; return;
} }
for (ApiScenarioStepCommonDTO step : steps) { for (ApiScenarioStepCommonDTO step : steps) {
StepRequest stepRequest = new StepRequest(); this.requestGet(STEP_GET, step.getId());
stepRequest.setStepId(step.getId());
stepRequest.setStepType(step.getStepType());
stepRequest.setResourceId(step.getResourceId());
this.requestPost(STEP_GET, stepRequest);
List<? extends ApiScenarioStepCommonDTO> children = step.getChildren(); List<? extends ApiScenarioStepCommonDTO> children = step.getChildren();
requestGetStepDetail(children); requestGetStepDetail(children);
} }
@ -2630,12 +2622,7 @@ public class ApiScenarioControllerTests extends BaseTest {
apiScenarioSystemRequest.setRefType(ApiScenarioStepRefType.COPY.name()); apiScenarioSystemRequest.setRefType(ApiScenarioStepRefType.COPY.name());
this.requestPostWithOkAndReturn("/get/system-request", apiScenarioSystemRequest); this.requestPostWithOkAndReturn("/get/system-request", apiScenarioSystemRequest);
StepRequest stepRequest = new StepRequest(); mockMvc.perform(getRequestBuilder(STEP_GET, "system-scenario-id1"))
stepRequest.setStepId("system-scenario-id1");
stepRequest.setStepType(ApiScenarioStepType.API_SCENARIO.name());
stepRequest.setResourceId("system-scenario-id1");
mockMvc.perform(getPostRequestBuilder(STEP_GET, stepRequest))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }