Some more
This commit is contained in:
parent
b6dba5fc88
commit
9fbcee0bea
2 changed files with 96 additions and 0 deletions
|
|
@ -260,4 +260,61 @@ mod tests {
|
|||
Err(ValidationError::InvalidStatusTransition { .. })
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_todo_default_values() {
|
||||
let todo = ToDo::default();
|
||||
assert_eq!(todo.status, ToDoStatus::Pending);
|
||||
assert_eq!(todo.priority, DEFAULT_PRIORITY);
|
||||
assert!(todo.depends_on.is_empty());
|
||||
assert!(!todo.id.is_nil());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_todo_serialization_roundtrip() {
|
||||
let original = ToDo::new(
|
||||
"Test Title".to_string(),
|
||||
"Test Description".to_string(),
|
||||
Uuid::new_v4(),
|
||||
);
|
||||
|
||||
let serialized = serde_json::to_string(&original).unwrap();
|
||||
let deserialized: ToDo = serde_json::from_str(&serialized).unwrap();
|
||||
|
||||
assert_eq!(original.id, deserialized.id);
|
||||
assert_eq!(original.title, deserialized.title);
|
||||
assert_eq!(original.description, deserialized.description);
|
||||
assert_eq!(original.status, deserialized.status);
|
||||
assert_eq!(original.priority, deserialized.priority);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_todo_update_title() {
|
||||
let mut todo = ToDo::default();
|
||||
let result = todo.update(Some("New Title".to_string()), None, None);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(todo.title, "New Title");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_todo_update_empty_title() {
|
||||
let mut todo = ToDo::default();
|
||||
let result = todo.update(Some("".to_string()), None, None);
|
||||
assert!(matches!(result, Err(ValidationError::EmptyTitle)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_todo_update_priority() {
|
||||
let mut todo = ToDo::default();
|
||||
let result = todo.update(None, None, Some(50));
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(todo.priority, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_todo_update_invalid_priority() {
|
||||
let mut todo = ToDo::default();
|
||||
let result = todo.update(None, None, Some(0));
|
||||
assert!(matches!(result, Err(ValidationError::InvalidPriority)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue