fix(接口测试): form-data请求体,参数同步有误

--bug=1045452 --user=陈建星 【接口测试】-API请求体参数名变更后,不开启删除无法对应的参数情况下同步,旧的参数依旧会被删除 https://www.tapd.cn/55049933/s/1566030
This commit is contained in:
AgAngle 2024-08-20 17:15:16 +08:00 committed by Craftsman
parent 3a71d97845
commit 5165988f48
2 changed files with 7 additions and 1 deletions

View File

@ -303,7 +303,7 @@ public class HttpRequestParamDiffUtils {
* @return * @return
*/ */
public static Body syncBodyDiff(boolean isDeleteRedundantParam, Body sourceBody, Body targetBody) { 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; return sourceBody;
} }
Body.BodyType bodyType = EnumValidator.validateEnum(Body.BodyType.class, sourceBody.getBodyType()); Body.BodyType bodyType = EnumValidator.validateEnum(Body.BodyType.class, sourceBody.getBodyType());

View File

@ -766,6 +766,12 @@ public class HttpRequestParamDiffUtilsTests {
sourceBody.getFormDataBody().getFormValues().add(formDataKV); sourceBody.getFormDataBody().getFormValues().add(formDataKV);
result = HttpRequestParamDiffUtils.syncBodyDiff(true, sourceBody, targetBody); result = HttpRequestParamDiffUtils.syncBodyDiff(true, sourceBody, targetBody);
Assertions.assertEquals(result.getFormDataBody(), sourceBody.getFormDataBody()); 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()); sourceBody.setBodyType(Body.BodyType.WWW_FORM.name());
targetBody.setBodyType(Body.BodyType.WWW_FORM.name()); targetBody.setBodyType(Body.BodyType.WWW_FORM.name());