Skip to content

Commit a78eabc

Browse files
committed
Test PatchDocument::condition serde
1 parent 1faf6dc commit a78eabc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

sdk/cosmos/azure_data_cosmos/src/models/patch_operations.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@ mod tests {
266266
Ok(())
267267
}
268268

269+
#[test]
270+
pub fn serialize_condition() -> Result<(), Box<dyn std::error::Error>> {
271+
let patch_document = PatchDocument::default().with_condition("from c where c.value = 0");
272+
273+
let serialized = serde_json::to_string(&patch_document).unwrap();
274+
assert_eq!(
275+
serialized,
276+
"{\"condition\":\"from c where c.value = 0\",\"operations\":[]}"
277+
);
278+
Ok(())
279+
}
280+
269281
#[test]
270282
pub fn serialize_add() -> Result<(), Box<dyn std::error::Error>> {
271283
let patch_document = PatchDocument::default().with_add(
@@ -391,6 +403,30 @@ mod tests {
391403
Ok(())
392404
}
393405

406+
#[test]
407+
pub fn cosmos_docs_conditional_patch_example() -> Result<(), Box<dyn std::error::Error>> {
408+
const TEST_DOC: &str = r#"{
409+
"condition": "from c where c.Address.ZipCode = '98101'",
410+
"operations": [
411+
{
412+
"op":"replace",
413+
"path":"/Address/ZipCode",
414+
"value":98107
415+
}
416+
]
417+
}"#;
418+
419+
let doc: PatchDocument = serde_json::from_str(TEST_DOC)?;
420+
421+
assert_eq!(
422+
doc,
423+
PatchDocument::default()
424+
.with_condition("from c where c.Address.ZipCode = '98101'")
425+
.with_replace("/Address/ZipCode", 98107)?
426+
);
427+
Ok(())
428+
}
429+
394430
#[test]
395431
pub fn to_json_number_f64() -> Result<(), Box<dyn std::error::Error>> {
396432
assert_eq!(

0 commit comments

Comments
 (0)