@@ -2043,6 +2043,40 @@ mod tests {
2043
2043
assert_eq ! ( res. offset, 2 ) ;
2044
2044
}
2045
2045
2046
+ #[ meilisearch_test]
2047
+ async fn test_update_document_json ( client : Client , index : Index ) -> Result < ( ) , Error > {
2048
+ let old_json = r#"{ "id": 1, "body": "doggo" }{ "id": 2, "body": "catto" }"# . as_bytes ( ) ;
2049
+ let updated_json = r#"{ "id": 1, "second_body": "second_doggo" }{ "id": 2, "second_body": "second_catto" }"# . as_bytes ( ) ;
2050
+
2051
+ let task = index
2052
+ . add_documents ( old_json, Some ( "id" ) )
2053
+ . await ?
2054
+ . wait_for_completion ( & client, None , None )
2055
+ . await ?;
2056
+ let _ = index. get_task ( task) . await ?;
2057
+
2058
+ let task = index
2059
+ . add_or_update ( updated_json, None )
2060
+ . await ?
2061
+ . wait_for_completion ( & client, None , None )
2062
+ . await ?;
2063
+
2064
+ let status = index. get_task ( task) . await ?;
2065
+ let elements = index. get_documents :: < serde_json:: Value > ( ) . await . unwrap ( ) ;
2066
+
2067
+ assert ! ( matches!( status, Task :: Succeeded { .. } ) ) ;
2068
+ assert_eq ! ( elements. results. len( ) , 2 ) ;
2069
+
2070
+ let expected_result = vec ! [
2071
+ json!( { "body" : "doggo" , "id" : 1 , "second_body" : "second_doggo" } ) ,
2072
+ json!( { "body" : "catto" , "id" : 2 , "second_body" : "second_catto" } ) ,
2073
+ ] ;
2074
+
2075
+ assert_eq ! ( elements. results, expected_result) ;
2076
+
2077
+ Ok ( ( ) )
2078
+ }
2079
+
2046
2080
#[ meilisearch_test]
2047
2081
async fn test_add_documents_ndjson ( client : Client , index : Index ) -> Result < ( ) , Error > {
2048
2082
let ndjson = r#"{ "id": 1, "body": "doggo" }{ "id": 2, "body": "catto" }"# . as_bytes ( ) ;
0 commit comments