From 398c0c32cd56dfe0843b0376d9955e6a7ffefb96 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 10 Jan 2023 18:19:27 +0100 Subject: [PATCH] test all the error codes that can be throw in the settings --- meilisearch/tests/settings/errors.rs | 191 +++++++++++++++++++++++++++ meilisearch/tests/settings/mod.rs | 1 + 2 files changed, 192 insertions(+) create mode 100644 meilisearch/tests/settings/errors.rs diff --git a/meilisearch/tests/settings/errors.rs b/meilisearch/tests/settings/errors.rs new file mode 100644 index 000000000..b1a846637 --- /dev/null +++ b/meilisearch/tests/settings/errors.rs @@ -0,0 +1,191 @@ +use meili_snap::*; +use serde_json::json; + +use crate::common::Server; + +#[actix_rt::test] +async fn settings_bad_displayed_attributes() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "displayedAttributes": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Sequence at `.displayedAttributes`.", + "code": "invalid_settings_displayed_attributes", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-displayed-attributes" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_searchable_attributes() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "searchableAttributes": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Sequence at `.searchableAttributes`.", + "code": "invalid_settings_searchable_attributes", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-searchable-attributes" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_filterable_attributes() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "filterableAttributes": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Sequence at `.filterableAttributes`.", + "code": "invalid_settings_filterable_attributes", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-filterable-attributes" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_sortable_attributes() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "sortableAttributes": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Sequence at `.sortableAttributes`.", + "code": "invalid_settings_sortable_attributes", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-sortable-attributes" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_ranking_rules() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "rankingRules": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Sequence at `.rankingRules`.", + "code": "invalid_settings_ranking_rules", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-ranking-rules" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_stop_words() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "stopWords": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Sequence at `.stopWords`.", + "code": "invalid_settings_stop_words", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-stop-words" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_synonyms() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "synonyms": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Map at `.synonyms`.", + "code": "invalid_settings_synonyms", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-synonyms" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_distinct_attribute() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "distinctAttribute": ["doggo"] })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: Sequence `[\"doggo\"]`, expected a String at `.distinctAttribute`.", + "code": "invalid_settings_distinct_attribute", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-distinct-attribute" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_typo_tolerance() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "typoTolerance": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Map at `.typoTolerance`.", + "code": "invalid_settings_typo_tolerance", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-typo-tolerance" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_faceting() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "faceting": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Map at `.faceting`.", + "code": "invalid_settings_faceting", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-faceting" + } + "###); +} + +#[actix_rt::test] +async fn settings_bad_pagination() { + let server = Server::new().await; + let index = server.index("test"); + + let (response, code) = index.update_settings(json!({ "pagination": "doggo" })).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "invalid type: String `\"doggo\"`, expected a Map at `.pagination`.", + "code": "invalid_settings_pagination", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-settings-pagination" + } + "###); +} diff --git a/meilisearch/tests/settings/mod.rs b/meilisearch/tests/settings/mod.rs index 05339cb37..fa4df254c 100644 --- a/meilisearch/tests/settings/mod.rs +++ b/meilisearch/tests/settings/mod.rs @@ -1,2 +1,3 @@ mod distinct; +mod errors; mod get_settings;