fix(接口测试): 修复接口或用例同名数据源匹配错误问题
--bug=1012653 --user=赵勇 【接口测试】接口定义-接口case-添加前后置sql-切换运行环境-未使用同名的数据源 https://www.tapd.cn/55049933/s/1146978
This commit is contained in:
parent
26c47c15fa
commit
3edaefef08
|
@ -117,9 +117,6 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
if (!this.scenarioId) {
|
||||
this.request.environmentId = this.$store.state.useEnvironment;
|
||||
}
|
||||
this.getEnvironments();
|
||||
},
|
||||
computed: {
|
||||
|
@ -128,16 +125,23 @@ export default {
|
|||
},
|
||||
},
|
||||
watch: {
|
||||
// 场景环境监听
|
||||
'$store.state.scenarioEnvMap': {
|
||||
handler(v) {
|
||||
this.getEnvironments();
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
// 接口/用例 右上角公共环境监听
|
||||
'$store.state.useEnvironment': function () {
|
||||
if (!this.scenarioId) {
|
||||
this.request.environmentId = this.$store.state.useEnvironment;
|
||||
this.getEnvironments();
|
||||
this.getEnvironments(this.$store.state.useEnvironment);
|
||||
}
|
||||
},
|
||||
// 接口/用例 自身环境监听
|
||||
'request.environmentId': function () {
|
||||
if (!this.scenarioId) {
|
||||
this.initDataSource(undefined, undefined, this.request.targetDataSourceName);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -173,29 +177,40 @@ export default {
|
|||
runTest() {
|
||||
|
||||
},
|
||||
itselfEnvironment() {
|
||||
itselfEnvironment(environmentId) {
|
||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||
this.result = this.$get('/api/environment/list/' + id, response => {
|
||||
this.environments = response.data;
|
||||
let targetDataSourceName = undefined;
|
||||
this.environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
// 找到原始环境和数据源名称
|
||||
if (environment.id === this.request.environmentId) {
|
||||
if (environment.config && environment.config.databaseConfigs) {
|
||||
environment.config.databaseConfigs.forEach(item => {
|
||||
if (item.id === this.request.dataSourceId) {
|
||||
targetDataSourceName = item.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
this.initDataSource();
|
||||
if (environmentId) {
|
||||
this.request.environmentId = environmentId;
|
||||
}
|
||||
this.initDataSource(undefined, undefined, targetDataSourceName);
|
||||
});
|
||||
},
|
||||
getEnvironments() {
|
||||
getEnvironments(environmentId) {
|
||||
let envId = "";
|
||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||
let scenarioEnvId = this.scenarioId ? (this.scenarioId + "_" + id) : id;
|
||||
let scenarioEnvId = this.scenarioId !== "" ? (this.scenarioId + "_" + id) : id;
|
||||
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
||||
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
|
||||
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
|
||||
}
|
||||
if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) {
|
||||
this.itselfEnvironment();
|
||||
return;
|
||||
} else if (!this.scenarioId && !this.request.customizeReq) {
|
||||
this.itselfEnvironment();
|
||||
if (!this.scenarioId && !this.request.customizeReq) {
|
||||
this.itselfEnvironment(environmentId);
|
||||
return;
|
||||
}
|
||||
this.environments = [];
|
||||
|
@ -292,7 +307,6 @@ export default {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.databaseConfigsOptions = [];
|
||||
if (environment.config && environment.config.databaseConfigs) {
|
||||
environment.config.databaseConfigs.forEach(item => {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
:project-id="projectId"
|
||||
:is-read-only="isReadOnly"
|
||||
:useEnvironment='useEnvironment'
|
||||
@setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP'"/>
|
||||
@setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP' || api.protocol ==='TCP'"/>
|
||||
</el-col>
|
||||
<el-col :span="2">
|
||||
<!-- 保存操作 -->
|
||||
|
@ -100,10 +100,9 @@ export default {
|
|||
setEnvironment(data) {
|
||||
if (data) {
|
||||
this.$emit('setEnvironment', data.id);
|
||||
this.$store.state.scenarioEnvMap = new Map();
|
||||
this.$store.state.scenarioEnvMap.set(getCurrentProjectID(), data.id);
|
||||
}
|
||||
},
|
||||
|
||||
open() {
|
||||
this.$refs.searchBar.open();
|
||||
},
|
||||
|
|
|
@ -58,6 +58,7 @@ import {getCurrentProjectID, getUUID} from "@/common/js/utils";
|
|||
import MsDrawer from "../../../../common/components/MsDrawer";
|
||||
import {CASE_ORDER} from "../../model/JsonData";
|
||||
import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components";
|
||||
import {parseEnvironment} from "@/business/components/api/definition/model/EnvironmentModel";
|
||||
|
||||
export default {
|
||||
name: 'ApiCaseList',
|
||||
|
@ -223,6 +224,13 @@ export default {
|
|||
});
|
||||
},
|
||||
setEnvironment(environment) {
|
||||
if (this.environment !== environment) {
|
||||
if (this.apiCaseList && this.apiCaseList.length > 0) {
|
||||
if (this.apiCaseList[0].request && this.apiCaseList[0].request.hashTree) {
|
||||
this.setOwnEnvironment(this.apiCaseList[0].request.hashTree, environment);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.environment = environment;
|
||||
},
|
||||
sysAddition(apiCase) {
|
||||
|
@ -281,6 +289,39 @@ export default {
|
|||
refreshModule() {
|
||||
this.$emit('refreshModule');
|
||||
},
|
||||
setEnvironments(obj) {
|
||||
this.$get('/api/environment/list/' + this.projectId, response => {
|
||||
let environments = response.data;
|
||||
this.getTargetSource(environments, obj);
|
||||
});
|
||||
},
|
||||
getTargetSource(environments, obj) {
|
||||
environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
// 找到原始环境和数据源名称
|
||||
if (environment.id === obj.environmentId) {
|
||||
if (environment.config && environment.config.databaseConfigs) {
|
||||
environment.config.databaseConfigs.forEach(item => {
|
||||
if (item.id === obj.dataSourceId) {
|
||||
obj.targetDataSourceName = item.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
setOwnEnvironment(scenarioDefinition, env) {
|
||||
for (let i in scenarioDefinition) {
|
||||
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||
this.setEnvironments(scenarioDefinition[i]);
|
||||
scenarioDefinition[i].environmentId = env;
|
||||
}
|
||||
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);
|
||||
}
|
||||
}
|
||||
},
|
||||
runRefresh(data) {
|
||||
this.batchLoadingIds = [];
|
||||
this.singleLoading = false;
|
||||
|
|
|
@ -92,11 +92,45 @@
|
|||
this.currentData.environmentId = value;
|
||||
if (this.currentData.request) {
|
||||
this.currentData.request.useEnvironment = value;
|
||||
// 更改当前步骤中含SQL前后置步骤对应的数据源
|
||||
if(this.currentData.request.hashTree) {
|
||||
// 找到原始环境和数据源名称
|
||||
let environment = this.environments[i];
|
||||
this.setOwnEnvironment(this.currentData.request.hashTree, environment);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
getTargetSource(obj){
|
||||
this.environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
// 找到原始环境和数据源名称
|
||||
if (environment.id === obj.environmentId) {
|
||||
if (environment.config && environment.config.databaseConfigs) {
|
||||
environment.config.databaseConfigs.forEach(item => {
|
||||
if (item.id === obj.dataSourceId) {
|
||||
obj.targetDataSourceName = item.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
setOwnEnvironment(scenarioDefinition,env) {
|
||||
for (let i in scenarioDefinition) {
|
||||
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||
// 找到原始数据源名称
|
||||
this.getTargetSource(scenarioDefinition[i])
|
||||
scenarioDefinition[i].environmentId = env.id;
|
||||
}
|
||||
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||
this.setOwnEnvironment(scenarioDefinition[i].hashTree,env);
|
||||
}
|
||||
}
|
||||
},
|
||||
openEnvironmentConfig() {
|
||||
if (!this.projectId) {
|
||||
this.$error(this.$t('api_test.select_project'));
|
||||
|
@ -104,10 +138,10 @@
|
|||
}
|
||||
this.$refs.environmentConfig.open(this.projectId);
|
||||
},
|
||||
setEnvironment(enviromentId){
|
||||
this.currentData.environmentId = enviromentId;
|
||||
setEnvironment(environmentId){
|
||||
this.currentData.environmentId = environmentId;
|
||||
if (this.currentData.request) {
|
||||
this.currentData.request.useEnvironment = enviromentId;
|
||||
this.currentData.request.useEnvironment = environmentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,9 +176,8 @@ export default {
|
|||
deep: true
|
||||
},
|
||||
'$store.state.useEnvironment': function () {
|
||||
if (!this.scenarioId) {
|
||||
this.request.environmentId = this.$store.state.useEnvironment;
|
||||
this.getEnvironments();
|
||||
if (this.scenarioId !== "") {
|
||||
this.getEnvironments(this.$store.state.useEnvironment);
|
||||
}
|
||||
},
|
||||
'$store.state.scenarioEnvMap': {
|
||||
|
@ -263,17 +262,32 @@ export default {
|
|||
runTest() {
|
||||
|
||||
},
|
||||
itselfEnvironment() {
|
||||
itselfEnvironment(environmentId) {
|
||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||
this.result = this.$get('/api/environment/list/' + id, response => {
|
||||
this.environments = response.data;
|
||||
let targetDataSourceName = undefined;
|
||||
let currentEnvironment = undefined;
|
||||
this.environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
// 找到原始环境和数据源名称
|
||||
if (environment.id === environmentId) {
|
||||
currentEnvironment = environment;
|
||||
}
|
||||
if (environment.id === this.request.environmentId) {
|
||||
if (environment.config && environment.config.databaseConfigs) {
|
||||
environment.config.databaseConfigs.forEach(item => {
|
||||
if (item.id === this.request.dataSourceId) {
|
||||
targetDataSourceName = item.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
this.initDataSource();
|
||||
this.initDataSource(environmentId, currentEnvironment, targetDataSourceName);
|
||||
});
|
||||
},
|
||||
getEnvironments() {
|
||||
getEnvironments(environmentId) {
|
||||
let envId = "";
|
||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||
let scenarioEnvId = this.request.currentScenarioId ? (this.request.currentScenarioId + "_" + id) : id;
|
||||
|
@ -281,13 +295,11 @@ export default {
|
|||
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
|
||||
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
|
||||
}
|
||||
if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) {
|
||||
alert(2222)
|
||||
this.itselfEnvironment();
|
||||
if (this.request.referenced === 'Created' && this.scenarioId !== "" && !this.request.isRefEnvironment) {
|
||||
this.itselfEnvironment(environmentId);
|
||||
return;
|
||||
} else if (!this.scenarioId && !this.request.customizeReq) {
|
||||
alert(333)
|
||||
this.itselfEnvironment();
|
||||
this.itselfEnvironment(environmentId);
|
||||
return;
|
||||
}
|
||||
this.environments = [];
|
||||
|
@ -384,10 +396,41 @@ export default {
|
|||
this.environments[i].config.databaseConfigs.forEach(item => {
|
||||
this.databaseConfigsOptions.push(item);
|
||||
})
|
||||
if (this.request.hashTree && !this.scenarioId) {
|
||||
this.setOwnEnvironment(this.request.hashTree, value)
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
setOwnEnvironment(scenarioDefinition, env) {
|
||||
for (let i in scenarioDefinition) {
|
||||
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||
// 找到原始数据源名称
|
||||
this.getTargetSource(scenarioDefinition[i])
|
||||
scenarioDefinition[i].environmentId = env;
|
||||
}
|
||||
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);
|
||||
}
|
||||
}
|
||||
},
|
||||
getTargetSource(obj) {
|
||||
this.environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
// 找到原始环境和数据源名称
|
||||
if (environment.id === obj.environmentId) {
|
||||
if (environment.config && environment.config.databaseConfigs) {
|
||||
environment.config.databaseConfigs.forEach(item => {
|
||||
if (item.id === obj.dataSourceId) {
|
||||
obj.targetDataSourceName = item.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
environmentConfigClose() {
|
||||
this.getEnvironments();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue