From c395e24792d113dd8f67323cb08295e203a7bc4c Mon Sep 17 00:00:00 2001 From: P0lunin Date: Thu, 19 Sep 2019 19:37:48 +0300 Subject: [PATCH] add enum ChatMemberStatus --- src/core/types/chat_member.rs | 73 ++++++++++++++++++++++++- src/core/types/mod.rs | 2 +- src/core/types/not_implemented_types.rs | 3 - 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/core/types/chat_member.rs b/src/core/types/chat_member.rs index 600b7e2e..cee60bc6 100644 --- a/src/core/types/chat_member.rs +++ b/src/core/types/chat_member.rs @@ -1,4 +1,4 @@ -use crate::core::types::{ChatMemberStatus, User}; +use crate::core::types::User; /// This object contains information about one member of the chat. #[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] @@ -54,3 +54,74 @@ pub struct ChatMember { /// his messages, implies can_send_media_messages pub can_add_web_page_previews: Option, } + +#[derive(Deserialize, Debug, Hash, PartialEq, Eq, Clone)] +#[serde(rename_all = "snake_case")] +pub enum ChatMemberStatus { + Creator, + Administrator, + Member, + Restricted, + Left, + Kicked +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize() { + let json = r#"{ + "user":{ + "id":12345, + "is_bot":false, + "first_name":"firstName" + }, + "status":"creator", + "until_date":123456, + "can_be_edited":true, + "can_post_messages":true, + "can_edit_messages":true, + "can_delete_messages":true, + "can_restrict_members":true, + "can_promote_members":true, + "can_change_info":true, + "can_invite_users":true, + "can_pin_messages":true, + "is_member":true, + "can_send_messages":true, + "can_send_media_messages":true, + "can_send_polls":true, + "can_send_other_messages":true, + "can_add_web_page_previews":true + }"#; + let expected = ChatMember { + user: User { + id: 12345, + is_bot: false, + first_name: "firstName".to_string(), + last_name: None, + username: None, + language_code: None + }, + status: ChatMemberStatus::Creator, + until_date: Some(123456), + can_be_edited: Some(true), + can_change_info: Some(true), + can_post_messages: Some(true), + can_edit_messages: Some(true), + can_delete_messages: Some(true), + can_invite_users: Some(true), + can_restrict_members: Some(true), + can_pin_messages: Some(true), + can_promote_members: Some(true), + can_send_messages: Some(true), + can_send_media_messages: Some(true), + can_send_other_messages: Some(true), + can_add_web_page_previews: Some(true) + }; + let actual = serde_json::from_str::(&json).unwrap(); + assert_eq!(actual, expected) + } +} \ No newline at end of file diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index 42e9869a..27ba457b 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -4,7 +4,7 @@ pub use self::{ audio::Audio, callback_query::CallbackQuery, chat::{Chat, ChatKind, NonPrivateChatKind}, - chat_member::ChatMember, + chat_member::{ChatMember, ChatMemberStatus}, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, chosen_inline_result::ChosenInlineResult, diff --git a/src/core/types/not_implemented_types.rs b/src/core/types/not_implemented_types.rs index c2700b2d..c1e9d2ba 100644 --- a/src/core/types/not_implemented_types.rs +++ b/src/core/types/not_implemented_types.rs @@ -1,5 +1,2 @@ #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct PassportData; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct ChatMemberStatus;