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);
}
@PostMapping("/step/get")
@GetMapping("/step/get/{stepId}")
@Operation(summary = "接口测试-接口场景管理-获取场景步骤详情")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
public Object getStepDetail(@Validated @RequestBody StepRequest request) {
return apiScenarioService.getStepDetail(request);
public Object getStepDetail(@PathVariable String stepId) {
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);
}
public Object getStepDetail(StepRequest request) {
ApiScenarioStep step = apiScenarioStepMapper.selectByPrimaryKey(request.getStepId());
if (step == null) {
step = new ApiScenarioStep();
step.setStepType(request.getStepType());
step.setResourceId(request.getResourceId());
step.setRefType(ApiScenarioStepRefType.REF.name());
}
public Object getStepDetail(String stepId) {
ApiScenarioStep step = apiScenarioStepMapper.selectByPrimaryKey(stepId);
StepParser stepParser = StepParserFactory.getStepParser(step.getStepType());
Object stepDetail = stepParser.parseDetail(step);
if (stepDetail instanceof AbstractMsTestElement msTestElement) {

View File

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