diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java index 483e179d90..e380b0bb43 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java @@ -136,7 +136,7 @@ public class ApiCommonService { linkFile.setFileAlias(fileAssociations.get(0).getDeletedFileName()); } } else { - String fileName = fileMetadata.getName() + fileMetadata.getType(); + String fileName = fileMetadata.getName(); if (StringUtils.isNotBlank(fileMetadata.getType())) { // 前端展示别名加后缀 fileName += "." + fileMetadata.getType(); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index 07f3440275..36e5c6e5fe 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -29,6 +29,7 @@ import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.api.assertion.MsResponseCodeAssertion; import io.metersphere.project.api.assertion.MsScriptAssertion; +import io.metersphere.project.domain.FileMetadata; import io.metersphere.project.domain.ProjectVersion; import io.metersphere.project.dto.environment.variables.CommonVariables; import io.metersphere.project.dto.filemanagement.request.FileUploadRequest; @@ -497,7 +498,8 @@ public class ApiScenarioControllerTests extends BaseTest { csvVariable.setName("csv-关联的"); file = new ApiFile(); file.setFileId(fileMetadataId); - file.setFileName("test.jbc"); + FileMetadata fileMetadata = fileMetadataService.selectById(fileMetadataId); + file.setFileName(fileMetadata.getOriginalName()); file.setLocal(false); csvVariable.setScope(CsvVariable.CsvVariableScope.SCENARIO.name()); csvVariable.setFile(file); @@ -1241,6 +1243,9 @@ public class ApiScenarioControllerTests extends BaseTest { // 验证数据 assertGetApiScenarioSteps(this.addApiScenarioSteps, apiScenarioDetail.getSteps()); + // 校验csv数据 + assertCsvFiles(apiScenarioDetail); + apiScenarioService.follow(anOtherAddApiScenario.getId(), "admin"); mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, anOtherAddApiScenario.getId()); apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetailDTO.class); @@ -1252,6 +1257,21 @@ public class ApiScenarioControllerTests extends BaseTest { requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, DEFAULT_GET, addApiScenario.getId()); } + private void assertCsvFiles(ApiScenarioDetailDTO apiScenarioDetail) { + List csvVariables = apiScenarioDetail.getScenarioConfig().getVariable().getCsvVariables(); + ApiScenarioCsvExample example = new ApiScenarioCsvExample(); + example.createCriteria().andScenarioIdEqualTo(this.addApiScenario.getId()); + List csvList = apiScenarioCsvMapper.selectByExample(example); + Assertions.assertEquals(csvVariables.size(), csvList.size()); + for (CsvVariable csvVariable : csvVariables) { + if (!csvVariable.getFile().getLocal()) { + FileMetadata fileMetadata = fileMetadataService.selectById(csvVariable.getFile().getFileId()); + Assertions.assertEquals(fileMetadata.getName() + "." + fileMetadata.getType(), csvVariable.getFile().getFileAlias()); + Assertions.assertEquals(fileMetadata.getOriginalName(), csvVariable.getFile().getFileName()); + } + } + } + @Test @Order(7) public void getStepDetail() throws Exception {