MeiliSearch/meilisearch-http/tests/documents_delete.rs

68 lines
2.4 KiB
Rust
Raw Normal View History

2020-03-04 15:06:16 +01:00
mod common;
2020-11-19 14:13:27 +01:00
use serde_json::json;
2020-04-16 11:09:47 +02:00
#[actix_rt::test]
async fn delete() {
let mut server = common::Server::test_server().await;
2020-03-04 15:06:16 +01:00
let (_response, status_code) = server.get_document(50).await;
2020-03-04 15:06:16 +01:00
assert_eq!(status_code, 200);
server.delete_document(50).await;
2020-03-04 15:06:16 +01:00
let (_response, status_code) = server.get_document(50).await;
2020-03-04 15:06:16 +01:00
assert_eq!(status_code, 404);
}
2020-05-22 18:04:23 +02:00
// Resolve the issue https://github.com/meilisearch/MeiliSearch/issues/493
2020-04-16 11:09:47 +02:00
#[actix_rt::test]
async fn delete_batch() {
let mut server = common::Server::test_server().await;
2020-03-04 15:06:16 +01:00
let doc_ids = vec!(50, 55, 60);
for doc_id in &doc_ids {
let (_response, status_code) = server.get_document(doc_id).await;
assert_eq!(status_code, 200);
}
2020-03-04 15:06:16 +01:00
let body = serde_json::json!(&doc_ids);
2020-04-16 11:09:47 +02:00
server.delete_multiple_documents(body).await;
2020-03-04 15:06:16 +01:00
for doc_id in &doc_ids {
let (_response, status_code) = server.get_document(doc_id).await;
assert_eq!(status_code, 404);
}
2020-03-04 15:06:16 +01:00
}
2020-11-19 14:13:27 +01:00
#[actix_rt::test]
async fn text_clear_all_placeholder_search() {
let mut server = common::Server::with_uid("test");
let body = json!({
"uid": "test",
});
server.create_index(body).await;
let settings = json!({
"attributesForFaceting": ["genre"],
});
server.update_all_settings(settings).await;
let documents = json!([
{ "id": 2, "title": "Pride and Prejudice", "author": "Jane Austin", "genre": "romance" },
{ "id": 456, "title": "Le Petit Prince", "author": "Antoine de Saint-Exupéry", "genre": "adventure" },
{ "id": 1, "title": "Alice In Wonderland", "author": "Lewis Carroll", "genre": "fantasy" },
{ "id": 1344, "title": "The Hobbit", "author": "J. R. R. Tolkien", "genre": "fantasy" },
{ "id": 4, "title": "Harry Potter and the Half-Blood Prince", "author": "J. K. Rowling", "genre": "fantasy" },
{ "id": 42, "title": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams" }
]);
server.add_or_update_multiple_documents(documents).await;
server.clear_all_documents().await;
let (response, _) = server.search_post(json!({ "q": "", "facetsDistribution": ["genre"] })).await;
assert_eq!(response["nbHits"], 0);
let (response, _) = server.search_post(json!({ "q": "" })).await;
assert_eq!(response["nbHits"], 0);
}