fix(接口测试): 修复接口测试报告全选删除时删除所有的场景和接口报告的问题

--bug=1015725 --user=宋天阳
【接口测试】接口测试报告-全选接口报告-批量删除,会把场景报告也都删掉,全选场景报告也是
https://www.tapd.cn/55049933/s/1221535
This commit is contained in:
song-tianyang 2022-08-10 14:27:28 +08:00 committed by 建国
parent 15b9d260b5
commit acf13a286e
5 changed files with 67 additions and 39 deletions

View File

@ -23,5 +23,10 @@ public class QueryAPIReportRequest {
private Map<String, List<String>> filters;
private Map<String, Object> combine;
/**
* 查询哪种用例的报告 SCENARIO/API
*/
private String caseType;
private String limit;
}

View File

@ -203,7 +203,12 @@ public class ApiScenarioReportService {
public List<String> idList(QueryAPIReportRequest request) {
request = this.initRequest(request);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
return extApiScenarioReportMapper.idList(request);
//检查必填参数caseType
if (StringUtils.equalsAny(request.getCaseType(), ReportTypeConstants.API.name(), ReportTypeConstants.SCENARIO.name())) {
return extApiScenarioReportMapper.idList(request);
} else {
return new ArrayList<>(0);
}
}
private void checkNameExist(APIScenarioReportResult request) {
@ -694,13 +699,19 @@ public class ApiScenarioReportService {
}
public void deleteAPIReportBatch(APIReportBatchRequest reportRequest) {
List<String> ids = getIdsByDeleteBatchRequest(reportRequest);
ids = batchDeleteReportResource(reportRequest, ids, true);
if (reportRequest.getIsUi()) {
//ui报告对应的用例类型也是scenario
reportRequest.setCaseType(ReportTypeConstants.SCENARIO.name());
}
if (StringUtils.isNotBlank(reportRequest.getCaseType())) {
List<String> ids = getIdsByDeleteBatchRequest(reportRequest);
ids = batchDeleteReportResource(reportRequest, ids, true);
//处理最后剩余的数据
if (!ids.isEmpty()) {
deleteScenarioReportByIds(ids);
deleteApiDefinitionResultByIds(ids);
//处理报告关联数据
if (!ids.isEmpty()) {
deleteScenarioReportByIds(ids);
deleteApiDefinitionResultByIds(ids);
}
}
}
@ -952,10 +963,10 @@ public class ApiScenarioReportService {
if (StringUtils.isNotEmpty(dto.getRunMode()) && dto.getRunMode().startsWith("UI")) {
try {
errorSize = dto.getRequestResults().stream().filter(requestResult ->
StringUtils.isNotEmpty(requestResult.getResponseResult().getHeaders())
&& JSONArray.parseArray(requestResult.getResponseResult().getHeaders()).stream().filter(
r -> ((JSONObject) r).containsKey("success") && !((JSONObject) r).getBoolean("success")
).count() > 0)
StringUtils.isNotEmpty(requestResult.getResponseResult().getHeaders())
&& JSONArray.parseArray(requestResult.getResponseResult().getHeaders()).stream().filter(
r -> ((JSONObject) r).containsKey("success") && !((JSONObject) r).getBoolean("success")
).count() > 0)
.count();
} catch (Exception e) {
// UI 返回的结果在 headers 里面格式不符合规范的直接认定结果为失败

View File

@ -241,34 +241,37 @@
<select id="idList" resultType="java.lang.String">
select r.id from (
SELECT s_r.name AS test_name,
s_r.end_time,
s_r.user_id,
s_r.name,
s_r.id,
s_r.project_id,
s_r.create_time,
s_r.update_time,
s_r.status,
s_r.trigger_mode,
s_r.execute_type,
s_r.report_type
FROM api_scenario_report s_r
union all
select a_r.name as test_name,
a_r.end_time,
a_r.user_id,
a_r.name,
a_r.id,
a_r.project_id,
a_r.create_time,
a_r.create_time as update_time,
a_r.status,
a_r.trigger_mode,
'Saved' as execute_type,
'API_INDEPENDENT' as report_type
from api_definition_exec_result a_r
where a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'
<if test="request.caseType == 'SCENARIO'">
SELECT s_r.name AS test_name,
s_r.end_time,
s_r.user_id,
s_r.name,
s_r.id,
s_r.project_id,
s_r.create_time,
s_r.update_time,
s_r.status,
s_r.trigger_mode,
s_r.execute_type,
s_r.report_type
FROM api_scenario_report s_r
</if>
<if test="request.caseType == 'API'">
select a_r.name as test_name,
a_r.end_time,
a_r.user_id,
a_r.name,
a_r.id,
a_r.project_id,
a_r.create_time,
a_r.create_time as update_time,
a_r.status,
a_r.trigger_mode,
'Saved' as execute_type,
'API_INDEPENDENT' as report_type
from api_definition_exec_result a_r
where a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'
</if>
) r
<where>
<if test="request.combine != null">

View File

@ -1,6 +1,14 @@
package io.metersphere.commons.constants;
public enum ReportTypeConstants {
/**
* 所有场景类型包括接口场景UI场景
*/
SCENARIO,
/**
* 所有接口类型包括接口接口用例
*/
API,
SCENARIO_INTEGRATED,
SCENARIO_INDEPENDENT,
API_INTEGRATED,

View File

@ -385,6 +385,7 @@ export default {
sendParam.selectAllDate = this.isSelectAllDate;
sendParam.unSelectIds = this.unSelection;
sendParam = Object.assign(sendParam, this.condition);
sendParam.caseType = this.trashActiveDom === 'right' ? 'API' : 'SCENARIO';
this.$post('/api/scenario/report/batch/delete', sendParam, () => {
this.selectRows.clear();
this.$success(this.$t('commons.delete_success'));