From 4c7e31df200549192604b2c3ea5036b8d5111dae Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Tue, 23 Sep 2025 23:54:32 +0700 Subject: [PATCH] add patch error test Signed-off-by: Alexander Onnikov --- server/src/patch.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/src/patch.rs b/server/src/patch.rs index fe471e348d..36711db7ee 100644 --- a/server/src/patch.rs +++ b/server/src/patch.rs @@ -473,6 +473,30 @@ mod tests { ); } + #[test] + fn test_patch_err() { + let mut doc = json!({}); + + let patches = vec![ + PatchOperation::Standard(StandardPatchOperation::Add(json_patch::AddOperation { + path: PointerBuf::from_tokens(["a"]), + value: json!([]), + })), + PatchOperation::Standard(StandardPatchOperation::Add(json_patch::AddOperation { + path: PointerBuf::from_tokens(["a", "b"]), + value: json!(1), + })), + ]; + + let res = apply(&mut doc, &patches); + assert_eq!( + res, + Err(HulyPatchError::PatchError(String::from( + "operation '/0' failed at path '/a/b': path is invalid" + ))) + ); + } + #[test] fn test_deserialize_add_safe() { let patch = r#"{ "hop": "add", "path": "/a", "value": 1, "safe": true }"#;