refactor(接口测试): 优化接口分享报告
This commit is contained in:
parent
c88cfa3ad1
commit
af988df1b8
|
@ -1,8 +1,9 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import io.metersphere.api.dto.share.ApiReportShareDTO;
|
||||
import io.metersphere.api.dto.share.ApiReportShareRequest;
|
||||
import io.metersphere.api.dto.share.ShareInfoDTO;
|
||||
import io.metersphere.api.service.ApiReportShareService;
|
||||
import io.metersphere.sdk.domain.ShareInfo;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -21,12 +22,12 @@ public class ApiReportShareController {
|
|||
private ApiReportShareService apiReportShareService;
|
||||
|
||||
@PostMapping("/gen")
|
||||
public ShareInfoDTO generateShareInfo(@Validated(Created.class) @RequestBody ShareInfo request) {
|
||||
public ShareInfoDTO generateShareInfo(@Validated(Created.class) @RequestBody ApiReportShareRequest request) {
|
||||
return apiReportShareService.gen(request, Objects.requireNonNull(SessionUtils.getUser()));
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ShareInfo get(@PathVariable String id) {
|
||||
public ApiReportShareDTO get(@PathVariable String id) {
|
||||
return apiReportShareService.get(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package io.metersphere.api.dto.share;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApiReportShareDTO {
|
||||
|
||||
@Schema(description = "分享id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "分享类型 资源的类型 Single, Batch, API_SHARE_REPORT, TEST_PLAN_SHARE_REPORT")
|
||||
private String shareType;
|
||||
|
||||
@Schema(description = "语言")
|
||||
private String lang;
|
||||
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "分享扩展数据 资源的id" ,requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String reportId;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package io.metersphere.api.dto.share;
|
||||
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApiReportShareRequest {
|
||||
|
||||
@Schema(description = "分享类型 资源的类型 Single, Batch, API_SHARE_REPORT, TEST_PLAN_SHARE_REPORT")
|
||||
private String shareType;
|
||||
|
||||
@Schema(description = "语言")
|
||||
private String lang;
|
||||
|
||||
@Schema(description = "项目id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{share_info.project_id.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 50, message = "{share_info.project_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "分享扩展数据 资源的id" ,requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{share_info.project_id.not_blank}")
|
||||
private String reportId;
|
||||
}
|
|
@ -3,6 +3,8 @@ package io.metersphere.api.service;
|
|||
import io.metersphere.api.constants.ShareInfoType;
|
||||
import io.metersphere.api.domain.ApiReport;
|
||||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
import io.metersphere.api.dto.share.ApiReportShareDTO;
|
||||
import io.metersphere.api.dto.share.ApiReportShareRequest;
|
||||
import io.metersphere.api.dto.share.ShareInfoDTO;
|
||||
import io.metersphere.api.mapper.ApiReportMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportMapper;
|
||||
|
@ -12,6 +14,7 @@ import io.metersphere.project.mapper.ProjectApplicationMapper;
|
|||
import io.metersphere.sdk.domain.ShareInfo;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.ShareInfoMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
|
@ -99,10 +102,13 @@ public class ApiReportShareService {
|
|||
return returnDTO;
|
||||
}
|
||||
|
||||
public ShareInfoDTO gen(ShareInfo request, SessionUser user) {
|
||||
public ShareInfoDTO gen(ApiReportShareRequest shareRequest, SessionUser user) {
|
||||
String lang = user.getLanguage() == null ? LocaleContextHolder.getLocale().toString() : user.getLanguage();
|
||||
ShareInfo request = new ShareInfo();
|
||||
BeanUtils.copyBean(request, shareRequest);
|
||||
request.setLang(lang);
|
||||
request.setCreateUser(user.getId());
|
||||
request.setCustomData(shareRequest.getReportId().getBytes());
|
||||
request.setShareType(ShareInfoType.API_SHARE_REPORT.name());
|
||||
ShareInfo shareInfo = createShareInfo(request);
|
||||
return conversionShareInfoToDTO(shareInfo);
|
||||
|
@ -116,7 +122,11 @@ public class ApiReportShareService {
|
|||
return shareInfo;
|
||||
}
|
||||
|
||||
public ShareInfo get(String id) {
|
||||
return checkResource(id);
|
||||
public ApiReportShareDTO get(String id) {
|
||||
ShareInfo shareInfo = checkResource(id);
|
||||
ApiReportShareDTO dto = new ApiReportShareDTO();
|
||||
BeanUtils.copyBean(dto, shareInfo);
|
||||
dto.setReportId(new String(shareInfo.getCustomData()));
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.ApiReportDTO;
|
|||
import io.metersphere.api.dto.definition.ApiReportDetailDTO;
|
||||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.share.ApiReportShareRequest;
|
||||
import io.metersphere.api.dto.share.ShareInfoDTO;
|
||||
import io.metersphere.api.mapper.ApiReportDetailMapper;
|
||||
import io.metersphere.api.mapper.ApiReportLogMapper;
|
||||
|
@ -416,8 +417,8 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(8)
|
||||
public void generateUrl() throws Exception {
|
||||
ShareInfo shareInfo = new ShareInfo();
|
||||
shareInfo.setCustomData("test-report-id".getBytes());
|
||||
ApiReportShareRequest shareInfo = new ApiReportShareRequest();
|
||||
shareInfo.setReportId("test-report-id");
|
||||
shareInfo.setProjectId(DEFAULT_PROJECT_ID);
|
||||
shareInfo.setShareType(ShareInfoType.API_SHARE_REPORT.name());
|
||||
MvcResult mvcResult = responsePost("/api/report/share/gen", shareInfo);
|
||||
|
@ -455,8 +456,8 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
//TODO 过期的校验 未完成 需要补充
|
||||
//项目当前设置了分享时间 并且没有过期
|
||||
|
||||
shareInfo = new ShareInfo();
|
||||
shareInfo.setCustomData("test-report-id".getBytes());
|
||||
shareInfo = new ApiReportShareRequest();
|
||||
shareInfo.setReportId("test-report-id");
|
||||
shareInfo.setProjectId(DEFAULT_PROJECT_ID);
|
||||
shareInfo.setShareType(ShareInfoType.API_SHARE_REPORT.name());
|
||||
mvcResult = responsePost("/api/report/share/gen", shareInfo);
|
||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
|||
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
|
||||
import io.metersphere.api.dto.share.ApiReportShareRequest;
|
||||
import io.metersphere.api.dto.share.ShareInfoDTO;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportDetailMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportLogMapper;
|
||||
|
@ -376,8 +377,8 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(8)
|
||||
public void generateUrl() throws Exception {
|
||||
ShareInfo shareInfo = new ShareInfo();
|
||||
shareInfo.setCustomData("test-scenario-report-id".getBytes());
|
||||
ApiReportShareRequest shareInfo = new ApiReportShareRequest();
|
||||
shareInfo.setReportId("test-scenario-report-id");
|
||||
shareInfo.setProjectId(DEFAULT_PROJECT_ID);
|
||||
shareInfo.setShareType(ShareInfoType.API_SHARE_REPORT.name());
|
||||
MvcResult mvcResult = responsePost("/api/report/share/gen", shareInfo);
|
||||
|
@ -413,8 +414,8 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
.andExpect(status().is5xxServerError());
|
||||
|
||||
|
||||
shareInfo = new ShareInfo();
|
||||
shareInfo.setCustomData("test-scenario-report-id".getBytes());
|
||||
shareInfo = new ApiReportShareRequest();
|
||||
shareInfo.setReportId("test-scenario-report-id");
|
||||
shareInfo.setProjectId(DEFAULT_PROJECT_ID);
|
||||
shareInfo.setShareType(ShareInfoType.API_SHARE_REPORT.name());
|
||||
mvcResult = responsePost("/api/report/share/gen", shareInfo);
|
||||
|
|
Loading…
Reference in New Issue