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.
This commit is contained in:
Lahfir 2026-02-27 10:53:15 -08:00
parent 53d697d522
commit 2374330bb1
2 changed files with 72 additions and 0 deletions

View file

@ -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\"");
}
}

View file

@ -231,3 +231,55 @@ fn matches_filters(
fn list_from_nc(_filter: &NotificationFilter) -> Result<Vec<NotificationInfo>, 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())
));
}
}