vkteams_bot/api/chats/
unpin_message.rs

1//! Unpin Message method `chats/unpinMessage`
2//! [More info](https://teams.vk.com/botapi/#/chats/get_chats_unpinMessage)
3use crate::api::types::*;
4bot_api_method! {
5    method   = "chats/unpinMessage",
6    request  = RequestChatsUnpinMessage {
7        required {
8            chat_id: ChatId,
9            msg_id: MsgId,
10        },
11        optional {}
12    },
13    response = ResponseChatsUnpinMessage {},
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19    use crate::api::types::{ChatId, MsgId};
20    use serde_json::json;
21
22    #[test]
23    fn test_request_chats_unpin_message_serialize() {
24        let req = RequestChatsUnpinMessage {
25            chat_id: ChatId::from("c1"),
26            msg_id: MsgId("m1".to_string()),
27        };
28        let val = serde_json::to_value(&req).unwrap();
29        assert_eq!(val["chatId"], "c1");
30        assert_eq!(val["msgId"], "m1");
31    }
32
33    #[test]
34    fn test_request_chats_unpin_message_deserialize() {
35        let val = json!({"chatId": "c2", "msgId": "m2"});
36        let req: RequestChatsUnpinMessage = serde_json::from_value(val).unwrap();
37        assert_eq!(req.chat_id.0, "c2");
38        assert_eq!(req.msg_id.0, "m2");
39    }
40
41    #[test]
42    fn test_response_chats_unpin_message_serialize() {
43        let resp = ResponseChatsUnpinMessage {};
44        let val = serde_json::to_value(&resp).unwrap();
45        assert_eq!(val.as_object().unwrap().len(), 0);
46    }
47
48    #[test]
49    fn test_response_chats_unpin_message_deserialize() {
50        let val = json!({});
51        let resp: ResponseChatsUnpinMessage = serde_json::from_value(val).unwrap();
52        let _ = resp;
53    }
54
55    #[test]
56    fn test_request_chats_unpin_message_missing_fields() {
57        let val = json!({"chatId": "c1"});
58        let req = serde_json::from_value::<RequestChatsUnpinMessage>(val);
59        assert!(req.is_err());
60    }
61
62    #[test]
63    fn test_request_chats_unpin_message_wrong_type() {
64        let val = json!({"chatId": 123, "msgId": "m1"});
65        let req = serde_json::from_value::<RequestChatsUnpinMessage>(val);
66        assert!(req.is_err());
67    }
68}