diff --git a/meilisearch/tests/features/mod.rs b/meilisearch/tests/features/mod.rs new file mode 100644 index 000000000..045440f49 --- /dev/null +++ b/meilisearch/tests/features/mod.rs @@ -0,0 +1,109 @@ +use serde_json::json; + +use crate::common::Server; + +/// Feature name to test against. +/// This will have to be changed by a different one when that feature is stabilized. +/// All tests that need to set a feature can make use of this constant. +const FEATURE_NAME: &str = "vectorStore"; + +#[actix_rt::test] +async fn experimental_features() { + let server = Server::new().await; + + let (response, code) = server.get_features().await; + + meili_snap::snapshot!(code, @"200 OK"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "scoreDetails": false, + "vectorStore": false + } + "###); + + let (response, code) = server.set_features(json!({FEATURE_NAME: true})).await; + + meili_snap::snapshot!(code, @"200 OK"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "scoreDetails": false, + "vectorStore": true + } + "###); + + let (response, code) = server.get_features().await; + + meili_snap::snapshot!(code, @"200 OK"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "scoreDetails": false, + "vectorStore": true + } + "###); + + // sending null does not change the value + let (response, code) = server.set_features(json!({FEATURE_NAME: null})).await; + + meili_snap::snapshot!(code, @"200 OK"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "scoreDetails": false, + "vectorStore": true + } + "###); + + // not sending the field does not change the value + let (response, code) = server.set_features(json!({})).await; + + meili_snap::snapshot!(code, @"200 OK"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "scoreDetails": false, + "vectorStore": true + } + "###); +} + +#[actix_rt::test] +async fn errors() { + let server = Server::new().await; + + // Sending a feature not in the list is an error + let (response, code) = server.set_features(json!({"NotAFeature": true})).await; + + meili_snap::snapshot!(code, @"400 Bad Request"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "message": "Unknown field `NotAFeature`: expected one of `scoreDetails`, `vectorStore`", + "code": "bad_request", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#bad_request" + } + "###); + + // The type must be a bool, not a number + let (response, code) = server.set_features(json!({FEATURE_NAME: 42})).await; + + meili_snap::snapshot!(code, @"400 Bad Request"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "message": "Invalid value type at `.vectorStore`: expected a boolean, but found a positive integer: `42`", + "code": "bad_request", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#bad_request" + } + "###); + + // The type must be a bool, not a string + let (response, code) = server.set_features(json!({FEATURE_NAME: "true"})).await; + + meili_snap::snapshot!(code, @"400 Bad Request"); + meili_snap::snapshot!(meili_snap::json_string!(response), @r###" + { + "message": "Invalid value type at `.vectorStore`: expected a boolean, but found a string: `\"true\"`", + "code": "bad_request", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#bad_request" + } + "###); +} diff --git a/meilisearch/tests/integration.rs b/meilisearch/tests/integration.rs index 4383aea57..b6992791a 100644 --- a/meilisearch/tests/integration.rs +++ b/meilisearch/tests/integration.rs @@ -3,6 +3,7 @@ mod common; mod dashboard; mod documents; mod dumps; +mod features; mod index; mod search; mod settings;