mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
a30e02c18c
implements: https://github.com/meilisearch/specifications/blob/develop/text/0060-refashion-updates-apis.md linked PR: - #1889 - #1891 - #1892 - #1902 - #1906 - #1911 - #1914 - #1915 - #1916 - #1918 - #1924 - #1925 - #1926 - #1930 - #1936 - #1937 - #1942 - #1944 - #1945 - #1946 - #1947 - #1950 - #1951 - #1957 - #1959 - #1960 - #1961 - #1962 - #1964 - https://github.com/meilisearch/milli/pull/414 - https://github.com/meilisearch/milli/pull/409 - https://github.com/meilisearch/milli/pull/406 - https://github.com/meilisearch/milli/pull/418 - close #1687 - close #1786 - close #1940 - close #1948 - close #1949 - close #1932 - close #1956
148 lines
4.6 KiB
Rust
148 lines
4.6 KiB
Rust
use serde_json::json;
|
|
|
|
use crate::common::{GetAllDocumentsOptions, Server};
|
|
|
|
#[actix_rt::test]
|
|
async fn delete_one_document_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_response, code) = index.delete_document(0).await;
|
|
assert_eq!(code, 202);
|
|
|
|
let response = index.wait_task(0).await;
|
|
|
|
assert_eq!(response["status"], "failed");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn delete_one_unexisting_document() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index.create(None).await;
|
|
let (response, code) = index.delete_document(0).await;
|
|
assert_eq!(code, 202, "{}", response);
|
|
let update = index.wait_task(0).await;
|
|
assert_eq!(update["status"], "succeeded");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn delete_one_document() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index
|
|
.add_documents(json!([{ "id": 0, "content": "foobar" }]), None)
|
|
.await;
|
|
index.wait_task(0).await;
|
|
let (_response, code) = server.index("test").delete_document(0).await;
|
|
assert_eq!(code, 202);
|
|
index.wait_task(1).await;
|
|
|
|
let (_response, code) = index.get_document(0, None).await;
|
|
assert_eq!(code, 404);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn clear_all_documents_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_response, code) = index.clear_all_documents().await;
|
|
assert_eq!(code, 202);
|
|
|
|
let response = index.wait_task(0).await;
|
|
|
|
assert_eq!(response["status"], "failed");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn clear_all_documents() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index
|
|
.add_documents(
|
|
json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }]),
|
|
None,
|
|
)
|
|
.await;
|
|
index.wait_task(0).await;
|
|
let (_response, code) = index.clear_all_documents().await;
|
|
assert_eq!(code, 202);
|
|
|
|
let _update = index.wait_task(1).await;
|
|
let (response, code) = index
|
|
.get_all_documents(GetAllDocumentsOptions::default())
|
|
.await;
|
|
assert_eq!(code, 200);
|
|
assert!(response.as_array().unwrap().is_empty());
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn clear_all_documents_empty_index() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index.create(None).await;
|
|
|
|
let (_response, code) = index.clear_all_documents().await;
|
|
assert_eq!(code, 202);
|
|
|
|
let _update = index.wait_task(0).await;
|
|
let (response, code) = index
|
|
.get_all_documents(GetAllDocumentsOptions::default())
|
|
.await;
|
|
assert_eq!(code, 200);
|
|
assert!(response.as_array().unwrap().is_empty());
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn error_delete_batch_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_, code) = index.delete_batch(vec![]).await;
|
|
let expected_response = json!({
|
|
"message": "Index `test` not found.",
|
|
"code": "index_not_found",
|
|
"type": "invalid_request",
|
|
"link": "https://docs.meilisearch.com/errors#index_not_found"
|
|
});
|
|
assert_eq!(code, 202);
|
|
|
|
let response = index.wait_task(0).await;
|
|
|
|
assert_eq!(response["status"], "failed");
|
|
assert_eq!(response["error"], expected_response);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn delete_batch() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await;
|
|
index.wait_task(0).await;
|
|
let (_response, code) = index.delete_batch(vec![1, 0]).await;
|
|
assert_eq!(code, 202);
|
|
|
|
let _update = index.wait_task(1).await;
|
|
let (response, code) = index
|
|
.get_all_documents(GetAllDocumentsOptions::default())
|
|
.await;
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response.as_array().unwrap().len(), 1);
|
|
assert_eq!(response.as_array().unwrap()[0]["id"], 3);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn delete_no_document_batch() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await;
|
|
index.wait_task(0).await;
|
|
let (_response, code) = index.delete_batch(vec![]).await;
|
|
assert_eq!(code, 202, "{}", _response);
|
|
|
|
let _update = index.wait_task(1).await;
|
|
let (response, code) = index
|
|
.get_all_documents(GetAllDocumentsOptions::default())
|
|
.await;
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response.as_array().unwrap().len(), 3);
|
|
}
|