mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
fix the bad filter test
This commit is contained in:
parent
d4157c0ce4
commit
d0a85057a3
@ -55,7 +55,7 @@ impl ErrorCode for MeilisearchHttpError {
|
|||||||
MeilisearchHttpError::MissingPayload(_) => Code::MissingPayload,
|
MeilisearchHttpError::MissingPayload(_) => Code::MissingPayload,
|
||||||
MeilisearchHttpError::InvalidContentType(_, _) => Code::InvalidContentType,
|
MeilisearchHttpError::InvalidContentType(_, _) => Code::InvalidContentType,
|
||||||
MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound,
|
MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound,
|
||||||
MeilisearchHttpError::InvalidExpression(_, _) => Code::Filter,
|
MeilisearchHttpError::InvalidExpression(_, _) => Code::InvalidSearchFilter,
|
||||||
MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge,
|
MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge,
|
||||||
MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::InvalidSwapIndexes,
|
MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::InvalidSwapIndexes,
|
||||||
MeilisearchHttpError::IndexUid(e) => e.error_code(),
|
MeilisearchHttpError::IndexUid(e) => e.error_code(),
|
||||||
|
@ -695,7 +695,7 @@ fn parse_filter(facets: &Value) -> Result<Option<Filter>, MeilisearchHttpError>
|
|||||||
Ok(condition)
|
Ok(condition)
|
||||||
}
|
}
|
||||||
Value::Array(arr) => parse_filter_array(arr),
|
Value::Array(arr) => parse_filter_array(arr),
|
||||||
v => Err(MeilisearchHttpError::InvalidExpression(&["Array"], v.clone())),
|
v => Err(MeilisearchHttpError::InvalidExpression(&["String", "Array"], v.clone())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,20 +233,26 @@ async fn search_bad_attributes_to_highlight() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn search_bad_filter() {
|
async fn search_bad_filter() {
|
||||||
|
// Since a filter is deserialized as a json Value it will never fail to deserialize.
|
||||||
|
// Thus the error message is not generated by deserr but written by us.
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let index = server.index("test");
|
let index = server.index("test");
|
||||||
|
// Also, to trigger the error message we need to effectively create the index or else it'll throw an
|
||||||
|
// index does not exists error.
|
||||||
|
let (_, code) = index.create(None).await;
|
||||||
|
snapshot!(code, @"202 Accepted");
|
||||||
|
|
||||||
// Can't make the `filter` fail with a get search since it'll accept anything as a strings.
|
|
||||||
let (response, code) = index.search_post(json!({ "filter": true })).await;
|
let (response, code) = index.search_post(json!({ "filter": true })).await;
|
||||||
snapshot!(code, @"404 Not Found");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(json_string!(response), @r###"
|
snapshot!(json_string!(response), @r###"
|
||||||
{
|
{
|
||||||
"message": "Index `test` not found.",
|
"message": "Invalid syntax for the filter parameter: `expected String, Array, found: true`.",
|
||||||
"code": "index_not_found",
|
"code": "invalid_search_filter",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#index-not-found"
|
"link": "https://docs.meilisearch.com/errors#invalid-search-filter"
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
// Can't make the `filter` fail with a get search since it'll accept anything as a strings.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
Loading…
Reference in New Issue
Block a user