fix(接口测试): 引用的场景csv不生效

--bug=1041213 --user=陈建星 【场景】-场景引用有CSV参数的场景作为步骤,执行时,引用场景步骤内的CSV没有循环取值 https://www.tapd.cn/55049933/s/1521182
This commit is contained in:
AgAngle 2024-05-27 11:36:01 +08:00 committed by 刘瑞斌
parent 9da5383c1a
commit 292c3abe61
3 changed files with 27 additions and 12 deletions

View File

@ -15,7 +15,7 @@ public interface ExtApiScenarioStepMapper {
List<ApiScenarioStepDTO> getStepDTOByScenarioIds(@Param("scenarioIds") List<String> scenarioIds);
List<ApiScenarioCsvStep> getCsvStepByScenarioId(@Param("scenarioId") String scenarioId);
List<ApiScenarioCsvStep> getCsvStepByScenarioIds(@Param("scenarioIds") List<String> scenarioId);
/**
* 查询有步骤详情的请求类型的步骤

View File

@ -13,10 +13,13 @@
#{scenarioId}
</foreach>
</select>
<select id="getCsvStepByScenarioId" resultType="io.metersphere.api.domain.ApiScenarioCsvStep">
<select id="getCsvStepByScenarioIds" resultType="io.metersphere.api.domain.ApiScenarioCsvStep">
select
<include refid="io.metersphere.api.mapper.ApiScenarioCsvStepMapper.Base_Column_List"/>
from api_scenario_csv_step where scenario_id = #{scenarioId}
from api_scenario_csv_step where scenario_id in
<foreach collection="scenarioIds" item="scenarioId" open="(" separator="," close=")">
#{scenarioId}
</foreach>
</select>
<select id="getHasBlobRequestStepIds" resultType="java.lang.String">
select id

View File

@ -2224,15 +2224,8 @@ public class ApiScenarioService extends MoveNodeService {
.distinct() // 这里可能存在多次引用相同场景步骤可能会重复去重
.collect(Collectors.toList());
//获取所有步骤的csv的关联关系
List<ApiScenarioCsvStep> csvSteps = extApiScenarioStepMapper.getCsvStepByScenarioId(scenarioId);
// 构造 mapkey 为步骤IDvalue 为csv文件ID列表
Map<String, List<String>> stepsCsvMap = csvSteps.stream()
.collect(Collectors.groupingBy(ApiScenarioCsvStep::getStepId, Collectors.mapping(ApiScenarioCsvStep::getFileId, Collectors.toList())));
//将stepsCsvMap根据步骤id放入到allSteps中
if (CollectionUtils.isNotEmpty(allSteps)) {
allSteps.forEach(step -> step.setCsvIds(stepsCsvMap.get(step.getId())));
}
// 设置步骤的 csvIds
setStepCsvIds(scenarioId, allSteps);
// 构造 mapkey 为场景IDvalue 为步骤列表
Map<String, List<ApiScenarioStepDTO>> scenarioStepMap = allSteps.stream()
@ -2265,6 +2258,25 @@ public class ApiScenarioService extends MoveNodeService {
return apiScenarioDetail;
}
private void setStepCsvIds(String scenarioId, List<ApiScenarioStepDTO> allSteps) {
List<String> refScenarioIds = allSteps.stream()
.filter(step -> isRefOrPartialScenario(step))
.map(ApiScenarioStepCommonDTO::getResourceId)
.collect(Collectors.toList());
refScenarioIds.add(scenarioId);
//获取所有步骤的csv的关联关系
List<ApiScenarioCsvStep> csvSteps = extApiScenarioStepMapper.getCsvStepByScenarioIds(refScenarioIds);
// 构造 mapkey 为步骤IDvalue 为csv文件ID列表
Map<String, List<String>> stepsCsvMap = csvSteps.stream()
.collect(Collectors.groupingBy(ApiScenarioCsvStep::getStepId, Collectors.mapping(ApiScenarioCsvStep::getFileId, Collectors.toList())));
//将stepsCsvMap根据步骤id放入到allSteps中
if (CollectionUtils.isNotEmpty(allSteps)) {
allSteps.forEach(step -> step.setCsvIds(stepsCsvMap.get(step.getId())));
}
}
private List<CsvVariable> getCsvVariables(String scenarioId) {
ApiScenarioCsvExample example = new ApiScenarioCsvExample();
example.createCriteria().andScenarioIdEqualTo(scenarioId);