fix(接口测试): 修复接口或用例同名数据源匹配错误问题

--bug=1012653 --user=赵勇 【接口测试】接口定义-接口case-添加前后置sql-切换运行环境-未使用同名的数据源 https://www.tapd.cn/55049933/s/1146978
This commit is contained in:
fit2-zhao 2022-04-25 18:06:41 +08:00 committed by fit2-zhao
parent 26c47c15fa
commit 3edaefef08
5 changed files with 163 additions and 32 deletions

View File

@ -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 => {

View File

@ -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();
},

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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();
},