refactor(接口测试): 优化获取分享报告

This commit is contained in:
wxg0103 2024-06-19 12:02:57 +08:00 committed by 刘瑞斌
parent e62149ae10
commit ce28d64da4
4 changed files with 35 additions and 11 deletions

View File

@ -16,10 +16,13 @@ public class ApiReportShareDTO {
private String lang; private String lang;
private String projectId; private String projectId;
@Schema(description = "分享扩展数据 资源的id" ,requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "分享扩展数据 资源的id", requiredMode = Schema.RequiredMode.REQUIRED)
private String reportId; private String reportId;
@Schema(description = "分享链接是否被删") @Schema(description = "分享链接是否被删")
private Boolean deleted; private boolean deleted;
@Schema(description = "分享链接是否过期")
private boolean expired;
} }

View File

@ -128,19 +128,30 @@ public class ApiReportShareService {
} }
public ApiReportShareDTO get(String id) { public ApiReportShareDTO get(String id) {
ShareInfo shareInfo = checkResource(id);
ApiReportShareDTO dto = new ApiReportShareDTO(); ApiReportShareDTO dto = new ApiReportShareDTO();
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(id);
if (shareInfo == null) {
dto.setExpired(true);
return dto;
}
BeanUtils.copyBean(dto, shareInfo); BeanUtils.copyBean(dto, shareInfo);
dto.setReportId(new String(shareInfo.getCustomData())); dto.setReportId(new String(shareInfo.getCustomData()));
//检查id是否存在 //检查id是否存在
dto.setDeleted(false); dto.setDeleted(true);
ApiReport apiReport = apiReportMapper.selectByPrimaryKey(dto.getReportId()); ApiReport apiReport = apiReportMapper.selectByPrimaryKey(dto.getReportId());
if (apiReport != null && BooleanUtils.isTrue(apiReport.getDeleted())) { if (apiReport != null && BooleanUtils.isFalse(apiReport.getDeleted())) {
dto.setDeleted(true); dto.setDeleted(false);
} else { } else {
ApiScenarioReport result = apiScenarioReportMapper.selectByPrimaryKey(dto.getReportId()); ApiScenarioReport result = apiScenarioReportMapper.selectByPrimaryKey(dto.getReportId());
if (result != null && BooleanUtils.isTrue(result.getDeleted())) { if (result != null && BooleanUtils.isFalse(result.getDeleted())) {
dto.setDeleted(true); dto.setDeleted(false);
}
}
if (BooleanUtils.isFalse(dto.isDeleted())) {
try {
validateExpired(shareInfo);
} catch (Exception e) {
dto.setExpired(true);
} }
} }
return dto; return dto;

View File

@ -421,7 +421,7 @@ public class ApiReportControllerTests extends BaseTest {
mockMvc.perform(getRequestBuilder("/api/report/share/get/" + "test")) mockMvc.perform(getRequestBuilder("/api/report/share/get/" + "test"))
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError()); .andExpect(status().isOk());
mvcResult = this.requestGetWithOk(BASIC + "/share/detail/" + shareId + "/" + "test-report-id" + "/" + "test-report-step-id1") mvcResult = this.requestGetWithOk(BASIC + "/share/detail/" + shareId + "/" + "test-report-id" + "/" + "test-report-step-id1")
.andReturn(); .andReturn();
@ -436,6 +436,16 @@ public class ApiReportControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError()); .andExpect(status().is5xxServerError());
mvcResult = responsePost("/api/report/share/gen", shareInfo);
shareInfoDTO = parseObjectFromMvcResult(mvcResult, ShareInfoDTO.class);
shareId = shareInfoDTO.getId();
shareInfo1 = shareInfoMapper.selectByPrimaryKey(shareId);
shareInfo1.setUpdateTime(1702950953000L);
shareInfoMapper.updateByPrimaryKey(shareInfo1);
this.requestGetWithOk("/api/report/share/get/" + shareId)
.andReturn();
//TODO 过期的校验 未完成 需要补充 //TODO 过期的校验 未完成 需要补充
//项目当前设置了分享时间 并且没有过期 //项目当前设置了分享时间 并且没有过期

View File

@ -474,7 +474,7 @@ public class ApiScenarioReportControllerTests extends BaseTest {
mockMvc.perform(getRequestBuilder("/api/report/share/get/" + "test")) mockMvc.perform(getRequestBuilder("/api/report/share/get/" + "test"))
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError()); .andExpect(status().isOk());
mvcResult = this.requestGetWithOk(BASIC + "/share/detail/" + shareId + "/" + "test-scenario-report-id" + "/" + "test-scenario-report-step-id1") mvcResult = this.requestGetWithOk(BASIC + "/share/detail/" + shareId + "/" + "test-scenario-report-id" + "/" + "test-scenario-report-step-id1")
.andReturn(); .andReturn();