mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Added tests for media (video) and media as part of media group
This commit is contained in:
parent
1fa64afad2
commit
b42c8b65f7
10 changed files with 212 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
||||||
use crate::core::types::{ChatPermissions, ChatPhoto, Message};
|
use crate::core::types::{ChatPermissions, ChatPhoto, Message};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
@ -10,7 +10,7 @@ pub struct Chat {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum ChatKind {
|
pub enum ChatKind {
|
||||||
NonPrivate {
|
NonPrivate {
|
||||||
|
@ -33,7 +33,7 @@ pub enum ChatKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum NonPrivateChatKind {
|
pub enum NonPrivateChatKind {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::core::types::PhotoSize;
|
use crate::core::types::PhotoSize;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
pub file_id: String,
|
pub file_id: String,
|
||||||
pub thumb: Option<PhotoSize>,
|
pub thumb: Option<PhotoSize>,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||||
pub struct Invoice {
|
pub struct Invoice {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::core::types::{
|
||||||
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
|
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
#[serde(rename = "message_id")]
|
#[serde(rename = "message_id")]
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
|
@ -14,7 +14,7 @@ pub struct Message {
|
||||||
pub message_kind: MessageKind,
|
pub message_kind: MessageKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum MessageKind {
|
pub enum MessageKind {
|
||||||
IncomingMessage {
|
IncomingMessage {
|
||||||
|
@ -72,7 +72,7 @@ pub enum MessageKind {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
pub enum Sender {
|
pub enum Sender {
|
||||||
/// If message is sent from Chat
|
/// If message is sent from Chat
|
||||||
#[serde(rename = "from")]
|
#[serde(rename = "from")]
|
||||||
|
@ -82,7 +82,7 @@ pub enum Sender {
|
||||||
Signature(String),
|
Signature(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum ForwardKind {
|
pub enum ForwardKind {
|
||||||
ChannelForward {
|
ChannelForward {
|
||||||
|
@ -106,7 +106,7 @@ pub enum ForwardKind {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
pub enum ForwardedFrom {
|
pub enum ForwardedFrom {
|
||||||
#[serde(rename = "forward_from")]
|
#[serde(rename = "forward_from")]
|
||||||
User(User),
|
User(User),
|
||||||
|
@ -114,11 +114,12 @@ pub enum ForwardedFrom {
|
||||||
SenderName(String),
|
SenderName(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum MediaKind {
|
pub enum MediaKind {
|
||||||
Animation {
|
Animation {
|
||||||
animation: Animation,
|
animation: Animation,
|
||||||
|
#[doc(hidden)]
|
||||||
/// "For backward compatibility" (c) Telegram Docs
|
/// "For backward compatibility" (c) Telegram Docs
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
document: (),
|
document: (),
|
||||||
|
@ -148,11 +149,11 @@ pub enum MediaKind {
|
||||||
location: Location,
|
location: Location,
|
||||||
},
|
},
|
||||||
Photo {
|
Photo {
|
||||||
sizes: Vec<PhotoSize>,
|
photo: Vec<PhotoSize>,
|
||||||
caption: Option<String>,
|
caption: Option<String>,
|
||||||
#[serde(default = "Vec::new")]
|
#[serde(default = "Vec::new")]
|
||||||
caption_entities: Vec<MessageEntity>,
|
caption_entities: Vec<MessageEntity>,
|
||||||
media_group_id: Option<i32>,
|
media_group_id: Option<String>,
|
||||||
},
|
},
|
||||||
Poll {
|
Poll {
|
||||||
poll: Poll,
|
poll: Poll,
|
||||||
|
@ -170,7 +171,7 @@ pub enum MediaKind {
|
||||||
caption: Option<String>,
|
caption: Option<String>,
|
||||||
#[serde(default = "Vec::new")]
|
#[serde(default = "Vec::new")]
|
||||||
caption_entities: Vec<MessageEntity>,
|
caption_entities: Vec<MessageEntity>,
|
||||||
media_group_id: Option<i32>,
|
media_group_id: Option<String>,
|
||||||
},
|
},
|
||||||
VideoNote {
|
VideoNote {
|
||||||
video_note: VideoNote,
|
video_note: VideoNote,
|
||||||
|
@ -227,8 +228,197 @@ mod tests {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// actual message from telegram
|
// actual message from telegram
|
||||||
let json = r#"{"message_id":6534,"from":{"id":457569668,"is_bot":true,"first_name":"BT","username":"BloodyTestBot"},"chat":{"id":218485655,"first_name":"W","username":"WaffleLapkin","type":"private"},"date":1567898953,"text":"text"}"#;
|
let json = r#"{
|
||||||
|
"message_id": 6534,
|
||||||
|
"from": {
|
||||||
|
"id": 457569668,
|
||||||
|
"is_bot": true,
|
||||||
|
"first_name": "BT",
|
||||||
|
"username": "BloodyTestBot"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 218485655,
|
||||||
|
"first_name": "W",
|
||||||
|
"username": "WaffleLapkin",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1567898953,
|
||||||
|
"text": "text"
|
||||||
|
}"#;
|
||||||
let actual = from_str::<Message>(json).unwrap();
|
let actual = from_str::<Message>(json).unwrap();
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn media_message_de() {
|
||||||
|
let json = r#"{
|
||||||
|
"message_id": 198283,
|
||||||
|
"from": {
|
||||||
|
"id": 250918540,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 250918540,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1567927221,
|
||||||
|
"video": {
|
||||||
|
"duration": 13,
|
||||||
|
"width": 512,
|
||||||
|
"height": 640,
|
||||||
|
"mime_type": "video/mp4",
|
||||||
|
"thumb": {
|
||||||
|
"file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE",
|
||||||
|
"file_size": 10339,
|
||||||
|
"width": 256,
|
||||||
|
"height": 320
|
||||||
|
},
|
||||||
|
"file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE",
|
||||||
|
"file_size": 1381334
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
let actual = from_str::<Message>(json).unwrap();
|
||||||
|
let expected = Message {
|
||||||
|
id: 198283,
|
||||||
|
date: 1567927221,
|
||||||
|
chat: Chat {
|
||||||
|
id: 250918540,
|
||||||
|
photo: None,
|
||||||
|
kind: ChatKind::Private {
|
||||||
|
first_name: Some("Андрей".to_string()),
|
||||||
|
last_name: Some("Власов".to_string()),
|
||||||
|
username: Some("aka_dude".to_string()),
|
||||||
|
type_: ()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
message_kind: MessageKind::IncomingMessage {
|
||||||
|
from: Sender::User(User {
|
||||||
|
id: 250918540,
|
||||||
|
is_bot: false,
|
||||||
|
first_name: "Андрей".to_string(),
|
||||||
|
last_name: Some("Власов".to_string()),
|
||||||
|
username: Some("aka_dude".to_string()),
|
||||||
|
language_code: Some("en".to_string())
|
||||||
|
}),
|
||||||
|
forward_kind: ForwardKind::Origin { reply_to_message: None },
|
||||||
|
edit_date: None,
|
||||||
|
media_kind: MediaKind::Video {
|
||||||
|
video: Video {
|
||||||
|
duration: 13,
|
||||||
|
width: 512,
|
||||||
|
height: 640,
|
||||||
|
mime_type: Some("video/mp4".to_string()),
|
||||||
|
thumb: Some(PhotoSize {
|
||||||
|
file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(),
|
||||||
|
file_size: Some(10339),
|
||||||
|
width: 256,
|
||||||
|
height: 320
|
||||||
|
}),
|
||||||
|
file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(),
|
||||||
|
file_size: Some(1381334)
|
||||||
|
},
|
||||||
|
caption: None,
|
||||||
|
caption_entities: vec![],
|
||||||
|
media_group_id: None
|
||||||
|
},
|
||||||
|
reply_markup: None
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn media_group_message_de() {
|
||||||
|
let json = r#"{
|
||||||
|
"message_id": 198283,
|
||||||
|
"from": {
|
||||||
|
"id": 250918540,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 250918540,
|
||||||
|
"first_name": "Андрей",
|
||||||
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1567927221,
|
||||||
|
"media_group_id": "12543417770506682",
|
||||||
|
"video": {
|
||||||
|
"duration": 13,
|
||||||
|
"width": 512,
|
||||||
|
"height": 640,
|
||||||
|
"mime_type": "video/mp4",
|
||||||
|
"thumb": {
|
||||||
|
"file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE",
|
||||||
|
"file_size": 10339,
|
||||||
|
"width": 256,
|
||||||
|
"height": 320
|
||||||
|
},
|
||||||
|
"file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE",
|
||||||
|
"file_size": 1381334
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
let actual = from_str::<Message>(json).unwrap();
|
||||||
|
let expected = Message {
|
||||||
|
id: 198283,
|
||||||
|
date: 1567927221,
|
||||||
|
chat: Chat {
|
||||||
|
id: 250918540,
|
||||||
|
photo: None,
|
||||||
|
kind: ChatKind::Private {
|
||||||
|
first_name: Some("Андрей".to_string()),
|
||||||
|
last_name: Some("Власов".to_string()),
|
||||||
|
username: Some("aka_dude".to_string()),
|
||||||
|
type_: ()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
message_kind: MessageKind::IncomingMessage {
|
||||||
|
from: Sender::User(User {
|
||||||
|
id: 250918540,
|
||||||
|
is_bot: false,
|
||||||
|
first_name: "Андрей".to_string(),
|
||||||
|
last_name: Some("Власов".to_string()),
|
||||||
|
username: Some("aka_dude".to_string()),
|
||||||
|
language_code: Some("en".to_string())
|
||||||
|
}),
|
||||||
|
forward_kind: ForwardKind::Origin { reply_to_message: None },
|
||||||
|
edit_date: None,
|
||||||
|
media_kind: MediaKind::Video {
|
||||||
|
video: Video {
|
||||||
|
duration: 13,
|
||||||
|
width: 512,
|
||||||
|
height: 640,
|
||||||
|
mime_type: Some("video/mp4".to_string()),
|
||||||
|
thumb: Some(PhotoSize {
|
||||||
|
file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(),
|
||||||
|
file_size: Some(10339),
|
||||||
|
width: 256,
|
||||||
|
height: 320
|
||||||
|
}),
|
||||||
|
file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(),
|
||||||
|
file_size: Some(1381334)
|
||||||
|
},
|
||||||
|
caption: None,
|
||||||
|
caption_entities: vec![],
|
||||||
|
media_group_id: Some("12543417770506682".to_string())
|
||||||
|
},
|
||||||
|
reply_markup: None
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::core::types::User;
|
use crate::core::types::User;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
pub struct MessageEntity {
|
pub struct MessageEntity {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub kind: MessageEntityKind,
|
pub kind: MessageEntityKind,
|
||||||
|
@ -8,7 +8,7 @@ pub struct MessageEntity {
|
||||||
pub length: usize,
|
pub length: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum MessageEntityKind {
|
pub enum MessageEntityKind {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::core::types::ShippingAddress;
|
use crate::core::types::ShippingAddress;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||||
pub struct OrderInfo {
|
pub struct OrderInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub phone_number: String,
|
pub phone_number: String,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||||
pub struct ShippingAddress {
|
pub struct ShippingAddress {
|
||||||
pub country_code: String,
|
pub country_code: String,
|
||||||
pub state: String,
|
pub state: String,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::core::types::{MaskPosition, PhotoSize};
|
use crate::core::types::{MaskPosition, PhotoSize};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||||
pub struct Sticker {
|
pub struct Sticker {
|
||||||
pub file_id: String,
|
pub file_id: String,
|
||||||
pub width: u16,
|
pub width: u16,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::core::types::OrderInfo;
|
use crate::core::types::OrderInfo;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||||
pub struct SuccessfulPayment {
|
pub struct SuccessfulPayment {
|
||||||
pub currency: String,
|
pub currency: String,
|
||||||
pub total_amount: i64,
|
pub total_amount: i64,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub is_bot: bool,
|
pub is_bot: bool,
|
||||||
|
|
Loading…
Reference in a new issue