mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
1. Box<Chat> -> Chat; 2. assert_eq!( //much code//, //same// ) -> expected & actual; 3. User { user: User } -> User(User)
This commit is contained in:
parent
620ffe5580
commit
0d6bb9840b
2 changed files with 68 additions and 50 deletions
|
@ -86,25 +86,24 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn channel_de() {
|
||||
assert_eq!(
|
||||
Chat {
|
||||
let expected = Chat {
|
||||
id: -1,
|
||||
kind: ChatKind::NonPrivate {
|
||||
title: None,
|
||||
kind: NonPrivateChatKind::Channel {
|
||||
username: Some("channelname".into())
|
||||
username: Some("channelname".into()),
|
||||
},
|
||||
description: None,
|
||||
invite_link: None,
|
||||
pinned_message: None
|
||||
pinned_message: None,
|
||||
},
|
||||
photo: None,
|
||||
},
|
||||
from_str(
|
||||
r#"{"chat_id":-1,"type":"channel","username":"channelname"}"#
|
||||
};
|
||||
let actual = from_str(
|
||||
r#"{"chat_id":-1,"type":"channel","username":"channelname"}"#,
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
.unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -129,22 +128,4 @@ mod tests {
|
|||
fn private_chat_de_wrong_type_field() {
|
||||
assert!(from_str::<Chat>(r#"{"chat_id":0,"type":"WRONG"}"#).is_err());
|
||||
}
|
||||
|
||||
/*#[test]
|
||||
fn private_chat_ser() {
|
||||
assert_eq!(
|
||||
to_string(&Chat {
|
||||
id: 0,
|
||||
type_: ChatKind::Private {
|
||||
type_: (),
|
||||
username: None,
|
||||
first_name: None,
|
||||
last_name: None
|
||||
},
|
||||
photo: None
|
||||
})
|
||||
.unwrap(),
|
||||
r#"{"chat_id":0,"type":"private"}"#.to_owned()
|
||||
);
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ pub struct Message {
|
|||
#[serde(rename = "message_id")]
|
||||
pub id: i64,
|
||||
pub date: i32,
|
||||
pub chat: Box<Chat>,
|
||||
pub chat: Chat,
|
||||
#[serde(flatten)]
|
||||
pub message_kind: MessageKind,
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ pub enum ForwardKind {
|
|||
#[serde(rename = "forward_date")]
|
||||
date: i32,
|
||||
#[serde(rename = "forward_from_chat")]
|
||||
chat: Box<Chat>,
|
||||
chat: Chat,
|
||||
#[serde(rename = "forward_from_message_id")]
|
||||
message_id: i64,
|
||||
#[serde(rename = "forward_signature")]
|
||||
|
@ -95,16 +95,11 @@ pub enum ForwardKind {
|
|||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
pub enum ForwardedFrom {
|
||||
User {
|
||||
#[serde(rename = "forward_from")]
|
||||
user: User,
|
||||
},
|
||||
SenderName {
|
||||
User(User),
|
||||
#[serde(rename = "forward_sender_name")]
|
||||
sender_name: String,
|
||||
},
|
||||
SenderName(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
|
||||
|
@ -167,11 +162,11 @@ mod tests {
|
|||
use serde_json::from_str;
|
||||
|
||||
#[test]
|
||||
fn incoming_origin_de() {
|
||||
fn origin_de() {
|
||||
let expected = Message {
|
||||
id: 0,
|
||||
date: 0,
|
||||
chat: Box::new(Chat {
|
||||
chat: Chat {
|
||||
id: 0,
|
||||
kind: ChatKind::Private {
|
||||
type_: (),
|
||||
|
@ -180,7 +175,7 @@ mod tests {
|
|||
last_name: None,
|
||||
},
|
||||
photo: None,
|
||||
}),
|
||||
},
|
||||
message_kind: MessageKind::IncomingMessage {
|
||||
forward_kind: ForwardKind::Origin {
|
||||
reply_to_message: None,
|
||||
|
@ -193,7 +188,49 @@ mod tests {
|
|||
reply_markup: None,
|
||||
},
|
||||
};
|
||||
let actual = from_str(r#"{"message_id":0,"date":0,"chat":{"chat_id":0,"type":"private"},"text":"Hello","entities":[]}"#).unwrap();
|
||||
let actual = from_str::<Message>(r#"{"message_id":0,"date":0,"chat":{"chat_id":0,"type":"private"},"text":"Hello","entities":[]}"#).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forward_de() {
|
||||
let expected = Message {
|
||||
id: 1,
|
||||
date: 1,
|
||||
chat: Chat {
|
||||
id: 1,
|
||||
kind: ChatKind::Private {
|
||||
type_: (),
|
||||
username: None,
|
||||
first_name: None,
|
||||
last_name: None,
|
||||
},
|
||||
photo: None,
|
||||
},
|
||||
message_kind: MessageKind::IncomingMessage {
|
||||
forward_kind: ForwardKind::NonChannelForward {
|
||||
date: 1,
|
||||
from: ForwardedFrom::User(User {
|
||||
id: 123,
|
||||
is_bot: false,
|
||||
first_name: "Name".to_string(),
|
||||
last_name: None,
|
||||
username: None,
|
||||
language_code: None,
|
||||
}),
|
||||
},
|
||||
edit_date: None,
|
||||
media_kind: MediaKind::Text {
|
||||
text: "Message".into(),
|
||||
entities: vec![],
|
||||
},
|
||||
reply_markup: None,
|
||||
},
|
||||
};
|
||||
let actual = from_str::<Message>(
|
||||
r#"{"message_id":1,"date":1,"chat":{"chat_id":1,"type":"private"},"forward_date":1,"forward_from":{"id":123,"is_bot":false,"first_name":"Name"},"text":"Message","entities":[]}"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue