mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
add tests
This commit is contained in:
parent
c395e24792
commit
7b638eb2c0
3 changed files with 110 additions and 20 deletions
|
@ -1,17 +1,51 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
||||
pub struct Audio {
|
||||
pub file_id: String,
|
||||
pub duration: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub performer: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mime_type: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_size: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thumb: Option<PhotoSize>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"file_id":"id",
|
||||
"duration":60,
|
||||
"performer":"Performer",
|
||||
"title":"Title",
|
||||
"mime_type":"MimeType",
|
||||
"file_size":123456,
|
||||
"thumb":{
|
||||
"file_id":"id",
|
||||
"width":320,
|
||||
"height":320,
|
||||
"file_size":3452
|
||||
}
|
||||
}"#;
|
||||
let expected = Audio {
|
||||
file_id: "id".to_string(),
|
||||
duration: 60,
|
||||
performer: Some("Performer".to_string()),
|
||||
title: Some("Title".to_string()),
|
||||
mime_type: Some("MimeType".to_string()),
|
||||
file_size: Some(123456),
|
||||
thumb: Some(PhotoSize {
|
||||
file_id: "id".to_string(),
|
||||
width: 320,
|
||||
height: 320,
|
||||
file_size: Some(3452)
|
||||
})
|
||||
};
|
||||
let actual = serde_json::from_str::<Audio>(&json).unwrap();
|
||||
assert_eq!(actual, expected)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,51 @@
|
|||
use crate::core::types::{Message, User};
|
||||
|
||||
/// This object represents an incoming callback query from a callback button in
|
||||
/// an inline keyboard.
|
||||
#[derive(Debug, Deserialize, PartialEq, Clone)]
|
||||
pub struct CallbackQuery {
|
||||
/// Unique identifier for this query
|
||||
pub id: String,
|
||||
/// Sender
|
||||
pub from: User,
|
||||
/// Message with the callback button that originated the query.
|
||||
/// Note that message content and message date will not be available if the
|
||||
/// message is too old
|
||||
pub message: Message,
|
||||
/// Global identifier, uniquely corresponding to the chat to which the
|
||||
/// message with the callback button was sent. Useful for high scores
|
||||
/// in games.
|
||||
pub chat_instance: String,
|
||||
/// Data associated with the callback button. Be aware that a bad client
|
||||
/// can send arbitrary data in this field.
|
||||
pub data: String,
|
||||
pub message: Option<Message>,
|
||||
pub inline_message_id: Option<String>,
|
||||
pub data: Option<String>,
|
||||
pub game_short_name: Option<String>
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"id":"id",
|
||||
"from":{
|
||||
"id":12345,
|
||||
"is_bot":false,
|
||||
"first_name":"firstName"
|
||||
},
|
||||
"inline_message_id":"i_m_id",
|
||||
"chat_instance":"123456",
|
||||
"data":"some_data",
|
||||
"game_short_name":"game_name"
|
||||
}"#;
|
||||
let expected = CallbackQuery {
|
||||
id: "id".to_string(),
|
||||
from: User {
|
||||
id: 12345,
|
||||
is_bot: false,
|
||||
first_name: "firstName".to_string(),
|
||||
last_name: None,
|
||||
username: None,
|
||||
language_code: None
|
||||
},
|
||||
chat_instance: "123456".to_string(),
|
||||
message: None,
|
||||
inline_message_id: Some("i_m_id".to_string()),
|
||||
data: Some("some_data".to_string()),
|
||||
game_short_name: Some("game_name".to_string())
|
||||
};
|
||||
let actual = serde_json::from_str::<CallbackQuery>(json).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,3 +7,30 @@ pub struct User {
|
|||
pub username: Option<String>,
|
||||
pub language_code: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"id":12345,
|
||||
"is_bot":false,
|
||||
"first_name":"firstName",
|
||||
"last_name":"lastName",
|
||||
"username":"Username",
|
||||
"language_code":"languageCode"
|
||||
}"#;
|
||||
let expected = User {
|
||||
id: 12345,
|
||||
is_bot: false,
|
||||
first_name: "firstName".to_string(),
|
||||
last_name: Some("lastName".to_string()),
|
||||
username: Some("Username".to_string()),
|
||||
language_code: Some("languageCode".to_string())
|
||||
};
|
||||
let actual = serde_json::from_str::<User>(&json).unwrap();
|
||||
assert_eq!(actual, expected)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue