diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index 3402cac1e..ecb97f233 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -115,7 +115,8 @@ pub async fn update_all(mut ctx: Request) -> SResult { }; let mut writer = db.update_write_txn()?; - let update_id = index.settings_update(&mut writer, settings.into_update()?)?; + let settings = settings.into_update().map_err(ResponseError::bad_request)?; + let update_id = index.settings_update(&mut writer, settings)?; writer.commit()?; let response_body = IndexUpdateResponse { update_id }; @@ -177,7 +178,8 @@ pub async fn update_rules(mut ctx: Request) -> SResult { }; let mut writer = db.update_write_txn()?; - let update_id = index.settings_update(&mut writer, settings.into_update()?)?; + let settings = settings.into_update().map_err(ResponseError::bad_request)?; + let update_id = index.settings_update(&mut writer, settings)?; writer.commit()?; let response_body = IndexUpdateResponse { update_id }; @@ -229,7 +231,8 @@ pub async fn update_distinct(mut ctx: Request) -> SResult { }; let mut writer = db.update_write_txn()?; - let update_id = index.settings_update(&mut writer, settings.into_update()?)?; + let settings = settings.into_update().map_err(ResponseError::bad_request)?; + let update_id = index.settings_update(&mut writer, settings)?; writer.commit()?; let response_body = IndexUpdateResponse { update_id }; @@ -284,7 +287,8 @@ pub async fn update_searchable(mut ctx: Request) -> SResult { }; let mut writer = db.update_write_txn()?; - let update_id = index.settings_update(&mut writer, settings.into_update()?)?; + let settings = settings.into_update().map_err(ResponseError::bad_request)?; + let update_id = index.settings_update(&mut writer, settings)?; writer.commit()?; let response_body = IndexUpdateResponse { update_id }; @@ -342,7 +346,8 @@ pub async fn update_displayed(mut ctx: Request) -> SResult { }; let mut writer = db.update_write_txn()?; - let update_id = index.settings_update(&mut writer, settings.into_update()?)?; + let settings = settings.into_update().map_err(ResponseError::bad_request)?; + let update_id = index.settings_update(&mut writer, settings)?; writer.commit()?; let response_body = IndexUpdateResponse { update_id }; @@ -395,7 +400,8 @@ pub async fn update_accept_new_fields(mut ctx: Request) -> SResult (Value, StatusCode) { + let url = format!("/indexes/{}/settings/ranking-rules", self.uid); + self.post_request(&url, body) + } + pub fn delete_ranking_rules(&mut self) -> (Value, StatusCode) { let url = format!("/indexes/{}/settings/ranking-rules", self.uid); self.delete_request_async(&url) diff --git a/meilisearch-http/tests/settings_ranking_rules.rs b/meilisearch-http/tests/settings_ranking_rules.rs index 39e4c7061..908dd9c31 100644 --- a/meilisearch-http/tests/settings_ranking_rules.rs +++ b/meilisearch-http/tests/settings_ranking_rules.rs @@ -37,7 +37,7 @@ fn write_all_and_delete() { let (response, _status_code) = server.get_ranking_rules(); - let json = json!([ + let expected = json!([ "typo", "words", "proximity", @@ -46,7 +46,7 @@ fn write_all_and_delete() { "exactness" ]); - assert_json_eq!(expect, response, ordered: false); + assert_json_eq!(expected, response, ordered: false); } #[test] @@ -105,3 +105,37 @@ fn write_all_and_update() { assert_json_eq!(expected, response, ordered: false); } + +#[test] +fn send_undefined_rule() { + let mut server = common::Server::with_uid("movies"); + let body = json!({ + "uid": "movies", + "identifier": "id", + }); + server.create_index(body); + + let body = json!([ + "typos", + ]); + + let (_response, status_code) = server.update_ranking_rules_sync(body); + assert_eq!(status_code, 400); +} + +#[test] +fn send_malformed_custom_rule() { + let mut server = common::Server::with_uid("movies"); + let body = json!({ + "uid": "movies", + "identifier": "id", + }); + server.create_index(body); + + let body = json!([ + "dsc(truc)", + ]); + + let (_response, status_code) = server.update_ranking_rules_sync(body); + assert_eq!(status_code, 400); +}