From d2d2bacaf2a972190f798c7a362db760e224d74e Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 3 May 2023 20:07:08 +0200 Subject: [PATCH] add a test on the complex filter --- .../tests/documents/delete_documents.rs | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/meilisearch/tests/documents/delete_documents.rs b/meilisearch/tests/documents/delete_documents.rs index 8de36490d..8f6ae1985 100644 --- a/meilisearch/tests/documents/delete_documents.rs +++ b/meilisearch/tests/documents/delete_documents.rs @@ -257,3 +257,133 @@ async fn delete_document_by_filter() { } "###); } + +#[actix_rt::test] +async fn delete_document_by_complex_filter() { + let server = Server::new().await; + let index = server.index("doggo"); + index.update_settings_filterable_attributes(json!(["color"])).await; + index + .add_documents( + json!([ + { "id": 0, "color": "red" }, + { "id": 1, "color": "blue" }, + { "id": 2, "color": "blue" }, + { "id": 3, "color": "green" }, + { "id": 4 }, + ]), + Some("id"), + ) + .await; + index.wait_task(1).await; + let (response, code) = index + .delete_document_by_filter( + json!({ "filter": ["color != red", "color != green", "color EXISTS"] }), + ) + .await; + snapshot!(code, @"202 Accepted"); + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]" }), @r###" + { + "taskUid": 2, + "indexUid": "doggo", + "status": "enqueued", + "type": "documentDeletion", + "enqueuedAt": "[date]" + } + "###); + + let response = index.wait_task(2).await; + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" + { + "uid": 2, + "indexUid": "doggo", + "status": "succeeded", + "type": "documentDeletion", + "canceledBy": null, + "details": { + "providedIds": 0, + "deletedDocuments": 2, + "originalFilter": "[\"color != red\",\"color != green\",\"color EXISTS\"]" + }, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); + + let (documents, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(documents), @r###" + { + "results": [ + { + "id": 0, + "color": "red" + }, + { + "id": 3, + "color": "green" + }, + { + "id": 4 + } + ], + "offset": 0, + "limit": 20, + "total": 3 + } + "###); + + let (response, code) = index + .delete_document_by_filter(json!({ "filter": [["color = green", "color NOT EXISTS"]] })) + .await; + snapshot!(code, @"202 Accepted"); + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" + { + "taskUid": 3, + "indexUid": "doggo", + "status": "enqueued", + "type": "documentDeletion", + "enqueuedAt": "[date]" + } + "###); + + let response = index.wait_task(3).await; + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" + { + "uid": 3, + "indexUid": "doggo", + "status": "succeeded", + "type": "documentDeletion", + "canceledBy": null, + "details": { + "providedIds": 0, + "deletedDocuments": 4, + "originalFilter": "[[\"color = green\",\"color NOT EXISTS\"]]" + }, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); + + let (documents, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(documents), @r###" + { + "results": [ + { + "id": 0, + "color": "red" + } + ], + "offset": 0, + "limit": 20, + "total": 1 + } + "###); +}