Merge branch 'main' into feature/scholarship-edit-form
# Conflicts: # src/app.rs # src/common/mod.rs # src/pages/api/scholarships.rs # src/pages/comparison_test.rs # src/pages/home_page.rs # src/pages/mod.rs # src/pages/scholarship_info.rs
This commit is contained in:
commit
1d41d1cbf5
15 files changed
+289
-214
No files matched your search
@@ -40,10 +40,15 @@ impl ComparisonData {
|
||||
display_text: display_text.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn compare(&self, student_data: &ExpandableInfo) -> Result<bool, String> {
|
||||
let value = student_data.data.get(&self.member)
|
||||
.expect(format!("Couldn't find member {:?}, current student data: {:?}", self.member, student_data).as_str());
|
||||
let value = student_data.data.get(&self.member).expect(
|
||||
format!(
|
||||
"Couldn't find member {:?}, current student data: {:?}",
|
||||
self.member, student_data
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
self.comparison.evaluate(value, &self.target_value)
|
||||
}
|
||||
}
|
||||
@@ -73,13 +78,13 @@ impl Comparison for ComparisonType {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::common::comparison::test_utils::create_student_data;
|
||||
use super::*;
|
||||
|
||||
use crate::common::comparison::test_utils::create_student_data;
|
||||
|
||||
#[test]
|
||||
fn test_student_data() {
|
||||
let student_data = create_student_data();
|
||||
|
||||
|
||||
// Should succeed every time.
|
||||
let text_comp_success = ComparisonData {
|
||||
id: "first_name_success".to_string(),
|
||||
@@ -99,11 +104,11 @@ mod tests {
|
||||
category: "Basic Checks".to_string(),
|
||||
display_text: "First Name is Jane".to_string(),
|
||||
};
|
||||
|
||||
|
||||
let mut result = text_comp_success.compare(&student_data);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), true);
|
||||
|
||||
|
||||
result = text_comp_fail.compare(&student_data);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ impl Comparison for NumberListComparison {
|
||||
|
||||
/// Represents all available comparisons for a text list. All comparisons are comparable to a
|
||||
/// single value.
|
||||
///
|
||||
///
|
||||
/// For example, using `TextListComparison::Contains` checks if a specific value is contained
|
||||
/// in the list.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -148,12 +148,12 @@ impl Comparison for TextListComparison {
|
||||
/// For right now, nested lists should be flattened into a list of a single type before they
|
||||
/// are compared. The plan is to create a more robust framework that eventually be able to
|
||||
/// query specific lists and perform comparisons on them.
|
||||
///
|
||||
///
|
||||
/// For example:
|
||||
/// ```
|
||||
/// NestedListComparison::FlattenToTextList(Box::new(TextListComparison::Contains));
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// This will flatten a nested list into a single list of `ValueType::String` enums and then
|
||||
/// will check if the list contains the indicated target value.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -288,10 +288,12 @@ impl Comparison for MapListComparison {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::test_utils::create_map_list_helper;
|
||||
use super::*;
|
||||
use super::super::test_utils::{create_map_list_helper};
|
||||
use crate::common::{ComparisonType};
|
||||
use crate::common::comparison::test_utils::{create_empty_lists, create_number_list, create_text_list};
|
||||
use crate::common::ComparisonType;
|
||||
use crate::common::comparison::test_utils::{
|
||||
create_empty_lists, create_number_list, create_text_list,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn map_list_flatten_to_text_list() {
|
||||
@@ -415,61 +417,59 @@ mod tests {
|
||||
assert_eq!(incorrect_value.unwrap(), false);
|
||||
assert_eq!(mixed_incorrect_type.unwrap(), false);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn text_list_contains() {
|
||||
let (none_list, empty_list) = create_empty_lists();
|
||||
let num_list = create_number_list();
|
||||
let text_list = create_text_list();
|
||||
|
||||
|
||||
// Define comparisons here
|
||||
let comparison = ComparisonType::TextList(TextListComparison::Contains);
|
||||
let target_value = ValueType::String(Some("one".to_string()));
|
||||
|
||||
|
||||
let none_result = comparison.evaluate(&none_list, &target_value);
|
||||
let empty_result = comparison.evaluate(&empty_list, &target_value);
|
||||
let num_result = comparison.evaluate(&num_list, &target_value);
|
||||
let text_list = comparison.evaluate(&text_list, &target_value);
|
||||
|
||||
|
||||
assert_eq!(none_result.unwrap(), false);
|
||||
assert_eq!(empty_result.unwrap(), false);
|
||||
assert_eq!(num_result.unwrap(), false);
|
||||
assert_eq!(text_list.unwrap(), true);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn text_list_empty() {
|
||||
let none_list = ValueType::List(None);
|
||||
let empty_list = ValueType::List(Some(vec![]));
|
||||
let long_list = ValueType::List(Some(vec![
|
||||
ValueType::String(None),
|
||||
]));
|
||||
|
||||
let long_list = ValueType::List(Some(vec![ValueType::String(None)]));
|
||||
|
||||
let empty_comp = ComparisonType::TextList(TextListComparison::IsEmpty);
|
||||
let not_empty_comp = ComparisonType::TextList(TextListComparison::IsNotEmpty);
|
||||
|
||||
|
||||
// This comparison does not use a target value, as it should just check if the list
|
||||
// either doesn't exist or is empty.
|
||||
let mut result = empty_comp.evaluate(&empty_list, &ValueType::List(None));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), true);
|
||||
|
||||
|
||||
result = empty_comp.evaluate(&none_list, &ValueType::List(None));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), true);
|
||||
|
||||
|
||||
result = empty_comp.evaluate(&long_list, &ValueType::List(None));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), false);
|
||||
|
||||
|
||||
result = not_empty_comp.evaluate(&empty_list, &ValueType::List(None));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), false);
|
||||
|
||||
|
||||
result = not_empty_comp.evaluate(&none_list, &ValueType::List(None));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), false);
|
||||
|
||||
|
||||
result = not_empty_comp.evaluate(&long_list, &ValueType::List(None));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), true);
|
||||
|
||||
@@ -9,8 +9,8 @@ pub use self::{base::*, lists::*, number::*, text::*, traits::*};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_utils {
|
||||
use std::collections::HashMap;
|
||||
use crate::common::{ExpandableInfo, ValueType};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn create_student_data() -> ExpandableInfo {
|
||||
let map = create_map_helper(
|
||||
@@ -40,19 +40,16 @@ mod test_utils {
|
||||
ValueType::String(Some(10.to_string())),
|
||||
])),
|
||||
ValueType::String(Some("N/A".to_string())),
|
||||
]
|
||||
],
|
||||
))),
|
||||
ValueType::Map(Some(create_map_helper(
|
||||
vec![
|
||||
"activity_name".to_string(),
|
||||
"total_hours".to_string(),
|
||||
],
|
||||
vec!["activity_name".to_string(), "total_hours".to_string()],
|
||||
vec![
|
||||
ValueType::String(Some("Raking".to_string())),
|
||||
ValueType::Number(Some(30.to_string())),
|
||||
]
|
||||
],
|
||||
))),
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
let mut info = ExpandableInfo::new("test");
|
||||
@@ -61,9 +58,11 @@ mod test_utils {
|
||||
info
|
||||
}
|
||||
|
||||
pub fn create_map_helper(keys: Vec<String>, values: Vec<ValueType>) -> HashMap<String, ValueType> {
|
||||
keys
|
||||
.iter()
|
||||
pub fn create_map_helper(
|
||||
keys: Vec<String>,
|
||||
values: Vec<ValueType>,
|
||||
) -> HashMap<String, ValueType> {
|
||||
keys.iter()
|
||||
.cloned()
|
||||
.zip(values.iter().cloned())
|
||||
.collect::<HashMap<String, ValueType>>()
|
||||
@@ -76,7 +75,7 @@ mod test_utils {
|
||||
"last_name".to_string(),
|
||||
"gender".to_string(),
|
||||
"sat_score".to_string(),
|
||||
"grades_participated".to_string()
|
||||
"grades_participated".to_string(),
|
||||
],
|
||||
vec![
|
||||
ValueType::String(Some("John".to_string())),
|
||||
@@ -85,8 +84,8 @@ mod test_utils {
|
||||
ValueType::Number(Some(1200.to_string())),
|
||||
ValueType::List(Some(vec![
|
||||
ValueType::String(Some("9".to_string())),
|
||||
ValueType::String(Some("10".to_string()))
|
||||
]))
|
||||
ValueType::String(Some("10".to_string())),
|
||||
])),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -96,7 +95,7 @@ mod test_utils {
|
||||
"last_name".to_string(),
|
||||
"gender".to_string(),
|
||||
"sat_score".to_string(),
|
||||
"grades_participated".to_string()
|
||||
"grades_participated".to_string(),
|
||||
],
|
||||
vec![
|
||||
ValueType::String(Some("Jane".to_string())),
|
||||
@@ -105,8 +104,8 @@ mod test_utils {
|
||||
ValueType::Number(Some(1000.to_string())),
|
||||
ValueType::List(Some(vec![
|
||||
ValueType::String(Some("11".to_string())),
|
||||
ValueType::String(Some("12".to_string()))
|
||||
]))
|
||||
ValueType::String(Some("12".to_string())),
|
||||
])),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -115,14 +114,14 @@ mod test_utils {
|
||||
ValueType::Map(Some(map_two)),
|
||||
]))
|
||||
}
|
||||
|
||||
|
||||
pub fn create_empty_lists() -> (ValueType, ValueType) {
|
||||
let none_list = ValueType::List(None);
|
||||
let empty_list = ValueType::List(Some(vec![]));
|
||||
|
||||
|
||||
(none_list, empty_list)
|
||||
}
|
||||
|
||||
|
||||
pub fn create_number_list() -> ValueType {
|
||||
ValueType::List(Some(vec![
|
||||
ValueType::Number(Some(1.to_string())),
|
||||
@@ -132,7 +131,7 @@ mod test_utils {
|
||||
ValueType::Number(Some(5.to_string())),
|
||||
]))
|
||||
}
|
||||
|
||||
|
||||
pub fn create_text_list() -> ValueType {
|
||||
ValueType::List(Some(vec![
|
||||
ValueType::String(Some("one".to_string())),
|
||||
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
mod comparison;
|
||||
mod expandable_info;
|
||||
mod form_params;
|
||||
mod form_schema;
|
||||
mod user;
|
||||
mod value_type;
|
||||
mod form_params;
|
||||
mod submit_status;
|
||||
|
||||
pub use self::{comparison::*, expandable_info::*, form_schema::*, user::*, value_type::*, form_params::*, submit_status::*};
|
||||
Reference in new issue
Block a user