From 497187083b918b6cee3832fe7ddca5467e4bd69a Mon Sep 17 00:00:00 2001 From: Philipp Ahlner Date: Wed, 18 Jan 2023 13:24:26 +0100 Subject: [PATCH] Add test for bug #3007: Wrong error message Adds a test for #3007: Wrong error message when lat and lng are unparseable --- milli/src/index.rs | 36 +++++++++++++++++++ .../bug_3007/geo_faceted_documents_ids.snap | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 milli/src/snapshots/index.rs/bug_3007/geo_faceted_documents_ids.snap diff --git a/milli/src/index.rs b/milli/src/index.rs index 46f8eb6a3..7ed9af424 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -2292,4 +2292,40 @@ pub(crate) mod tests { assert!(all_ids.insert(id)); } } + + #[test] + fn bug_3007() { + // https://github.com/meilisearch/meilisearch/issues/3007 + + use crate::error::{GeoError, UserError}; + let index = TempIndex::new(); + + // Given is an index with a geo field NOT contained in the sortable_fields of the settings + index + .update_settings(|settings| { + settings.set_primary_key("id".to_string()); + settings.set_filterable_fields(HashSet::from(["_geo".to_string()])); + }) + .unwrap(); + + // happy path + index.add_documents(documents!({ "id" : 5, "_geo": {"lat": 12.0, "lng": 11.0}})).unwrap(); + + db_snap!(index, geo_faceted_documents_ids); + + // both are unparseable, we expect GeoError::BadLatitudeAndLongitude + let err1 = index + .add_documents( + documents!({ "id" : 6, "_geo": {"lat": "unparseable", "lng": "unparseable"}}), + ) + .unwrap_err(); + assert!(matches!( + err1, + Error::UserError(UserError::InvalidGeoField( + GeoError::BadLatitudeAndLongitude { .. } + )) + )); + + db_snap!(index, geo_faceted_documents_ids); // ensure that no more document was inserted + } } diff --git a/milli/src/snapshots/index.rs/bug_3007/geo_faceted_documents_ids.snap b/milli/src/snapshots/index.rs/bug_3007/geo_faceted_documents_ids.snap new file mode 100644 index 000000000..f9ebc0c20 --- /dev/null +++ b/milli/src/snapshots/index.rs/bug_3007/geo_faceted_documents_ids.snap @@ -0,0 +1,4 @@ +--- +source: milli/src/index.rs +--- +[0, ]