Add some deserialization tests for topic-related types/values

This commit is contained in:
Maybe Waffle 2023-02-01 16:57:42 +04:00
parent 6a2f5d7f2f
commit 0b83007954
3 changed files with 52 additions and 1 deletions

View file

@ -19,3 +19,20 @@ pub struct ForumTopicCreated {
// FIXME: CustomEmojiId // FIXME: CustomEmojiId
pub icon_custom_emoji_id: Option<String>, pub icon_custom_emoji_id: Option<String>,
} }
#[cfg(test)]
mod tests {
use crate::types::ForumTopicCreated;
#[test]
fn deserialization() {
let json =
r#"{"icon_color":9367192,"icon_custom_emoji_id":"5312536423851630001","name":"???"}"#;
let event = serde_json::from_str::<ForumTopicCreated>(json).unwrap();
assert_eq!(event.name, "???");
assert_eq!(event.icon_color, [0x8E, 0xEE, 0x98]);
assert_eq!(event.icon_custom_emoji_id.as_deref(), Some("5312536423851630001"));
}
}

View file

@ -117,6 +117,8 @@ pub struct MessageCommon {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
/// `true`, if the message is sent to a forum topic. /// `true`, if the message is sent to a forum topic.
// FIXME: `is_topic_message` is included even in service messages, like ForumTopicCreated.
// more this to `Message`
#[serde(default)] #[serde(default)]
pub is_topic_message: bool, pub is_topic_message: bool,
@ -1838,4 +1840,36 @@ mod tests {
assert!(!entities.is_empty()); assert!(!entities.is_empty());
assert_eq!(entities[0].kind().clone(), MessageEntityKind::Url); assert_eq!(entities[0].kind().clone(), MessageEntityKind::Url);
} }
#[test]
fn topic_created() {
let json = r#"{
"chat":{"id":-1001847508954,"is_forum":true,"title":"twest","type":"supergroup"},
"date":1675229139,
"forum_topic_created":{
"icon_color":9367192,
"icon_custom_emoji_id":"5312536423851630001",
"name":"???"
},
"from":{
"first_name":"вафель'",
"id":1253681278,
"is_bot":false,
"language_code":"en",
"username":"wafflelapkin"
},
"is_topic_message":true,
"message_id":4,
"message_thread_id":4
}"#;
let message: Message = serde_json::from_str(json).unwrap();
}
#[test]
fn topic_message() {
let json = r#"{"chat":{"id":-1001847508954,"is_forum":true,"title":"twest","type":"supergroup"},"date":1675229140,"from":{"first_name":"вафель'","id":1253681278,"is_bot":false,"language_code":"en","username":"wafflelapkin"},"is_topic_message":true,"message_id":5,"message_thread_id":4,"reply_to_message":{"chat":{"id":-1001847508954,"is_forum":true,"title":"twest","type":"supergroup"},"date":1675229139,"forum_topic_created":{"icon_color":9367192,"icon_custom_emoji_id":"5312536423851630001","name":"???"},"from":{"first_name":"вафель'","id":1253681278,"is_bot":false,"language_code":"en","username":"wafflelapkin"},"is_topic_message":true,"message_id":4,"message_thread_id":4},"text":"blah"}"#;
let message: Message = serde_json::from_str(json).unwrap();
}
} }