diff --git a/src/option.rs b/src/option.rs index c88110ccd..0a1d494de 100644 --- a/src/option.rs +++ b/src/option.rs @@ -103,8 +103,8 @@ pub struct Opt { pub sentry_dsn: String, /// Disable Sentry error reporting. - #[cfg(all(not(debug_assertions), feature = "sentry"))] #[structopt(long, env = "MEILI_NO_SENTRY")] + #[cfg(all(not(debug_assertions), feature = "sentry"))] pub no_sentry: bool, /// This environment variable must be set to `production` if you are running in production. diff --git a/tests/common/index.rs b/tests/common/index.rs index 8afe78a35..a50f8e6a3 100644 --- a/tests/common/index.rs +++ b/tests/common/index.rs @@ -126,6 +126,11 @@ impl Index<'_> { let url = format!("/indexes/{}/documents", self.uid); self.service.delete(url).await } + + pub async fn delete_batch(&self, ids: Vec) -> (Value, StatusCode) { + let url = format!("/indexes/{}/documents/delete-batch", self.uid); + self.service.post(url, serde_json::to_value(&ids).unwrap()).await + } } pub struct GetDocumentOptions; diff --git a/tests/common/server.rs b/tests/common/server.rs index 630bb2791..de32a2045 100644 --- a/tests/common/server.rs +++ b/tests/common/server.rs @@ -43,6 +43,10 @@ impl Server { snapshot_interval_sec: None, import_dump: None, indexer_options: IndexerOpts::default(), + #[cfg(all(not(debug_assertions), feature = "sentry"))] + sentry_dsn: String::from(""), + #[cfg(all(not(debug_assertions), feature = "sentry"))] + no_sentry: true, }; let data = Data::new(opt).unwrap(); diff --git a/tests/documents/delete_documents.rs b/tests/documents/delete_documents.rs index 149319308..3dba7e6fd 100644 --- a/tests/documents/delete_documents.rs +++ b/tests/documents/delete_documents.rs @@ -28,6 +28,7 @@ async fn delete_one_document() { index.wait_update_id(0).await; let (_response, code) = server.index("test").delete_document(0).await; assert_eq!(code, 200); + index.wait_update_id(1).await; let (_response, code) = index.get_document(0, None).await; assert_eq!(code, 400); @@ -50,7 +51,7 @@ async fn clear_all_documents() { let (_response, code) = index.clear_all_documents().await; assert_eq!(code, 200); - let _update = index.wait_update_id(0).await; + let _update = index.wait_update_id(1).await; let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; assert_eq!(code, 200); assert!(response.as_array().unwrap().is_empty()); @@ -70,3 +71,42 @@ async fn clear_all_documents_empty_index() { assert_eq!(code, 200); assert!(response.as_array().unwrap().is_empty()); } + +#[actix_rt::test] +async fn delete_batch_unexisting_index() { + let server = Server::new().await; + let (_response, code) = server.index("test").delete_batch(vec![]).await; + assert_eq!(code, 400); +} + +#[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_update_id(0).await; + let (_response, code) = index.delete_batch(vec![1, 0]).await; + assert_eq!(code, 200); + + let _update = index.wait_update_id(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_update_id(0).await; + let (_response, code) = index.delete_batch(vec![]).await; + assert_eq!(code, 200); + + let _update = index.wait_update_id(1).await; + let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + assert_eq!(code, 200); + assert_eq!(response.as_array().unwrap().len(), 3); +}