mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Message test: english -> francais
This commit is contained in:
parent
a6c8942063
commit
0a87a8ecd2
1 changed files with 177 additions and 217 deletions
|
@ -193,232 +193,192 @@ mod tests {
|
||||||
use serde_json::from_str;
|
use serde_json::from_str;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sent_message_de() {
|
fn de_media_forwarded() {
|
||||||
let expected = Message {
|
|
||||||
id: 6534,
|
|
||||||
date: 1567898953,
|
|
||||||
chat: Chat {
|
|
||||||
id: 218485655,
|
|
||||||
photo: None,
|
|
||||||
kind: ChatKind::Private {
|
|
||||||
type_: (),
|
|
||||||
first_name: Some("W".to_string()),
|
|
||||||
last_name: None,
|
|
||||||
username: Some("WaffleLapkin".to_string()),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
message_kind: MessageKind::IncomingMessage {
|
|
||||||
from: Sender::User(User {
|
|
||||||
id: 457569668,
|
|
||||||
is_bot: true,
|
|
||||||
first_name: "BT".to_string(),
|
|
||||||
last_name: None,
|
|
||||||
username: Some("BloodyTestBot".to_string()),
|
|
||||||
language_code: None,
|
|
||||||
}),
|
|
||||||
forward_kind: ForwardKind::Origin {
|
|
||||||
reply_to_message: None,
|
|
||||||
},
|
|
||||||
edit_date: None,
|
|
||||||
media_kind: MediaKind::Text {
|
|
||||||
text: "text".to_string(),
|
|
||||||
entities: vec![],
|
|
||||||
},
|
|
||||||
reply_markup: None,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// actual message from telegram
|
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"message_id": 6534,
|
"message_id": 198283,
|
||||||
"from": {
|
"from": {
|
||||||
"id": 457569668,
|
"id": 250918540,
|
||||||
"is_bot": true,
|
"is_bot": false,
|
||||||
"first_name": "BT",
|
"first_name": "Андрей",
|
||||||
"username": "BloodyTestBot"
|
"last_name": "Власов",
|
||||||
},
|
"username": "aka_dude",
|
||||||
"chat": {
|
"language_code": "en"
|
||||||
"id": 218485655,
|
},
|
||||||
"first_name": "W",
|
"chat": {
|
||||||
"username": "WaffleLapkin",
|
"id": 250918540,
|
||||||
"type": "private"
|
"first_name": "Андрей",
|
||||||
},
|
"last_name": "Власов",
|
||||||
"date": 1567898953,
|
"username": "aka_dude",
|
||||||
"text": "text"
|
"type": "private"
|
||||||
}"#;
|
},
|
||||||
let actual = from_str::<Message>(json).unwrap();
|
"date": 1567927221,
|
||||||
assert_eq!(expected, actual);
|
"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 message = from_str::<Message>(json);
|
||||||
|
assert!(message.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn media_message_de() {
|
fn de_media_group_forwarded() {
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"message_id": 198283,
|
"message_id": 198283,
|
||||||
"from": {
|
"from": {
|
||||||
"id": 250918540,
|
"id": 250918540,
|
||||||
"is_bot": false,
|
"is_bot": false,
|
||||||
"first_name": "Андрей",
|
"first_name": "Андрей",
|
||||||
"last_name": "Власов",
|
"last_name": "Власов",
|
||||||
"username": "aka_dude",
|
"username": "aka_dude",
|
||||||
"language_code": "en"
|
"language_code": "en"
|
||||||
},
|
},
|
||||||
"chat": {
|
"chat": {
|
||||||
"id": 250918540,
|
"id": 250918540,
|
||||||
"first_name": "Андрей",
|
"first_name": "Андрей",
|
||||||
"last_name": "Власов",
|
"last_name": "Власов",
|
||||||
"username": "aka_dude",
|
"username": "aka_dude",
|
||||||
"type": "private"
|
"type": "private"
|
||||||
},
|
},
|
||||||
"date": 1567927221,
|
"date": 1567927221,
|
||||||
"video": {
|
"media_group_id": "12543417770506682",
|
||||||
"duration": 13,
|
"video": {
|
||||||
"width": 512,
|
"duration": 13,
|
||||||
"height": 640,
|
"width": 512,
|
||||||
"mime_type": "video/mp4",
|
"height": 640,
|
||||||
"thumb": {
|
"mime_type": "video/mp4",
|
||||||
"file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE",
|
"thumb": {
|
||||||
"file_size": 10339,
|
"file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE",
|
||||||
"width": 256,
|
"file_size": 10339,
|
||||||
"height": 320
|
"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 {
|
"file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE",
|
||||||
from: Sender::User(User {
|
"file_size": 1381334
|
||||||
id: 250918540,
|
}
|
||||||
is_bot: false,
|
}"#;
|
||||||
first_name: "Андрей".to_string(),
|
let message = from_str::<Message>(json);
|
||||||
last_name: Some("Власов".to_string()),
|
assert!(message.is_ok());
|
||||||
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]
|
#[test]
|
||||||
fn media_group_message_de() {
|
fn de_text() {
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"message_id": 198283,
|
"message_id": 199785,
|
||||||
"from": {
|
"from": {
|
||||||
"id": 250918540,
|
"id": 250918540,
|
||||||
"is_bot": false,
|
"is_bot": false,
|
||||||
"first_name": "Андрей",
|
"first_name": "Андрей",
|
||||||
"last_name": "Власов",
|
"last_name": "Власов",
|
||||||
"username": "aka_dude",
|
"username": "aka_dude",
|
||||||
"language_code": "en"
|
"language_code": "en"
|
||||||
},
|
},
|
||||||
"chat": {
|
"chat": {
|
||||||
"id": 250918540,
|
"id": 250918540,
|
||||||
"first_name": "Андрей",
|
"first_name": "Андрей",
|
||||||
"last_name": "Власов",
|
"last_name": "Власов",
|
||||||
"username": "aka_dude",
|
"username": "aka_dude",
|
||||||
"type": "private"
|
"type": "private"
|
||||||
},
|
},
|
||||||
"date": 1567927221,
|
"date": 1568289890,
|
||||||
"media_group_id": "12543417770506682",
|
"text": "Лол кек 😂"
|
||||||
"video": {
|
}"#;
|
||||||
"duration": 13,
|
let message = from_str::<Message>(json);
|
||||||
"width": 512,
|
assert!(message.is_ok());
|
||||||
"height": 640,
|
}
|
||||||
"mime_type": "video/mp4",
|
|
||||||
"thumb": {
|
#[test]
|
||||||
"file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE",
|
fn de_sticker() {
|
||||||
"file_size": 10339,
|
let json = r#"{
|
||||||
"width": 256,
|
"message_id": 199787,
|
||||||
"height": 320
|
"from": {
|
||||||
},
|
"id": 250918540,
|
||||||
"file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE",
|
"is_bot": false,
|
||||||
"file_size": 1381334
|
"first_name": "Андрей",
|
||||||
}
|
"last_name": "Власов",
|
||||||
}"#;
|
"username": "aka_dude",
|
||||||
let actual = from_str::<Message>(json).unwrap();
|
"language_code": "en"
|
||||||
let expected = Message {
|
},
|
||||||
id: 198283,
|
"chat": {
|
||||||
date: 1567927221,
|
"id": 250918540,
|
||||||
chat: Chat {
|
"first_name": "Андрей",
|
||||||
id: 250918540,
|
"last_name": "Власов",
|
||||||
photo: None,
|
"username": "aka_dude",
|
||||||
kind: ChatKind::Private {
|
"type": "private"
|
||||||
first_name: Some("Андрей".to_string()),
|
},
|
||||||
last_name: Some("Власов".to_string()),
|
"date": 1568290188,
|
||||||
username: Some("aka_dude".to_string()),
|
"sticker": {
|
||||||
type_: ()
|
"width": 512,
|
||||||
}
|
"height": 512,
|
||||||
},
|
"emoji": "😡",
|
||||||
message_kind: MessageKind::IncomingMessage {
|
"set_name": "AdvenTimeAnim",
|
||||||
from: Sender::User(User {
|
"is_animated": true,
|
||||||
id: 250918540,
|
"thumb": {
|
||||||
is_bot: false,
|
"file_id": "AAQCAAMjAAOw0PgMaabKAcaXKCBLubkPAAQBAAdtAAPGKwACFgQ",
|
||||||
first_name: "Андрей".to_string(),
|
"file_size": 4118,
|
||||||
last_name: Some("Власов".to_string()),
|
"width": 128,
|
||||||
username: Some("aka_dude".to_string()),
|
"height": 128
|
||||||
language_code: Some("en".to_string())
|
},
|
||||||
}),
|
"file_id": "CAADAgADIwADsND4DGmmygHGlyggFgQ",
|
||||||
forward_kind: ForwardKind::Origin { reply_to_message: None },
|
"file_size": 16639
|
||||||
edit_date: None,
|
}
|
||||||
media_kind: MediaKind::Video {
|
}"#;
|
||||||
video: Video {
|
let message = from_str::<Message>(json);
|
||||||
duration: 13,
|
assert!(message.is_ok());
|
||||||
width: 512,
|
}
|
||||||
height: 640,
|
|
||||||
mime_type: Some("video/mp4".to_string()),
|
#[test]
|
||||||
thumb: Some(PhotoSize {
|
fn de_image() {
|
||||||
file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(),
|
let json = r#"{
|
||||||
file_size: Some(10339),
|
"message_id": 199791,
|
||||||
width: 256,
|
"from": {
|
||||||
height: 320
|
"id": 250918540,
|
||||||
}),
|
"is_bot": false,
|
||||||
file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(),
|
"first_name": "Андрей",
|
||||||
file_size: Some(1381334)
|
"last_name": "Власов",
|
||||||
},
|
"username": "aka_dude",
|
||||||
caption: None,
|
"language_code": "en"
|
||||||
caption_entities: vec![],
|
},
|
||||||
media_group_id: Some("12543417770506682".to_string())
|
"chat": {
|
||||||
},
|
"id": 250918540,
|
||||||
reply_markup: None
|
"first_name": "Андрей",
|
||||||
},
|
"last_name": "Власов",
|
||||||
|
"username": "aka_dude",
|
||||||
};
|
"type": "private"
|
||||||
assert_eq!(actual, expected);
|
},
|
||||||
|
"date": 1568290622,
|
||||||
|
"photo": [
|
||||||
|
{
|
||||||
|
"file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA20AAybcBAABFgQ",
|
||||||
|
"file_size": 18188,
|
||||||
|
"width": 320,
|
||||||
|
"height": 239
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA3gAAyfcBAABFgQ",
|
||||||
|
"file_size": 62123,
|
||||||
|
"width": 800,
|
||||||
|
"height": 598
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA3kAAyTcBAABFgQ",
|
||||||
|
"file_size": 75245,
|
||||||
|
"width": 962,
|
||||||
|
"height": 719
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}"#;
|
||||||
|
let message = from_str::<Message>(json);
|
||||||
|
assert!(message.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue