From 5165988f4888669a6c5f336c7f1ba35a95cae5ef Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 20 Aug 2024 17:15:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20fo?= =?UTF-8?q?rm-data=E8=AF=B7=E6=B1=82=E4=BD=93=EF=BC=8C=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1045452 --user=陈建星 【接口测试】-API请求体参数名变更后,不开启删除无法对应的参数情况下同步,旧的参数依旧会被删除 https://www.tapd.cn/55049933/s/1566030 --- .../io/metersphere/api/utils/HttpRequestParamDiffUtils.java | 2 +- .../api/utils/HttpRequestParamDiffUtilsTests.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/utils/HttpRequestParamDiffUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/utils/HttpRequestParamDiffUtils.java index 505c2a6be7..281b6681ed 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/utils/HttpRequestParamDiffUtils.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/utils/HttpRequestParamDiffUtils.java @@ -303,7 +303,7 @@ public class HttpRequestParamDiffUtils { * @return */ public static Body syncBodyDiff(boolean isDeleteRedundantParam, Body sourceBody, Body targetBody) { - if (sourceBody == null || targetBody == null || sourceBody.getBodyType() != targetBody.getBodyType()) { + if (sourceBody == null || targetBody == null || !StringUtils.equals(sourceBody.getBodyType(), targetBody.getBodyType())) { return sourceBody; } Body.BodyType bodyType = EnumValidator.validateEnum(Body.BodyType.class, sourceBody.getBodyType()); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/utils/HttpRequestParamDiffUtilsTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/utils/HttpRequestParamDiffUtilsTests.java index 138840d57d..0974239532 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/utils/HttpRequestParamDiffUtilsTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/utils/HttpRequestParamDiffUtilsTests.java @@ -766,6 +766,12 @@ public class HttpRequestParamDiffUtilsTests { sourceBody.getFormDataBody().getFormValues().add(formDataKV); result = HttpRequestParamDiffUtils.syncBodyDiff(true, sourceBody, targetBody); Assertions.assertEquals(result.getFormDataBody(), sourceBody.getFormDataBody()); + FormDataKV formDataKV2 = new FormDataKV(); + formDataKV2.setKey("key2"); + formDataKV2.setValue("value2"); + targetBody.getFormDataBody().getFormValues().add(formDataKV); + result = HttpRequestParamDiffUtils.syncBodyDiff(true, sourceBody, targetBody); + Assertions.assertNotEquals(result.getFormDataBody(), sourceBody.getFormDataBody()); sourceBody.setBodyType(Body.BodyType.WWW_FORM.name()); targetBody.setBodyType(Body.BodyType.WWW_FORM.name());