refactor(接口测试): 优化报告

This commit is contained in:
wxg0103 2024-03-23 14:56:16 +08:00 committed by wxg0103
parent 5f7fa0fd6f
commit 82752b5bf7
5 changed files with 38 additions and 7 deletions

View File

@ -94,9 +94,9 @@ public class ApiReportController {
@Operation(summary = "接口测试-接口报告-报告详情获取") @Operation(summary = "接口测试-接口报告-报告详情获取")
@CheckOwner(resourceId = "#reportId", resourceType = "api_report") @CheckOwner(resourceId = "#reportId", resourceType = "api_report")
@RequiresPermissions(value = {PermissionConstants.PROJECT_API_REPORT_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}, logical = Logical.OR) @RequiresPermissions(value = {PermissionConstants.PROJECT_API_REPORT_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}, logical = Logical.OR)
public List<ApiReportDetailDTO> getDetail(@PathVariable String stepId, public List<ApiReportDetailDTO> getDetail(@PathVariable String reportId,
@PathVariable String reportId) { @PathVariable String stepId) {
return apiReportService.getDetail(stepId, reportId); return apiReportService.getDetail(reportId, stepId);
} }
@GetMapping("/share/detail/{shareId}/{reportId}/{stepId}") @GetMapping("/share/detail/{shareId}/{reportId}/{stepId}")
@ -105,7 +105,7 @@ public class ApiReportController {
@PathVariable String stepId) { @PathVariable String stepId) {
ShareInfo shareInfo = apiReportShareService.checkResource(shareId); ShareInfo shareInfo = apiReportShareService.checkResource(shareId);
apiReportShareService.validateExpired(shareInfo); apiReportShareService.validateExpired(shareInfo);
return apiReportService.getDetail(stepId, reportId); return apiReportService.getDetail(reportId, stepId);
} }
} }

View File

@ -6,6 +6,7 @@ import io.metersphere.api.dto.report.ApiReportListDTO;
import io.metersphere.api.mapper.*; import io.metersphere.api.mapper.*;
import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.sdk.constants.ApiExecuteResourceType; import io.metersphere.sdk.constants.ApiExecuteResourceType;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.dto.api.result.RequestResult; import io.metersphere.sdk.dto.api.result.RequestResult;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.mapper.EnvironmentMapper;
@ -185,7 +186,12 @@ public class ApiReportService {
//查询资源池名称 //查询资源池名称
apiReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(apiReportDTO.getPoolId()).getName()); apiReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(apiReportDTO.getPoolId()).getName());
//查询环境名称 //查询环境名称
apiReportDTO.setEnvironmentName(StringUtils.isNoneBlank(apiReportDTO.getEnvironmentId()) ? environmentMapper.selectByPrimaryKey(apiReportDTO.getEnvironmentId()).getName() : null); if (StringUtils.isNoneBlank(apiReportDTO.getEnvironmentId())) {
Environment environment = environmentMapper.selectByPrimaryKey(apiReportDTO.getEnvironmentId());
if (environment != null) {
apiReportDTO.setEnvironmentName(environment.getName());
}
}
apiReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(apiReportDTO.getCreateUser()).getName()); apiReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(apiReportDTO.getCreateUser()).getName());
//需要查询出所有的步骤 //需要查询出所有的步骤
if (BooleanUtils.isTrue(apiReport.getIntegrated())) { if (BooleanUtils.isTrue(apiReport.getIntegrated())) {
@ -206,6 +212,8 @@ public class ApiReportService {
ApiReportStepDTO apiReportStepDTO = new ApiReportStepDTO(); ApiReportStepDTO apiReportStepDTO = new ApiReportStepDTO();
BeanUtils.copyBean(apiReportStepDTO, apiReportDTO); BeanUtils.copyBean(apiReportStepDTO, apiReportDTO);
apiReportStepDTO.setStepId(apiTestCaseRecords.getFirst().getApiTestCaseId()); apiReportStepDTO.setStepId(apiTestCaseRecords.getFirst().getApiTestCaseId());
apiReportStepDTO.setReportId(id);
apiReportStepDTO.setSort(1L);
apiReportStepDTO.setStepType(ApiExecuteResourceType.API_CASE.name()); apiReportStepDTO.setStepType(ApiExecuteResourceType.API_CASE.name());
List<ApiReportStepDTO> apiReportSteps = new ArrayList<>(); List<ApiReportStepDTO> apiReportSteps = new ArrayList<>();
apiReportSteps.add(apiReportStepDTO); apiReportSteps.add(apiReportStepDTO);
@ -213,7 +221,7 @@ public class ApiReportService {
return apiReportDTO; return apiReportDTO;
} }
public List<ApiReportDetailDTO> getDetail(String stepId, String reportId) { public List<ApiReportDetailDTO> getDetail(String reportId, String stepId) {
List<ApiReportDetail> apiReportDetails = checkResourceStep(stepId, reportId); List<ApiReportDetail> apiReportDetails = checkResourceStep(stepId, reportId);
List<ApiReportDetailDTO> results = new ArrayList<>(); List<ApiReportDetailDTO> results = new ArrayList<>();
apiReportDetails.forEach(apiReportDetail -> { apiReportDetails.forEach(apiReportDetail -> {

View File

@ -11,6 +11,7 @@ import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO;
import io.metersphere.api.mapper.*; import io.metersphere.api.mapper.*;
import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.sdk.constants.ApiReportStatus; import io.metersphere.sdk.constants.ApiReportStatus;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.dto.api.result.RequestResult; import io.metersphere.sdk.dto.api.result.RequestResult;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.mapper.EnvironmentMapper;
@ -199,7 +200,12 @@ public class ApiScenarioReportService {
//查询资源池名称 //查询资源池名称
scenarioReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(scenarioReport.getPoolId()).getName()); scenarioReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(scenarioReport.getPoolId()).getName());
//查询环境名称 //查询环境名称
scenarioReportDTO.setEnvironmentName(StringUtils.isNotBlank(scenarioReport.getEnvironmentId()) ? environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId()).getName(): null); if (StringUtils.isNotBlank(scenarioReport.getEnvironmentId())) {
Environment environment = environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId());
if (environment != null) {
scenarioReportDTO.setEnvironmentName(environment.getName());
}
}
scenarioReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(scenarioReport.getCreateUser()).getName()); scenarioReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(scenarioReport.getCreateUser()).getName());
return scenarioReportDTO; return scenarioReportDTO;
} }

View File

@ -298,6 +298,14 @@ public class ApiReportControllerTests extends BaseTest {
Assertions.assertNotNull(apiReportDTO); Assertions.assertNotNull(apiReportDTO);
Assertions.assertEquals(apiReportDTO.getId(), "test-report-id"); Assertions.assertEquals(apiReportDTO.getId(), "test-report-id");
ApiReport apiReport1 = apiReportMapper.selectByPrimaryKey("test-report-id");
apiReport1.setEnvironmentId(null);
apiReport1.setPoolId(null);
apiReportMapper.updateByPrimaryKeySelective(apiReport1);
this.requestGetWithOk(GET + "test-report-id");
apiReport1.setEnvironmentId("env_id");
apiReportMapper.updateByPrimaryKeySelective(apiReport1);
this.requestGetWithOk(GET + "test-report-id");
reports = new ArrayList<>(); reports = new ArrayList<>();
apiReport = new ApiReport(); apiReport = new ApiReport();

View File

@ -327,6 +327,15 @@ public class ApiScenarioReportControllerTests extends BaseTest {
Assertions.assertNotNull(apiReportDTO); Assertions.assertNotNull(apiReportDTO);
Assertions.assertEquals(apiReportDTO.getId(), "test-scenario-report-id"); Assertions.assertEquals(apiReportDTO.getId(), "test-scenario-report-id");
ApiScenarioReport scenarioReport1 = apiScenarioReportMapper.selectByPrimaryKey("test-scenario-report-id");
scenarioReport1.setEnvironmentId(null);
scenarioReport1.setPoolId(null);
apiScenarioReportMapper.updateByPrimaryKeySelective(scenarioReport1);
this.requestGetWithOk(GET + "test-scenario-report-id");
scenarioReport1.setEnvironmentId("env_id");
apiScenarioReportMapper.updateByPrimaryKeySelective(scenarioReport1);
this.requestGetWithOk(GET + "test-scenario-report-id");
mockMvc.perform(getRequestBuilder(GET + "test")) mockMvc.perform(getRequestBuilder(GET + "test"))
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError()); .andExpect(status().is5xxServerError());