Added unit tests for pure logic. Refs #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 17:01:51 +02:00
co-authored by Claude Opus 5.5
parent 5dbe7c36b1
commit 2babe19299
7 changed files with 689 additions and 5 deletions
+47 -1
View File
@@ -101,4 +101,50 @@ impl From<std::io::Error> for AppError {
log_error(&value);
AppError::FileIOError(value.to_string())
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use chrono::NaiveTime;
#[test]
fn error_messages() {
assert_eq!(AppError::HourParseError.to_string(), "Hour parse error");
assert_eq!(AppError::SlotParseError.to_string(), "Book slot parse error");
assert_eq!(AppError::ServerError("boom".to_string()).to_string(), "Server error: boom");
assert_eq!(AppError::FatalError("boom".to_string()).to_string(), "Fatal error: boom");
assert_eq!(AppError::MailAddrParseErr("boom".to_string()).to_string(), "Cannot parse email address: boom");
assert_eq!(AppError::MailSendError("boom".to_string()).to_string(), "Cannot send email: boom");
assert_eq!(AppError::FileIOError("boom".to_string()).to_string(), "IO error: boom");
}
#[test]
fn time_parse_error_becomes_hour_parse_error() {
let err = NaiveTime::parse_from_str("nonsense", "%H:%M").unwrap_err();
assert_eq!(AppError::from(err), AppError::HourParseError);
}
#[test]
fn server_fn_error_keeps_message() {
let err = AppError::from(ServerFnError::new("boom"));
assert!(matches!(err, AppError::ServerError(ref m) if m.contains("boom")));
}
#[cfg(feature = "ssr")]
#[test]
fn io_error_becomes_file_io_error() {
let err = std::io::Error::new(std::io::ErrorKind::NotFound, "missing");
assert!(matches!(AppError::from(err), AppError::FileIOError(ref m) if m.contains("missing")));
}
#[test]
fn app_error_converts_to_server_fn_error() {
let err: ServerFnError = AppError::HourParseError.into();
assert!(err.to_string().contains("Hour parse error"));
}
}