fix(接口测试): 接口定义模块数量显示与列表不一致

--bug=1044789 --user=陈建星 【接口测试】接口定义-按照路径搜索后,左侧模块树结果是空 https://www.tapd.cn/55049933/s/1561339
This commit is contained in:
AgAngle 2024-08-13 11:05:36 +08:00 committed by Craftsman
parent 9357d86adc
commit 0c6223a8e2
2 changed files with 20 additions and 183 deletions

View File

@ -45,14 +45,14 @@
protocol
FROM api_definition
where api_definition.deleted = #{deleted}
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.api.mapper.ExtApiDefinitionMapper.queryWhereCondition"/>
ORDER BY pos DESC
</select>
<select id="countModuleIdByRequest" resultType="io.metersphere.project.dto.ModuleCountDTO">
SELECT module_id AS moduleId, count(id) AS dataCount
FROM api_definition
where api_definition.deleted = #{deleted}
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.api.mapper.ExtApiDefinitionMapper.queryWhereCondition"/>
<if test="request.testPlanId != null and request.testPlanId != ''">
and exists (
select id
@ -165,44 +165,12 @@
</where>
</sql>
<sql id="queryWhereCondition">
<if test="request.keyword != null and request.keyword != ''">
and (
api_definition.num like concat('%', #{request.keyword},'%')
or api_definition.name like concat('%', #{request.keyword},'%')
or api_definition.tags like concat('%', #{request.keyword},'%')
)
</if>
<if test="request.projectId != null and request.projectId != ''">
and api_definition.project_id = #{request.projectId}
</if>
<if test="request.protocols != null and request.protocols.size() >0 ">
AND api_definition.protocol in
<foreach collection="request.protocols" item="protocol" separator="," open="(" close=")">
#{protocol}
</foreach>
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
and api_definition.module_id in
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<include refid="filters">
<property name="filter" value="request.filter"/>
</include>
<sql id="filters">
<include refid="io.metersphere.api.mapper.ExtApiDefinitionMapper.filters"/>
</sql>
<if test="request.combine != null and request.combine != ''">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
<property name="ObjectTags" value="request.combine.tags"/>
</include>
</if>
<include refid="queryVersionCondition">
<property name="versionTable" value="api_definition"/>
</include>
<sql id="combine">
<include refid="io.metersphere.api.mapper.ExtApiDefinitionMapper.combine"/>
</sql>
<sql id="queryVersionCondition">
@ -216,150 +184,7 @@
AND ${versionTable}.latest = 1
</if>
</sql>
<sql id="combine">
<if test='${condition}.name != null and (${name} == null or ${name} == "")'>
and api_definition.name
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.name"/>
</include>
</if>
<if test='${condition}.id != null'>
and api_definition.num
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.id"/>
</include>
</if>
<if test="${condition}.updateTime != null">
and api_definition.update_time
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.updateTime"/>
</include>
</if>
<if test="${condition}.createTime != null">
and api_definition.create_time
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.createTime"/>
</include>
</if>
<if test="${condition}.status != null">
and api_definition.status
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.status"/>
</include>
</if>
<if test="${condition}.path != null">
and api_definition.path
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.path"/>
</include>
</if>
<if test="${condition}.method != null">
and api_definition.method
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.method"/>
</include>
</if>
<if test='${condition}.tags != null and ${ObjectTags}.operator == "not like"'>
and (api_definition.tags is null or api_definition.tags
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.tags"/>
</include>
)
</if>
<if test='${condition}.tags != null and ${ObjectTags}.operator == "like"'>
and api_definition.tags
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.tags"/>
</include>
</if>
<if test="${condition}.customs != null and ${condition}.customs.size() > 0">
<foreach collection="${condition}.customs" item="custom" separator="" open="" close="">
<if test="custom.value != ''">
<if test='custom.operator == "not like" or custom.operator == "not in"'>
and api_definition.id not in (
</if>
<if test='custom.operator != "not like" and custom.operator != "not in"'>
and api_definition.id in (
</if>
select api_id from api_definition_custom_field where field_id = #{custom.id}
<choose>
<when test="custom.type == 'TEXTAREA' or custom.operator == 'current user'">
and `value`
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="custom"/>
</include>
</when>
<when test="custom.type == 'MULTIPLE_MEMBER' or custom.type == 'CHECKBOX' or custom.type == 'MULTIPLE_SELECT'">
and ${custom.value}
</when>
<when test="custom.type == 'DATE' or custom.type == 'DATETIME'">
and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13)
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="custom"/>
</include>
</when>
<otherwise>
and trim(both '"' from `value`)
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="custom"/>
</include>
</otherwise>
</choose>
)
</if>
</foreach>
</if>
</sql>
<sql id="filters">
<if test="${filter} != null and ${filter}.size() > 0">
<foreach collection="${filter}.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='status'">
and api_definition.status in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='method'">
and api_definition.method in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='create_user'">
and api_definition.create_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='version_id'">
and api_definition.version_id in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key.startsWith('custom_single')">
and api_definition.id in (
select api_id from api_definition_custom_field where concat('custom_single_', field_id) = #{key}
and trim(both '"' from `value`) in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
)
</when>
<when test="key.startsWith('custom_multiple')">
and api_definition.id in (
select api_id from api_definition_custom_field where concat('custom_multiple_', field_id) = #{key}
and
<include refid="io.metersphere.system.mapper.BaseMapper.filterMultipleWrapper"/>
)
</when>
</choose>
</if>
</foreach>
</if>
</sql>
<sql id="module_request">
<where>
<if test="request.projectId != null and request.projectId != ''">
@ -388,7 +213,7 @@
INNER JOIN api_test_case ON api_definition.id = api_test_case.api_definition_id
WHERE
api_test_case.deleted = #{deleted}
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.api.mapper.ExtApiDefinitionMapper.queryWhereCondition"/>
<if test="request.testPlanId != null and request.testPlanId != ''">
and exists (
select id

View File

@ -66,6 +66,7 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
private static Project project;
private static List<BaseTreeNode> preliminaryTreeNodes = new ArrayList<>();
private static ApiDefinition apiDefinition;
private final ProjectServiceInvoker serviceInvoker;
@Resource
private ProjectMapper projectMapper;
@ -158,6 +159,8 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
apiDefinitionBlob.setResponse(new byte[0]);
apiDefinitionBlobMapper.insertSelective(apiDefinitionBlob);
this.apiDefinition = apiDefinition;
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiTestCaseMapper caseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
@ -837,6 +840,15 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
request.setTestPlanId("wx_123");
testPlanConfigMapper.insertSelective(planConfig);
this.requestPostWithOkAndReturn(URL_FILE_MODULE_COUNT, request);
request = new ApiModuleRequest() {{
this.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
this.setProjectId(project.getId());
}};
request.setKeyword(apiDefinition.getPath());
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_FILE_MODULE_COUNT, request);
Map countMap = getResultData(mvcResult, Map.class);
Assertions.assertEquals(countMap.get(apiDefinition.getModuleId()), 1);
}
@Test