| 1 | use serde_json::{Value, json}; |
| 2 | |
| 3 | pub fn messaging_policy_body() -> Value { |
| 4 | json!({"messagingPolicy": true}) |
| 5 | } |
| 6 | |
| 7 | /// Teams reads `messagingPolicy.allowPriorityMessages` and allows urgent messages unless it is `false`. |
| 8 | pub fn parse_allow_priority_messages(body: &Value) -> bool { |
| 9 | body.pointer("/messagingPolicy/value/allowPriorityMessages") |
| 10 | .and_then(Value::as_bool) |
| 11 | .unwrap_or(true) |
| 12 | } |
| 13 | |
| 14 | #[cfg(test)] |
| 15 | mod tests { |
| 16 | use super::*; |
| 17 | |
| 18 | #[test] |
| 19 | fn the_body_asks_for_the_messaging_policy() { |
| 20 | assert_eq!(messaging_policy_body(), json!({"messagingPolicy": true})); |
| 21 | } |
| 22 | |
| 23 | #[test] |
| 24 | fn priority_messages_follow_the_policy_and_default_to_allowed() { |
| 25 | let denied = json!({"messagingPolicy": {"value": {"allowPriorityMessages": false}}}); |
| 26 | let allowed = json!({"messagingPolicy": {"value": {"allowPriorityMessages": true}}}); |
| 27 | assert!(!parse_allow_priority_messages(&denied)); |
| 28 | assert!(parse_allow_priority_messages(&allowed)); |
| 29 | assert!(parse_allow_priority_messages(&json!({}))); |
| 30 | } |
| 31 | } |