mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-12-19 01:45:54 +08:00
tests: split test in separate file
Signed-off-by: Kushal Kumar <kushalkumargupta4@gmail.com>
This commit is contained in:
parent
b21d7aedf9
commit
c0aa018c87
@ -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;
|
||||||
|
@ -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(),]);
|
|
||||||
}
|
|
||||||
}
|
|
26
crates/meilisearch/src/routes/indexes/search_test.rs
Normal file
26
crates/meilisearch/src/routes/indexes/search_test.rs
Normal 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(),]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user