BlueGit

ict rusty-teams

Files

rusty-teams / crates / chatsvc / src / messaging_policy.rs

messaging_policy.rs

messaging_policy.rs 1.0 KiB Download Raw
1use serde_json::{Value, json};
2
3pub fn messaging_policy_body() -> Value {
4 json!({"messagingPolicy": true})
5}
6
7/// Teams reads `messagingPolicy.allowPriorityMessages` and allows urgent messages unless it is `false`.
8pub 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)]
15mod 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}