tests: split test in separate file

Signed-off-by: Kushal Kumar <kushalkumargupta4@gmail.com>
This commit is contained in:
Kushal Kumar 2024-12-08 00:32:32 +05:30
parent b21d7aedf9
commit c0aa018c87
3 changed files with 29 additions and 29 deletions

View File

@ -28,6 +28,7 @@ use crate::Opt;
pub mod documents; pub mod documents;
pub mod facet_search; pub mod facet_search;
pub mod search; pub mod search;
mod search_test;
mod search_analytics; mod search_analytics;
pub mod settings; pub mod settings;
mod settings_analytics; mod settings_analytics;

View File

@ -198,7 +198,7 @@ impl TryFrom<SearchQueryGet> for SearchQuery {
// TODO: TAMO: split on :asc, and :desc, instead of doing some weird things // TODO: TAMO: split on :asc, and :desc, instead of doing some weird things
/// Transform the sort query parameter into something that matches the post expected format. /// Transform the sort query parameter into something that matches the post expected format.
fn fix_sort_query_parameters(sort_query: &str) -> Vec<String> { pub fn fix_sort_query_parameters(sort_query: &str) -> Vec<String> {
let mut sort_parameters = Vec::new(); let mut sort_parameters = Vec::new();
let mut merge = false; let mut merge = false;
for current_sort in sort_query.trim_matches('"').split(',').map(|s| s.trim()) { for current_sort in sort_query.trim_matches('"').split(',').map(|s| s.trim()) {
@ -355,31 +355,4 @@ pub fn search_kind(
(_, None, Some(_)) => Err(MeilisearchHttpError::MissingSearchHybrid.into()), (_, None, Some(_)) => Err(MeilisearchHttpError::MissingSearchHybrid.into()),
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_fix_sort_query_parameters() {
let sort = fix_sort_query_parameters("_geoPoint(12, 13):asc");
assert_eq!(sort, vec!["_geoPoint(12,13):asc".to_string()]);
let sort = fix_sort_query_parameters("doggo:asc,_geoPoint(12.45,13.56):desc");
assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(12.45,13.56):desc".to_string(),]);
let sort = fix_sort_query_parameters(
"doggo:asc , _geoPoint(12.45, 13.56, 2590352):desc , catto:desc",
);
assert_eq!(
sort,
vec![
"doggo:asc".to_string(),
"_geoPoint(12.45,13.56,2590352):desc".to_string(),
"catto:desc".to_string(),
]
);
let sort = fix_sort_query_parameters("doggo:asc , _geoPoint(1, 2), catto:desc");
// This is ugly but eh, I don't want to write a full parser just for this unused route
assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(1,2),catto:desc".to_string(),]);
}
}

View File

@ -0,0 +1,26 @@
#[cfg(test)]
pub mod search_test {
use crate::routes::indexes::search::fix_sort_query_parameters;
#[test]
fn test_fix_sort_query_parameters() {
let sort = fix_sort_query_parameters("_geoPoint(12, 13):asc");
assert_eq!(sort, vec!["_geoPoint(12,13):asc".to_string()]);
let sort = fix_sort_query_parameters("doggo:asc,_geoPoint(12.45,13.56):desc");
assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(12.45,13.56):desc".to_string(),]);
let sort = fix_sort_query_parameters(
"doggo:asc , _geoPoint(12.45, 13.56, 2590352):desc , catto:desc",
);
assert_eq!(
sort,
vec![
"doggo:asc".to_string(),
"_geoPoint(12.45,13.56,2590352):desc".to_string(),
"catto:desc".to_string(),
]
);
let sort = fix_sort_query_parameters("doggo:asc , _geoPoint(1, 2), catto:desc");
// This is ugly but eh, I don't want to write a full parser just for this unused route
assert_eq!(sort, vec!["doggo:asc".to_string(), "_geoPoint(1,2),catto:desc".to_string(),]);
}
}