From 400cf3eb92be992e8056d3acddb8ffa086396051 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 5 Jun 2024 11:49:03 +0200 Subject: [PATCH] add api error test on the new retrieveVectors parameter --- meilisearch/tests/search/errors.rs | 68 +++++++++++++++++++++++++++++ meilisearch/tests/similar/errors.rs | 51 ++++++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 53d516c44..75977b190 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -167,6 +167,74 @@ async fn search_bad_hits_per_page() { "###); } +#[actix_rt::test] +async fn search_bad_attributes_to_retrieve() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.search_post(json!({"attributesToRetrieve": "doggo"})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value type at `.attributesToRetrieve`: expected an array, but found a string: `\"doggo\"`", + "code": "invalid_search_attributes_to_retrieve", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_attributes_to_retrieve" + } + "###); + // Can't make the `attributes_to_retrieve` fail with a get search since it'll accept anything as an array of strings. +} + +#[actix_rt::test] +async fn search_bad_retrieve_vectors() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.search_post(json!({"retrieveVectors": "doggo"})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value type at `.retrieveVectors`: expected a boolean, but found a string: `\"doggo\"`", + "code": "invalid_search_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_retrieve_vectors" + } + "###); + + let (response, code) = index.search_post(json!({"retrieveVectors": [true]})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value type at `.retrieveVectors`: expected a boolean, but found an array: `[true]`", + "code": "invalid_search_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_retrieve_vectors" + } + "###); + + let (response, code) = index.search_get("retrieveVectors=").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value in parameter `retrieveVectors`: could not parse `` as a boolean, expected either `true` or `false`", + "code": "invalid_search_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_retrieve_vectors" + } + "###); + + let (response, code) = index.search_get("retrieveVectors=doggo").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value in parameter `retrieveVectors`: could not parse `doggo` as a boolean, expected either `true` or `false`", + "code": "invalid_search_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_retrieve_vectors" + } + "###); +} + #[actix_rt::test] async fn search_bad_attributes_to_crop() { let server = Server::new().await; diff --git a/meilisearch/tests/similar/errors.rs b/meilisearch/tests/similar/errors.rs index 7765b9a85..546554882 100644 --- a/meilisearch/tests/similar/errors.rs +++ b/meilisearch/tests/similar/errors.rs @@ -756,3 +756,54 @@ async fn filter_reserved_geo_point_string() { }) .await; } + +#[actix_rt::test] +async fn similar_bad_retrieve_vectors() { + let server = Server::new().await; + server.set_features(json!({"vectorStore": true})).await; + let index = server.index("test"); + + let (response, code) = index.similar_post(json!({"retrieveVectors": "doggo"})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value type at `.retrieveVectors`: expected a boolean, but found a string: `\"doggo\"`", + "code": "invalid_similar_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_similar_retrieve_vectors" + } + "###); + + let (response, code) = index.similar_post(json!({"retrieveVectors": [true]})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value type at `.retrieveVectors`: expected a boolean, but found an array: `[true]`", + "code": "invalid_similar_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_similar_retrieve_vectors" + } + "###); + + let (response, code) = index.similar_get("retrieveVectors=").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value in parameter `retrieveVectors`: could not parse `` as a boolean, expected either `true` or `false`", + "code": "invalid_similar_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_similar_retrieve_vectors" + } + "###); + + let (response, code) = index.similar_get("retrieveVectors=doggo").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid value in parameter `retrieveVectors`: could not parse `doggo` as a boolean, expected either `true` or `false`", + "code": "invalid_similar_retrieve_vectors", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_similar_retrieve_vectors" + } + "###); +}