From 27fac113c95e59458524cd6794f72b2b9d6348c7 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 26 May 2021 13:42:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=9C=BA=E6=99=AF=E5=87=BA=E7=8E=B0=E7=A9=BA=E7=99=BD?= =?UTF-8?q?=E6=B0=94=E6=B3=A1=E5=BC=B9=E7=AA=97=E3=80=81=E4=BB=8Emock?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=87=BA=E6=9D=A5=E7=9A=84=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=20=E4=BC=9A=E5=AF=BC=E8=87=B4=E6=89=A7=E8=A1=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=97=B6=E9=BB=98=E8=AE=A4=E5=B8=A6=E4=B8=8Amock?= =?UTF-8?q?=E7=9A=84=E8=B7=AF=E5=BE=84):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复:创建场景出现空白气泡弹窗、从mock复制出来的环境 会导致执行测试时默认带上mock的路径 --- .../api/service/ApiTestEnvironmentService.java | 17 +++++++++++++++++ .../api/automation/scenario/EditApiScenario.vue | 2 +- .../test/components/ApiEnvironmentConfig.vue | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java index 6523f1636f..b84be7e3f6 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java @@ -86,10 +86,27 @@ public class ApiTestEnvironmentService { request.setCreateUser(SessionUtils.getUserId()); checkEnvironmentExist(request); FileUtils.createFiles(request.getUploadIds(), sslFiles, FileUtils.BODY_FILE_DIR + "/ssl"); + //检查Config,判断isMock参数是否给True + request = this.updateConfig(request,false); apiTestEnvironmentMapper.insert(request); return request.getId(); } + private ApiTestEnvironmentDTO updateConfig(ApiTestEnvironmentDTO request, boolean isMock) { + if(StringUtils.isNotEmpty(request.getConfig())){ + try{ + JSONObject configObj = JSONObject.parseObject(request.getConfig()); + if(configObj.containsKey("httpConfig")){ + JSONObject httpObj = configObj.getJSONObject("httpConfig"); + httpObj.put("isMock",isMock); + } + request.setConfig(configObj.toJSONString()); + }catch (Exception e){ + } + } + return request; + } + public void update(ApiTestEnvironmentDTO apiTestEnvironment,List sslFiles) { checkEnvironmentExist(apiTestEnvironment); FileUtils.createFiles(apiTestEnvironment.getUploadIds(), sslFiles, FileUtils.BODY_FILE_DIR + "/ssl"); diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 8b1cea2371..98ed99af03 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -110,7 +110,7 @@ {{ currentScenario.name === undefined || '' ? $t('api_test.scenario.name') : currentScenario.name }} diff --git a/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue b/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue index bf681eacbb..401cad8585 100644 --- a/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue +++ b/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue @@ -70,6 +70,8 @@ } }, copyEnvironment(environment) { + //点击复制的时候先选择改行,否则会出现解析错误 + this.environmentSelected(environment); this.currentEnvironment = environment; if (!environment.id) { this.$warning(this.$t('commons.please_save'));