fix(接口测试): 关联文件的名称显示有误

--bug=1041018 --user=陈建星 【场景】CSV参数-添加CSV关联文件并保存场景后,再次查看CSV参数,关联的CSV文件名显示错误 https://www.tapd.cn/55049933/s/1519173
This commit is contained in:
AgAngle 2024-05-23 13:48:46 +08:00 committed by jianxing
parent b4e59664d0
commit 74edb30ea3
2 changed files with 22 additions and 2 deletions

View File

@ -136,7 +136,7 @@ public class ApiCommonService {
linkFile.setFileAlias(fileAssociations.get(0).getDeletedFileName()); linkFile.setFileAlias(fileAssociations.get(0).getDeletedFileName());
} }
} else { } else {
String fileName = fileMetadata.getName() + fileMetadata.getType(); String fileName = fileMetadata.getName();
if (StringUtils.isNotBlank(fileMetadata.getType())) { if (StringUtils.isNotBlank(fileMetadata.getType())) {
// 前端展示别名加后缀 // 前端展示别名加后缀
fileName += "." + fileMetadata.getType(); fileName += "." + fileMetadata.getType();

View File

@ -29,6 +29,7 @@ import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.api.assertion.MsResponseCodeAssertion; import io.metersphere.project.api.assertion.MsResponseCodeAssertion;
import io.metersphere.project.api.assertion.MsScriptAssertion; import io.metersphere.project.api.assertion.MsScriptAssertion;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.domain.ProjectVersion; import io.metersphere.project.domain.ProjectVersion;
import io.metersphere.project.dto.environment.variables.CommonVariables; import io.metersphere.project.dto.environment.variables.CommonVariables;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest; import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
@ -497,7 +498,8 @@ public class ApiScenarioControllerTests extends BaseTest {
csvVariable.setName("csv-关联的"); csvVariable.setName("csv-关联的");
file = new ApiFile(); file = new ApiFile();
file.setFileId(fileMetadataId); file.setFileId(fileMetadataId);
file.setFileName("test.jbc"); FileMetadata fileMetadata = fileMetadataService.selectById(fileMetadataId);
file.setFileName(fileMetadata.getOriginalName());
file.setLocal(false); file.setLocal(false);
csvVariable.setScope(CsvVariable.CsvVariableScope.SCENARIO.name()); csvVariable.setScope(CsvVariable.CsvVariableScope.SCENARIO.name());
csvVariable.setFile(file); csvVariable.setFile(file);
@ -1241,6 +1243,9 @@ public class ApiScenarioControllerTests extends BaseTest {
// 验证数据 // 验证数据
assertGetApiScenarioSteps(this.addApiScenarioSteps, apiScenarioDetail.getSteps()); assertGetApiScenarioSteps(this.addApiScenarioSteps, apiScenarioDetail.getSteps());
// 校验csv数据
assertCsvFiles(apiScenarioDetail);
apiScenarioService.follow(anOtherAddApiScenario.getId(), "admin"); apiScenarioService.follow(anOtherAddApiScenario.getId(), "admin");
mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, anOtherAddApiScenario.getId()); mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, anOtherAddApiScenario.getId());
apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetailDTO.class); apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetailDTO.class);
@ -1252,6 +1257,21 @@ public class ApiScenarioControllerTests extends BaseTest {
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, DEFAULT_GET, addApiScenario.getId()); requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, DEFAULT_GET, addApiScenario.getId());
} }
private void assertCsvFiles(ApiScenarioDetailDTO apiScenarioDetail) {
List<CsvVariable> csvVariables = apiScenarioDetail.getScenarioConfig().getVariable().getCsvVariables();
ApiScenarioCsvExample example = new ApiScenarioCsvExample();
example.createCriteria().andScenarioIdEqualTo(this.addApiScenario.getId());
List<ApiScenarioCsv> 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 @Test
@Order(7) @Order(7)
public void getStepDetail() throws Exception { public void getStepDetail() throws Exception {