Skip to content

Commit 039d187

Browse files
committed
add a test case
1 parent f86fba9 commit 039d187

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/indexes.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,40 @@ mod tests {
20432043
assert_eq!(res.offset, 2);
20442044
}
20452045

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+
20462080
#[meilisearch_test]
20472081
async fn test_add_documents_ndjson(client: Client, index: Index) -> Result<(), Error> {
20482082
let ndjson = r#"{ "id": 1, "body": "doggo" }{ "id": 2, "body": "catto" }"#.as_bytes();

0 commit comments

Comments
 (0)