From d7844a6e4542c7b02c221661ce49d2a2be70a8ed Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 17 Jun 2024 15:37:32 +0200 Subject: [PATCH] add a bunch of tests on the errors of the distinct at search time --- meilisearch/tests/search/errors.rs | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 53d516c44..3f631773e 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -1072,3 +1072,66 @@ async fn search_on_unknown_field_plus_joker() { ) .await; } + +#[actix_rt::test] +async fn distinct_at_search_time() { + let server = Server::new().await; + let index = server.index("tamo"); + let (task, _) = index.create(None).await; + let task = index.wait_task(task.uid()).await; + snapshot!(task, name: "task-succeed"); + + let (response, code) = + index.search_post(json!({"page": 0, "hitsPerPage": 2, "distinct": "doggo.truc"})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(response, @r###" + { + "message": "Attribute `doggo.truc` is not filterable and thus, cannot be used as distinct attribute. This index does not have configured filterable attributes.", + "code": "invalid_search_distinct", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_distinct" + } + "###); + + let (task, _) = index.update_settings_filterable_attributes(json!(["color", "machin"])).await; + index.wait_task(task.uid()).await; + + let (response, code) = + index.search_post(json!({"page": 0, "hitsPerPage": 2, "distinct": "doggo.truc"})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(response, @r###" + { + "message": "Attribute `doggo.truc` is not filterable and thus, cannot be used as distinct attribute. Available filterable attributes are: `color, machin`.", + "code": "invalid_search_distinct", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_distinct" + } + "###); + + let (task, _) = index.update_settings_displayed_attributes(json!(["color"])).await; + index.wait_task(task.uid()).await; + + let (response, code) = + index.search_post(json!({"page": 0, "hitsPerPage": 2, "distinct": "doggo.truc"})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(response, @r###" + { + "message": "Attribute `doggo.truc` is not filterable and thus, cannot be used as distinct attribute. Available filterable attributes are: `color, <..hidden-attributes>`.", + "code": "invalid_search_distinct", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_distinct" + } + "###); + + let (response, code) = + index.search_post(json!({"page": 0, "hitsPerPage": 2, "distinct": true})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(response, @r###" + { + "message": "Invalid value type at `.distinct`: expected a string, but found a boolean: `true`", + "code": "invalid_search_distinct", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_distinct" + } + "###); +}