Added unit tests for pure logic. Refs #2
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+47
-1
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user