fix(项目设置): 修改环境配置-全局断言中json文档断言添加失败的缺陷

--bug=1019018 --user=宋天阳 [项目设置]项目环境-编辑项目环境-全局断言添加文档结果校验json格式失败
https://www.tapd.cn/55049933/s/1280284
This commit is contained in:
song-tianyang 2022-10-27 15:36:20 +08:00 committed by 刘瑞斌
parent 55401c04b3
commit f8ad0fb0a8
13 changed files with 48 additions and 39 deletions

View File

@ -246,14 +246,14 @@ export default {
this.environment.config.authManager.hashTree = [];
}
if (!this.environment.config.assertions) {
this.environment.config.assertions = {
this.$set(this.environment.config, 'assertions', {
duration: {duration: 0},
regex: [],
jsonPath: [],
xpath2: [],
jsr223: [],
document: {type: "json", data: {json: [], xml: []}},
};
document: {type: "JSON", data: {json: [], xml: []}},
});
}
},
@ -295,14 +295,14 @@ export default {
this.environment.config.authManager.hashTree = [];
}
if (!this.environment.config.assertions) {
this.environment.config.assertions = {
this.$set(this.environment.config, 'assertions', {
duration: {duration: 0},
regex: [],
jsonPath: [],
xpath2: [],
jsr223: [],
document: {type: "json", data: {json: [], xml: []}},
};
document: {type: "JSON", data: {json: [], xml: []}},
});
}
this.isRefresh = false;

View File

@ -10,9 +10,11 @@
</el-col>
<el-col class="assertion-btn">
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
<el-switch v-model="duration.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right: 10px"/>
<el-switch v-model="duration.enable" class="enable-switch" size="mini" :disabled="isReadOnly"
style="width: 30px;margin-right: 10px"/>
</el-tooltip>
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/>
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove"
v-if="edit"/>
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
{{ $t('api_test.request.assertions.add') }}
</el-button>
@ -71,7 +73,7 @@ export default {
<style scoped>
.assertion-btn {
text-align: center;
width: 80px;
text-align: right;
width: 180px;
}
</style>

View File

@ -27,9 +27,11 @@
</el-col>
<el-col class="assertion-btn">
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
<el-switch v-model="jsonPath.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right: 10px"/>
<el-switch v-model="jsonPath.enable" class="enable-switch" size="mini" :disabled="isReadOnly"
style="width: 30px;margin-right: 10px"/>
</el-tooltip>
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/>
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove"
v-if="edit"/>
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
{{ $t('api_test.request.assertions.add') }}
</el-button>
@ -124,7 +126,7 @@ export default {
}
.assertion-btn {
text-align: center;
width: 80px;
text-align: right;
width: 180px;
}
</style>

View File

@ -116,7 +116,7 @@ export default {
}
.assertion-btn {
text-align: center;
text-align: right;
width: 180px;
}
</style>

View File

@ -7,9 +7,11 @@
</el-col>
<el-col class="assertion-btn">
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
<el-switch v-model="xPath2.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right:10px"/>
<el-switch v-model="xPath2.enable" class="enable-switch" size="mini" :disabled="isReadOnly"
style="width: 30px;margin-right:10px"/>
</el-tooltip>
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/>
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove"
v-if="edit"/>
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
{{ $t('api_test.request.assertions.add') }}
</el-button>
@ -60,7 +62,7 @@ export default {
<style scoped>
.assertion-btn {
text-align: center;
width: 80px;
text-align: right;
width: 180px;
}
</style>

View File

@ -116,7 +116,7 @@ export default {
computed: {
isShow() {
let rt = this.assertions.duration;
return rt.value && rt.value !== 0;
return rt.value && rt.value !== 0;
},
isDocument() {
return this.assertions.document && this.assertions.document.data && (this.assertions.document.data.json.length > 0 || this.assertions.document.data.xml.length > 0);
@ -176,7 +176,7 @@ export default {
}
.assertion-remove-btn {
text-align: center;
width: 80px;
text-align: right;
width: 180px;
}
</style>

View File

@ -38,7 +38,7 @@
</template>
<script>
import {Regex, ASSERTION_REGEX_SUBJECT} from "../../../model/ApiTestModel";
import {ASSERTION_REGEX_SUBJECT, Regex} from "../../../model/ApiTestModel";
export default {
name: "MsApiAssertionText",
@ -123,6 +123,6 @@ export default {
}
.assertion-btn {
width: 60px;
width: 180px;
}
</style>

View File

@ -37,7 +37,7 @@ export default {
methods: {
add() {
let obj = new AssertionDocument({id: "root"});
if (this.document.type === "JSON" && this.document.data.json.length === 0) {
if (this.document.type === "JSON" || this.document.type === "json" && this.document.data.json.length === 0) {
this.document.data.json.push(obj);
}
if (this.document.type === "XML" && this.document.data.xml.length === 0) {
@ -62,7 +62,7 @@ export default {
<style scoped>
.assertion-btn {
text-align: center;
width: 60px;
text-align: right;
width: 180px;
}
</style>

View File

@ -112,9 +112,7 @@
<script>
import {
getCurrentProjectID, getCurrentUserId
} from "metersphere-frontend/src/utils/token";
import {getCurrentProjectID, getCurrentUserId} from "metersphere-frontend/src/utils/token";
import {listenGoBack, removeGoBackListener} from "metersphere-frontend/src/utils";
import MsFormDivider from "metersphere-frontend/src/components/MsFormDivider";
import {ASSERTION_REGEX_SUBJECT, ASSERTION_TYPE, Regex} from "metersphere-frontend/src/model/ApiTestModel";
@ -154,7 +152,7 @@ export default {
jsonPath: [],
xpath2: [],
jsr223: [],
document: {type: "json", data: {json: [], xml: []}},
document: {type: "JSON", data: {json: [], xml: []}},
},
},
rules: {

View File

@ -54,6 +54,6 @@ public class HistoryReportController {
@PostMapping("/selectById")
public ReportStatisticsWithBLOBs selectById(@RequestBody ReportStatisticsSaveRequest request) {
return reportStatisticsService.selectById(request.getId());
return reportStatisticsService.selectById(request.getId(), false);
}
}

View File

@ -18,6 +18,6 @@ public class ReportStatShareController {
@PostMapping("/select/report/by/id")
public ReportStatisticsWithBLOBs selectById(@RequestBody ReportStatisticsSaveRequest request) {
return reportStatisticsService.selectById(request.getId());
return reportStatisticsService.selectById(request.getId(), true);
}
}

View File

@ -476,7 +476,7 @@ public class EnterpriseTestReportService {
List<ReportStatisticsWithBLOBs> bloBsList = new ArrayList<>();
for (EnterpriseReportContentStep step : stepList) {
//定时任务触发的数据需要检查图片是否需要重新生成
ReportStatisticsWithBLOBs reportStatisticsWithBLOBs = reportStatisticsService.selectById(step.getReportRecordId());
ReportStatisticsWithBLOBs reportStatisticsWithBLOBs = reportStatisticsService.selectById(step.getReportRecordId(), false);
if (reportStatisticsWithBLOBs != null) {
boolean needSyncImage = reportStatisticsService.isReportNeedUpdate(reportStatisticsWithBLOBs);
if (needSyncImage) {

View File

@ -4,10 +4,7 @@ import io.metersphere.base.domain.ReportStatistics;
import io.metersphere.base.domain.ReportStatisticsExample;
import io.metersphere.base.domain.ReportStatisticsWithBLOBs;
import io.metersphere.base.mapper.ReportStatisticsMapper;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.commons.utils.*;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.reportstatistics.dto.*;
import io.metersphere.reportstatistics.dto.charts.Series;
@ -74,11 +71,16 @@ public class ReportStatisticsService {
return reportStatisticsMapper.deleteByPrimaryKey(id);
}
public ReportStatisticsWithBLOBs selectById(String id) {
public ReportStatisticsWithBLOBs selectById(String id, boolean isRemoteRequest) {
ReportStatisticsWithBLOBs blob = reportStatisticsMapper.selectByPrimaryKey(id);
if (blob == null) {
return null;
}
if (isRemoteRequest) {
//通过接口进行的请求时没有session的
HttpHeaderUtils.runAsUser(blob.getCreateUser());
}
Map<String, Object> selectOption = JSON.parseObject(blob.getSelectOption(), Map.class);
Map<String, Object> dataOption = JSON.parseObject(blob.getDataOption(), Map.class);
boolean isReportNeedUpdate = this.isReportNeedUpdate(blob);
@ -90,6 +92,9 @@ public class ReportStatisticsService {
}
}
if (isRemoteRequest) {
HttpHeaderUtils.clearUser();
}
if (!dataOption.containsKey("showTable")) {
if (dataOption.get("tableData") != null) {
String tableDataJsonStr = JSON.toJSONString(dataOption.get("tableData"));