mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-01 17:15:46 +01:00
Fix PR comments
This commit is contained in:
parent
b664a46e91
commit
b59145385e
@ -112,13 +112,15 @@ impl Code {
|
|||||||
// invalid state error
|
// invalid state error
|
||||||
InvalidState => ErrCode::internal("invalid_state", StatusCode::INTERNAL_SERVER_ERROR),
|
InvalidState => ErrCode::internal("invalid_state", StatusCode::INTERNAL_SERVER_ERROR),
|
||||||
// thrown when no primary key has been set
|
// thrown when no primary key has been set
|
||||||
MissingPrimaryKey => ErrCode::invalid("missing_primary_key", StatusCode::BAD_REQUEST),
|
MissingPrimaryKey => {
|
||||||
|
ErrCode::invalid("primary_key_inference_failed", StatusCode::BAD_REQUEST)
|
||||||
|
}
|
||||||
// error thrown when trying to set an already existing primary key
|
// error thrown when trying to set an already existing primary key
|
||||||
PrimaryKeyAlreadyPresent => {
|
PrimaryKeyAlreadyPresent => {
|
||||||
ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST)
|
ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST)
|
||||||
}
|
}
|
||||||
// invalid ranking rule
|
// invalid ranking rule
|
||||||
InvalidRankingRule => ErrCode::invalid("invalid_request", StatusCode::BAD_REQUEST),
|
InvalidRankingRule => ErrCode::invalid("invalid_ranking_rule", StatusCode::BAD_REQUEST),
|
||||||
|
|
||||||
// invalid database
|
// invalid database
|
||||||
InvalidStore => {
|
InvalidStore => {
|
||||||
|
@ -997,3 +997,32 @@ async fn error_add_documents_payload_size() {
|
|||||||
assert_eq!(response, expected_response);
|
assert_eq!(response, expected_response);
|
||||||
assert_eq!(code, 413);
|
assert_eq!(code, 413);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn error_primary_key_inference() {
|
||||||
|
let server = Server::new().await;
|
||||||
|
let index = server.index("test");
|
||||||
|
|
||||||
|
let documents = json!([
|
||||||
|
{
|
||||||
|
"title": "11",
|
||||||
|
"desc": "foobar"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
index.add_documents(documents, None).await;
|
||||||
|
index.wait_update_id(0).await;
|
||||||
|
let (response, code) = index.get_update(0).await;
|
||||||
|
assert_eq!(code, 200);
|
||||||
|
assert_eq!(response["status"], "failed");
|
||||||
|
assert_eq!(
|
||||||
|
response["message"],
|
||||||
|
r#"The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index."#
|
||||||
|
);
|
||||||
|
assert_eq!(response["code"], "primary_key_inference_failed");
|
||||||
|
assert_eq!(response["type"], "invalid_request");
|
||||||
|
assert_eq!(
|
||||||
|
response["link"],
|
||||||
|
"https://docs.meilisearch.com/errors#primary_key_inference_failed"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -63,7 +63,7 @@ async fn get_settings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn update_settings_unknown_field() {
|
async fn error_update_settings_unknown_field() {
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let index = server.index("test");
|
let index = server.index("test");
|
||||||
let (_response, code) = index.update_settings(json!({"foo": 12})).await;
|
let (_response, code) = index.update_settings(json!({"foo": 12})).await;
|
||||||
@ -95,10 +95,19 @@ async fn test_partial_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn delete_settings_unexisting_index() {
|
async fn error_delete_settings_unexisting_index() {
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let index = server.index("test");
|
let index = server.index("test");
|
||||||
let (_response, code) = index.delete_settings().await;
|
let (response, code) = index.delete_settings().await;
|
||||||
|
|
||||||
|
let expected_response = json!({
|
||||||
|
"message": "Index `test` not found.",
|
||||||
|
"code": "index_not_found",
|
||||||
|
"type": "invalid_request",
|
||||||
|
"link": "https://docs.meilisearch.com/errors#index_not_found"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(response, expected_response);
|
||||||
assert_eq!(code, 404);
|
assert_eq!(code, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,11 +173,20 @@ async fn update_setting_unexisting_index() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn update_setting_unexisting_index_invalid_uid() {
|
async fn error_update_setting_unexisting_index_invalid_uid() {
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let index = server.index("test##! ");
|
let index = server.index("test##! ");
|
||||||
let (response, code) = index.update_settings(json!({})).await;
|
let (response, code) = index.update_settings(json!({})).await;
|
||||||
assert_eq!(code, 400, "{}", response);
|
|
||||||
|
let expected_response = json!({
|
||||||
|
"message": "`test##! ` is not a valid index uid. Index uid can be an integer or a string containing only alphanumeric characters, hyphens (-) and underscores (_).",
|
||||||
|
"code": "invalid_index_uid",
|
||||||
|
"type": "invalid_request",
|
||||||
|
"link": "https://docs.meilisearch.com/errors#invalid_index_uid"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(response, expected_response);
|
||||||
|
assert_eq!(code, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! test_setting_routes {
|
macro_rules! test_setting_routes {
|
||||||
@ -246,3 +264,50 @@ test_setting_routes!(
|
|||||||
ranking_rules,
|
ranking_rules,
|
||||||
synonyms
|
synonyms
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn error_set_invalid_ranking_rules() {
|
||||||
|
let server = Server::new().await;
|
||||||
|
let index = server.index("test");
|
||||||
|
index.create(None).await;
|
||||||
|
|
||||||
|
let (_response, _code) = index
|
||||||
|
.update_settings(json!({ "rankingRules": [ "manyTheFish"]}))
|
||||||
|
.await;
|
||||||
|
index.wait_update_id(0).await;
|
||||||
|
let (response, code) = index.get_update(0).await;
|
||||||
|
|
||||||
|
assert_eq!(code, 200);
|
||||||
|
assert_eq!(response["status"], "failed");
|
||||||
|
assert_eq!(
|
||||||
|
response["message"],
|
||||||
|
r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are Words, Typo, Sort, Proximity, Attribute, Exactness and custom ranking rules."#
|
||||||
|
);
|
||||||
|
assert_eq!(response["code"], "invalid_ranking_rule");
|
||||||
|
assert_eq!(response["type"], "invalid_request");
|
||||||
|
assert_eq!(
|
||||||
|
response["link"],
|
||||||
|
"https://docs.meilisearch.com/errors#invalid_ranking_rule"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn set_and_reset_distinct_attribute_with_dedicated_route() {
|
||||||
|
let server = Server::new().await;
|
||||||
|
let index = server.index("test");
|
||||||
|
|
||||||
|
let (_response, _code) = index.update_distinct_attribute(json!("test")).await;
|
||||||
|
index.wait_update_id(0).await;
|
||||||
|
|
||||||
|
let (response, _) = index.get_distinct_attribute().await;
|
||||||
|
|
||||||
|
assert_eq!(response, "test");
|
||||||
|
|
||||||
|
index.update_distinct_attribute(json!(null)).await;
|
||||||
|
|
||||||
|
index.wait_update_id(1).await;
|
||||||
|
|
||||||
|
let (response, _) = index.get_distinct_attribute().await;
|
||||||
|
|
||||||
|
assert_eq!(response, json!(null));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user