vkteams_bot/api/chats/
get_blocked_users.rs

1#![allow(unused_parens)]
2//! Get blocked users method `chats/getBlockedUsers`
3//! [More info](https://teams.vk.com/botapi/#/chats/get_chats_getBlockedUsers)
4use crate::api::types::*;
5bot_api_method! {
6    method   = "chats/getBlockedUsers",
7    request  = RequestChatsGetBlockedUsers {
8        required {
9            chat_id: ChatId,
10        },
11        optional {}
12    },
13    response = ResponseChatsGetBlockedUsers {
14        users: Vec<Users>,
15    },
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    use crate::api::types::{ChatId, UserId, Users};
22    use serde_json::json;
23
24    #[test]
25    fn test_request_chats_get_blocked_users_serialize() {
26        let req = RequestChatsGetBlockedUsers {
27            chat_id: ChatId::from("c1"),
28        };
29        let val = serde_json::to_value(&req).unwrap();
30        assert_eq!(val["chatId"], "c1");
31    }
32
33    #[test]
34    fn test_request_chats_get_blocked_users_deserialize() {
35        let val = json!({"chatId": "c2"});
36        let req: RequestChatsGetBlockedUsers = serde_json::from_value(val).unwrap();
37        assert_eq!(req.chat_id.0, "c2");
38    }
39
40    #[test]
41    fn test_response_chats_get_blocked_users_serialize() {
42        let resp = ResponseChatsGetBlockedUsers {
43            users: vec![Users {
44                user_id: UserId("u1".to_string()),
45            }],
46        };
47        let val = serde_json::to_value(&resp).unwrap();
48        assert_eq!(val["users"][0]["userId"], "u1");
49    }
50
51    #[test]
52    fn test_response_chats_get_blocked_users_deserialize() {
53        let val = json!({"users": [{"userId": "u2"}]});
54        let resp: ResponseChatsGetBlockedUsers = serde_json::from_value(val).unwrap();
55        assert_eq!(resp.users.len(), 1);
56        assert_eq!(resp.users[0].user_id.0, "u2");
57    }
58
59    #[test]
60    fn test_response_chats_get_blocked_users_empty_users() {
61        let val = json!({"users": []});
62        let resp: ResponseChatsGetBlockedUsers = serde_json::from_value(val).unwrap();
63        assert!(resp.users.is_empty());
64    }
65
66    #[test]
67    fn test_response_chats_get_blocked_users_missing_users() {
68        let val = json!({});
69        let resp = serde_json::from_value::<ResponseChatsGetBlockedUsers>(val);
70        assert!(resp.is_err());
71    }
72
73    #[test]
74    fn test_response_chats_get_blocked_users_user_missing_userid() {
75        let val = json!({"users": [{}]});
76        let resp = serde_json::from_value::<ResponseChatsGetBlockedUsers>(val);
77        assert!(resp.is_err());
78    }
79}