diff --git a/src/service/query_api/mod.rs b/src/service/query_api/mod.rs index 501afce..70f7fb1 100644 --- a/src/service/query_api/mod.rs +++ b/src/service/query_api/mod.rs @@ -17,7 +17,7 @@ pub fn parse(query: Option<&str>) -> Option { continue; } // wellcome, now we can start the real parsing - let parts = param.splitn(2,"=").collect::>(); + let parts = param.splitn(2, "=").collect::>(); if parts.get(0).is_none() || parts.get(1).is_none() { continue; } @@ -62,7 +62,7 @@ fn set_where_it_belongs(queries: &mut Queries, q: Query) { } "_filter" => { let mut filter_vet = &mut queries.filter; - println!("parsing {}",q.value); + println!("parsing {}", q.value); filter_vet.extend(q.value.split(",").map(Query::from).collect::>()); } "_q" => { @@ -118,6 +118,10 @@ impl PartialEq for Queries { mod tests { use super::*; #[test] + fn parse_none_test() { + assert_eq!(parse(None), None); + } + #[test] fn parse_fields_test() { let mut queries = Queries::new(); { @@ -146,8 +150,9 @@ mod tests { let sort = &mut queries.sort; sort.push(Sort::ASC("a".to_string())); sort.push(Sort::DSC("b".to_string())); + sort.push(Sort::ASC("c".to_string())); } - assert_eq!(parse(Some("_sort=a+,b-")), Some(queries)); + assert_eq!(parse(Some("_sort=a+,b-,c")), Some(queries)); } #[test] @@ -161,7 +166,7 @@ mod tests { assert_eq!(parse(Some("_filter=name=seray,active=true")), Some(queries)); } - #[test] + #[test] fn parse_q_test() { let mut queries = Queries::new(); { diff --git a/src/service/query_api/page.rs b/src/service/query_api/page.rs index a462ffe..5a58deb 100644 --- a/src/service/query_api/page.rs +++ b/src/service/query_api/page.rs @@ -61,5 +61,10 @@ mod tests { Some(Page::OFFSET(123))); assert_eq!(parse(Query::new("_limit", "=", "123")), Some(Page::LIMIT(123))); + + assert_ne!(parse(Query::new("_offset", "=", "123")), + Some(Page::LIMIT(123))); + assert_ne!(parse(Query::new("_offset", "=", "123")), + Some(Page::LIMIT(123))); } } diff --git a/src/service/query_api/sort.rs b/src/service/query_api/sort.rs index cd747ce..eff5387 100644 --- a/src/service/query_api/sort.rs +++ b/src/service/query_api/sort.rs @@ -65,5 +65,8 @@ mod tests { assert_eq!(parse("name"), None); assert_eq!(parse("name+"), Some(Sort::ASC("name".to_string()))); assert_eq!(parse("name-"), Some(Sort::DSC("name".to_string()))); + + assert_ne!(parse("name+"), Some(Sort::DSC("name".to_string()))); + assert_ne!(parse("name-"), Some(Sort::ASC("name".to_string()))); } }