mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
added docs and tests
This commit is contained in:
parent
de0b9f4ab8
commit
d380f2696f
2 changed files with 76 additions and 1 deletions
|
@ -1,13 +1,63 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
/// This object represents an animation file (GIF or H.264/MPEG-4 AVC video
|
||||
/// without sound).
|
||||
pub struct Animation {
|
||||
/// Identifier for this file
|
||||
pub file_id: String,
|
||||
/// Video width as defined by sender
|
||||
pub width: u32,
|
||||
/// Video height as defined by sender
|
||||
pub height: u32,
|
||||
/// Duration of the video in seconds as defined by sender
|
||||
pub duration: u32,
|
||||
pub thumb: PhotoSize,
|
||||
/// Optional. Animation thumbnail as defined by sender
|
||||
pub thumb: Option<PhotoSize>,
|
||||
/// Optional. Original animation filename as defined by sender
|
||||
pub file_name: Option<String>,
|
||||
/// Optional. MIME type of the file as defined by sender
|
||||
pub mime_type: Option<String>,
|
||||
/// Optional. File size
|
||||
pub file_size: Option<u32>
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"file_id":"id",
|
||||
"width":320,
|
||||
"height":320,
|
||||
"duration":59,
|
||||
"thumb":{
|
||||
"file_id":"id",
|
||||
"width":320,
|
||||
"height":320,
|
||||
"file_size":3452
|
||||
},
|
||||
"file_name":"some",
|
||||
"mime_type":"gif",
|
||||
"file_size":6500}"#;
|
||||
let expected = Animation {
|
||||
file_id: "id".to_string(),
|
||||
width: 320,
|
||||
height: 320,
|
||||
duration: 59,
|
||||
thumb: Some(PhotoSize {
|
||||
file_id: "id".to_string(),
|
||||
width: 320,
|
||||
height: 320,
|
||||
file_size: Some(3452)
|
||||
}),
|
||||
file_name: Some("some".to_string()),
|
||||
mime_type: Some("gif".to_string()),
|
||||
file_size: Some(6500)
|
||||
};
|
||||
let actual = serde_json::from_str::<Animation>(json).unwrap();
|
||||
assert_eq!(actual, expected)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,32 @@
|
|||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
|
||||
/// This object represents one size of a photo or a [`Document`] /
|
||||
/// [`Sticker`] thumbnail.
|
||||
pub struct PhotoSize {
|
||||
/// Identifier for this file
|
||||
pub file_id: String,
|
||||
/// Photo width
|
||||
pub width: i32,
|
||||
/// Photo height
|
||||
pub height: i32,
|
||||
/// Optional. File size
|
||||
pub file_size: Option<u32>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{"file_id":"id","width":320,"height":320,
|
||||
"file_size":3452}"#;
|
||||
let expected = PhotoSize {
|
||||
file_id: "id".to_string(),
|
||||
width: 320,
|
||||
height: 320,
|
||||
file_size: Some(3452)
|
||||
};
|
||||
let actual = serde_json::from_str::<PhotoSize>(json).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue