fix(接口测试): 支持接口定义和用例添加步骤时继承当前请求的环境和数据源

This commit is contained in:
fit2-zhao 2022-04-26 10:39:47 +08:00 committed by fit2-zhao
parent 6c84ebff0f
commit d3b41b1caa
2 changed files with 52 additions and 9 deletions

View File

@ -100,11 +100,12 @@ export default {
api: {},
envMap: new Map,
maintainerOptions: [],
environments: []
};
},
watch: {
'$store.state.useEnvironment': function () {
this.environment = this.$store.state.useEnvironment;
this.setEnvironment(this.$store.state.useEnvironment);
},
refreshSign() {
this.api = this.currentApi;
@ -289,13 +290,43 @@ export default {
refreshModule() {
this.$emit('refreshModule');
},
setEnvironments(obj) {
this.$get('/api/environment/list/' + this.projectId, response => {
let environments = response.data;
this.getTargetSource(environments, obj);
});
setNewSource(environment, obj) {
if (environment.config && environment.config.databaseConfigs) {
let dataSources = environment.config.databaseConfigs.filter(item => item.name === obj.targetDataSourceName);
if (dataSources && dataSources.length > 0) {
obj.dataSourceId = dataSources[0].id;
} else {
obj.dataSourceId = environment.config.databaseConfigs[0].id;
}
}
},
getTargetSource(environments, obj) {
getEnvironments(obj, env) {
if (this.environments.length === 0) {
this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data;
//
this.getTargetSourceName(this.environments, obj);
//
obj.environmentId = env;
//
let envs = this.environments.filter(tab => tab.id === env);
if (envs && envs.length > 0) {
this.setNewSource(envs[0], obj);
}
});
} else {
//
this.getTargetSourceName(this.environments, obj);
//
obj.environmentId = env;
//
let envs = this.environments.filter(tab => tab.id === env);
if (envs && envs.length > 0) {
this.setNewSource(envs[0], obj);
}
}
},
getTargetSourceName(environments, obj) {
environments.forEach(environment => {
parseEnvironment(environment);
//
@ -314,8 +345,7 @@ export default {
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;
this.getEnvironments(scenarioDefinition[i], env);
}
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);

View File

@ -249,9 +249,22 @@ export default {
} else {
this.addAssertions();
}
//
if (this.request.hashTree && this.request.hashTree.length > 0) {
this.setOwnEnvironment(this.request.hashTree);
}
this.sort();
this.reload();
},
setOwnEnvironment(scenarioDefinition) {
for (let i in scenarioDefinition) {
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
scenarioDefinition[i].environmentId = this.request.environmentId;
scenarioDefinition[i].dataSourceId = this.request.dataSourceId;
}
}
},
filterNode(value, data) {
if (data.type && value.indexOf(data.type) !== -1) {
return true;