refactor(接口测试): 优化获取分享报告
This commit is contained in:
parent
e62149ae10
commit
ce28d64da4
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 过期的校验 未完成 需要补充
|
||||||
//项目当前设置了分享时间 并且没有过期
|
//项目当前设置了分享时间 并且没有过期
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue