From 2374330bb1af95e06d6e1ec7fa93414e4b363aa6 Mon Sep 17 00:00:00 2001 From: Lahfir Date: Fri, 27 Feb 2026 10:53:15 -0800 Subject: [PATCH] test: add notification error and filter matching tests Add error code serialization and notification_not_found tests in core. Add matches_filters unit tests in macOS list module covering app, text, combined, and no-filter cases. --- crates/core/src/error.rs | 20 ++++++++++ crates/macos/src/notifications/list.rs | 52 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index 8c3506b..4fc1b4f 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -163,3 +163,23 @@ impl AppError { AppError::Adapter(AdapterError::new(ErrorCode::InvalidArgs, msg)) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn notification_not_found_error_has_correct_code() { + let err = AdapterError::notification_not_found(5); + assert_eq!(err.code, ErrorCode::NotificationNotFound); + assert!(err.message.contains("5")); + assert!(err.suggestion.is_some()); + } + + #[test] + fn error_code_serialization() { + let code = ErrorCode::NotificationNotFound; + let json = serde_json::to_string(&code).unwrap(); + assert_eq!(json, "\"NOTIFICATION_NOT_FOUND\""); + } +} diff --git a/crates/macos/src/notifications/list.rs b/crates/macos/src/notifications/list.rs index 4e49283..ae1b6e4 100644 --- a/crates/macos/src/notifications/list.rs +++ b/crates/macos/src/notifications/list.rs @@ -231,3 +231,55 @@ fn matches_filters( fn list_from_nc(_filter: &NotificationFilter) -> Result, AdapterError> { Err(AdapterError::not_supported("list_notifications")) } + +#[cfg(test)] +mod tests { + use super::*; + + fn make_info(app: &str, title: &str, body: Option<&str>) -> NotificationInfo { + NotificationInfo { + index: 1, + app_name: app.into(), + title: title.into(), + body: body.map(String::from), + timestamp: None, + actions: vec![], + } + } + + #[test] + fn matches_filters_no_filter() { + let info = make_info("Slack", "Hello", None); + assert!(matches_filters(&info, &None, &None)); + } + + #[test] + fn matches_filters_app_match() { + let info = make_info("Slack", "Hello", None); + assert!(matches_filters(&info, &Some("slack".into()), &None)); + assert!(!matches_filters(&info, &Some("teams".into()), &None)); + } + + #[test] + fn matches_filters_text_match() { + let info = make_info("Slack", "Hello world", Some("body text")); + assert!(matches_filters(&info, &None, &Some("hello".into()))); + assert!(matches_filters(&info, &None, &Some("body".into()))); + assert!(!matches_filters(&info, &None, &Some("missing".into()))); + } + + #[test] + fn matches_filters_combined() { + let info = make_info("Slack", "Hello", None); + assert!(matches_filters( + &info, + &Some("slack".into()), + &Some("hello".into()) + )); + assert!(!matches_filters( + &info, + &Some("teams".into()), + &Some("hello".into()) + )); + } +}