use super::{overrides_with_notifications, resolved_with_notification_config};
#[test]
fn notification_config_enabled_true_when_notify_fail_only() {
let resolved = resolved_with_notification_config(Some(true), Some(true), Some(true));
let overrides = overrides_with_notifications(None, Some(true));
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(
enabled,
"enabled should be true when notify_on_fail is true"
);
assert!(
notify_on_complete,
"notify_on_complete should be true from config"
);
assert!(
notify_on_fail,
"notify_on_fail should be true from CLI override"
);
assert!(
notify_on_loop_complete,
"notify_on_loop_complete should be true from config"
);
}
#[test]
fn notification_config_enabled_true_when_no_notify_and_notify_fail() {
let resolved = resolved_with_notification_config(Some(true), Some(true), Some(true));
let overrides = overrides_with_notifications(Some(false), Some(true));
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(
enabled,
"enabled should be true when notify_on_fail is true even if notify_on_complete is false"
);
assert!(
!notify_on_complete,
"notify_on_complete should be false from CLI override"
);
assert!(
notify_on_fail,
"notify_on_fail should be true from CLI override"
);
assert!(
notify_on_loop_complete,
"notify_on_loop_complete should be true from config"
);
}
#[test]
fn notification_config_enabled_false_when_all_disabled() {
let resolved = resolved_with_notification_config(Some(false), Some(false), Some(false));
let overrides = overrides_with_notifications(None, None);
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(
!enabled,
"enabled should be false when all notification types are disabled"
);
assert!(!notify_on_complete, "notify_on_complete should be false");
assert!(!notify_on_fail, "notify_on_fail should be false");
assert!(
!notify_on_loop_complete,
"notify_on_loop_complete should be false"
);
}
#[test]
fn notification_config_enabled_true_when_notify_alone() {
let resolved = resolved_with_notification_config(Some(false), Some(false), Some(false));
let overrides = overrides_with_notifications(Some(true), None);
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(
enabled,
"enabled should be true when notify_on_complete is true"
);
assert!(
notify_on_complete,
"notify_on_complete should be true from CLI override"
);
assert!(
!notify_on_fail,
"notify_on_fail should be false from config"
);
assert!(
!notify_on_loop_complete,
"notify_on_loop_complete should be false from config (not using default)"
);
}
#[test]
fn notification_config_cli_overrides_config() {
let resolved = resolved_with_notification_config(Some(false), Some(false), Some(false));
let overrides = overrides_with_notifications(Some(true), Some(true));
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(enabled);
assert!(notify_on_complete, "CLI should override config");
assert!(notify_on_fail, "CLI should override config");
assert!(
!notify_on_loop_complete,
"notify_on_loop_complete should be false from config (not using default)"
);
}
#[test]
fn notification_config_uses_config_when_no_cli_overrides() {
let resolved = resolved_with_notification_config(Some(true), Some(false), Some(true));
let overrides = overrides_with_notifications(None, None);
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(enabled);
assert!(notify_on_complete, "should use config value");
assert!(!notify_on_fail, "should use config value");
assert!(notify_on_loop_complete, "should use config value");
}
#[test]
fn notification_config_bug_no_notify_suppresses_all_notifications() {
let resolved = resolved_with_notification_config(Some(true), Some(true), Some(true));
let overrides = overrides_with_notifications(Some(false), None);
let notify_on_complete = overrides
.notify_on_complete
.or(resolved.config.agent.notification.notify_on_complete)
.unwrap_or(true);
let notify_on_fail = overrides
.notify_on_fail
.or(resolved.config.agent.notification.notify_on_fail)
.unwrap_or(true);
let notify_on_loop_complete = resolved
.config
.agent
.notification
.notify_on_loop_complete
.unwrap_or(true);
let enabled = notify_on_complete || notify_on_fail || notify_on_loop_complete;
assert!(
enabled,
"BUG: enabled should be true because notify_on_fail and notify_on_loop_complete are still enabled"
);
assert!(
!notify_on_complete,
"notify_on_complete should be false from --no-notify"
);
assert!(
notify_on_fail,
"notify_on_fail should still be true from config"
);
assert!(
notify_on_loop_complete,
"notify_on_loop_complete should still be true from config"
);
}