fix: swagger 导入后无法保存
This commit is contained in:
parent
e88983ecb3
commit
cc7c5b9e23
|
@ -80,6 +80,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
projectId() {
|
||||||
|
this.initScenarioEnvironment();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
activated() {
|
||||||
|
this.initScenarioEnvironment();
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
createScenario: function () {
|
createScenario: function () {
|
||||||
this.scenarios.push(new Scenario());
|
this.scenarios.push(new Scenario());
|
||||||
|
@ -119,6 +129,22 @@
|
||||||
this.activeName = 0;
|
this.activeName = 0;
|
||||||
this.select(this.scenarios[0]);
|
this.select(this.scenarios[0]);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
initScenarioEnvironment: function () {
|
||||||
|
if (this.projectId) {
|
||||||
|
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
|
||||||
|
let environments = response.data;
|
||||||
|
let environmentMap = new Map();
|
||||||
|
environments.forEach(environment => {
|
||||||
|
environmentMap.set(environment.id, environment);
|
||||||
|
});
|
||||||
|
this.scenarios.forEach(scenario => {
|
||||||
|
if (scenario.environmentId) {
|
||||||
|
scenario.environment = environmentMap.get(scenario.environmentId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,6 @@
|
||||||
for (let i in this.environments) {
|
for (let i in this.environments) {
|
||||||
if (this.environments[i].id === this.scenario.environmentId) {
|
if (this.environments[i].id === this.scenario.environmentId) {
|
||||||
this.scenario.environment = this.environments[i];
|
this.scenario.environment = this.environments[i];
|
||||||
this.setRequestEnvironments();
|
|
||||||
hasEnvironment = true;
|
hasEnvironment = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +100,6 @@
|
||||||
for (let i in this.environments) {
|
for (let i in this.environments) {
|
||||||
if (this.environments[i].id === value) {
|
if (this.environments[i].id === value) {
|
||||||
this.scenario.environment = this.environments[i];
|
this.scenario.environment = this.environments[i];
|
||||||
this.setRequestEnvironments();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,11 +119,6 @@
|
||||||
},
|
},
|
||||||
environmentConfigClose() {
|
environmentConfigClose() {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
|
||||||
setRequestEnvironments() {
|
|
||||||
this.scenario.requests.forEach(request => {
|
|
||||||
request.environment = this.scenario.environment;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,8 +226,8 @@ export class HTTPSamplerProxy extends DefaultTestElement {
|
||||||
this.request = request || {};
|
this.request = request || {};
|
||||||
|
|
||||||
if (request.useEnvironment) {
|
if (request.useEnvironment) {
|
||||||
this.stringProp("HTTPSampler.domain", this.request.environment.domain);
|
this.stringProp("HTTPSampler.domain", request.domain);
|
||||||
this.stringProp("HTTPSampler.protocol", this.request.environment.protocol);
|
this.stringProp("HTTPSampler.protocol", request.protocol);
|
||||||
this.stringProp("HTTPSampler.path", this.request.path);
|
this.stringProp("HTTPSampler.path", this.request.path);
|
||||||
} else {
|
} else {
|
||||||
this.stringProp("HTTPSampler.domain", this.request.hostname);
|
this.stringProp("HTTPSampler.domain", this.request.hostname);
|
||||||
|
|
|
@ -160,6 +160,7 @@ export class Scenario extends BaseConfig {
|
||||||
this.headers = [];
|
this.headers = [];
|
||||||
this.requests = [];
|
this.requests = [];
|
||||||
this.environmentId = undefined;
|
this.environmentId = undefined;
|
||||||
|
this.environment = undefined;
|
||||||
|
|
||||||
this.set(options);
|
this.set(options);
|
||||||
this.sets({variables: KeyValue, headers: KeyValue, requests: Request}, options);
|
this.sets({variables: KeyValue, headers: KeyValue, requests: Request}, options);
|
||||||
|
@ -177,7 +178,7 @@ export class Scenario extends BaseConfig {
|
||||||
|
|
||||||
isValid() {
|
isValid() {
|
||||||
for (let i = 0; i < this.requests.length; i++) {
|
for (let i = 0; i < this.requests.length; i++) {
|
||||||
let validator = this.requests[i].isValid();
|
let validator = this.requests[i].isValid(this.environmentId);
|
||||||
if (!validator.isValid) {
|
if (!validator.isValid) {
|
||||||
return validator;
|
return validator;
|
||||||
}
|
}
|
||||||
|
@ -214,9 +215,9 @@ export class Request extends BaseConfig {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
isValid() {
|
isValid(environmentId) {
|
||||||
if (this.useEnvironment){
|
if (this.useEnvironment){
|
||||||
if (!this.environment) {
|
if (!environmentId) {
|
||||||
return {
|
return {
|
||||||
isValid: false,
|
isValid: false,
|
||||||
info: 'api_test.request.please_configure_environment_in_scenario'
|
info: 'api_test.request.please_configure_environment_in_scenario'
|
||||||
|
@ -423,7 +424,7 @@ const JMX_ASSERTION_CONDITION = {
|
||||||
}
|
}
|
||||||
|
|
||||||
class JMXRequest {
|
class JMXRequest {
|
||||||
constructor(request) {
|
constructor(request, environment) {
|
||||||
if (request && request instanceof Request && (request.url || request.path)) {
|
if (request && request instanceof Request && (request.url || request.path)) {
|
||||||
this.useEnvironment = request.useEnvironment;
|
this.useEnvironment = request.useEnvironment;
|
||||||
this.method = request.method;
|
this.method = request.method;
|
||||||
|
@ -435,10 +436,12 @@ class JMXRequest {
|
||||||
this.protocol = url.protocol.split(":")[0];
|
this.protocol = url.protocol.split(":")[0];
|
||||||
this.pathname = this.getPostQueryParameters(request, this.pathname);
|
this.pathname = this.getPostQueryParameters(request, this.pathname);
|
||||||
} else {
|
} else {
|
||||||
this.environment = request.environment;
|
if (environment) {
|
||||||
this.port = request.environment.port;
|
this.port = environment.port;
|
||||||
this.path = decodeURIComponent(request.path);
|
this.protocol = environment.protocol;
|
||||||
this.path = this.getPostQueryParameters(request, this.path);
|
this.domain = environment.domain;
|
||||||
|
}
|
||||||
|
this.path = this.getPostQueryParameters(request, decodeURIComponent(request.path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,7 +500,7 @@ class JMXGenerator {
|
||||||
scenario.requests.forEach(request => {
|
scenario.requests.forEach(request => {
|
||||||
if (!request.isValid()) return;
|
if (!request.isValid()) return;
|
||||||
|
|
||||||
let httpSamplerProxy = new HTTPSamplerProxy(request.name || "", new JMXRequest(request));
|
let httpSamplerProxy = new HTTPSamplerProxy(request.name || "", new JMXRequest(request, scenario.environment));
|
||||||
|
|
||||||
this.addRequestHeader(httpSamplerProxy, request);
|
this.addRequestHeader(httpSamplerProxy, request);
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,7 @@
|
||||||
maintainer: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
maintainer: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||||
priority: [{required: true, message: this.$t('test_track.case.input_priority'), trigger: 'change'}],
|
priority: [{required: true, message: this.$t('test_track.case.input_priority'), trigger: 'change'}],
|
||||||
type: [{required: true, message: this.$t('test_track.case.input_type'), trigger: 'change'}],
|
type: [{required: true, message: this.$t('test_track.case.input_type'), trigger: 'change'}],
|
||||||
testId: [{required: true, message: '请选择测试', trigger: 'change'}],
|
testId: [{required: true, message: this.$t('commons.please_select'), trigger: 'change'}],
|
||||||
method: [{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}],
|
method: [{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}],
|
||||||
prerequisite: [{max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}],
|
prerequisite: [{max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}],
|
||||||
remark: [{max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}]
|
remark: [{max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}]
|
||||||
|
|
Loading…
Reference in New Issue