mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-10 20:12:25 +01:00
Add some tests
This commit is contained in:
parent
b3c0d00b7d
commit
d91863e1c3
3 changed files with 78 additions and 0 deletions
|
@ -51,3 +51,32 @@ impl Deref for Me {
|
|||
&self.user
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::types::{Me, User, UserId};
|
||||
|
||||
#[test]
|
||||
fn convenience_methods_work() {
|
||||
let me = Me {
|
||||
user: User {
|
||||
id: UserId(42),
|
||||
is_bot: true,
|
||||
first_name: "First".to_owned(),
|
||||
last_name: None,
|
||||
username: Some("SomethingSomethingBot".to_owned()),
|
||||
language_code: None,
|
||||
},
|
||||
can_join_groups: false,
|
||||
can_read_all_group_messages: false,
|
||||
supports_inline_queries: false,
|
||||
};
|
||||
|
||||
assert_eq!(me.username(), "SomethingSomethingBot");
|
||||
assert_eq!(me.mention(), "@SomethingSomethingBot");
|
||||
assert_eq!(
|
||||
me.tme_url(),
|
||||
"https://t.me/SomethingSomethingBot".parse().unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,4 +141,46 @@ mod tests {
|
|||
let actual = serde_json::from_str::<User>(json).unwrap();
|
||||
assert_eq!(actual, expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convenience_methods_work() {
|
||||
let user_a = User {
|
||||
id: UserId(43),
|
||||
is_bot: false,
|
||||
first_name: "First".to_owned(),
|
||||
last_name: Some("Last".to_owned()),
|
||||
username: Some("aaaaaaaaaaaaaaaa".to_owned()),
|
||||
language_code: None,
|
||||
};
|
||||
|
||||
let user_b = User {
|
||||
id: UserId(44),
|
||||
is_bot: false,
|
||||
first_name: ".".to_owned(),
|
||||
last_name: None,
|
||||
username: None,
|
||||
language_code: None,
|
||||
};
|
||||
|
||||
assert_eq!(user_a.full_name(), "First Last");
|
||||
assert_eq!(user_b.full_name(), ".");
|
||||
|
||||
assert_eq!(user_a.mention(), Some("@aaaaaaaaaaaaaaaa".to_owned()));
|
||||
assert_eq!(user_b.mention(), None);
|
||||
|
||||
assert_eq!(
|
||||
user_a.tme_url(),
|
||||
Some("https://t.me/aaaaaaaaaaaaaaaa".parse().unwrap())
|
||||
);
|
||||
assert_eq!(user_b.tme_url(), None);
|
||||
|
||||
assert_eq!(
|
||||
user_a.preferably_tme_url(),
|
||||
"https://t.me/aaaaaaaaaaaaaaaa".parse().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
user_b.preferably_tme_url(),
|
||||
"tg://user/?id=44".parse().unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,4 +70,11 @@ mod tests {
|
|||
assert_eq!(serde_json::to_string(&user_id).unwrap(), json);
|
||||
assert_eq!(user_id, serde_json::from_str(json).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_works() {
|
||||
let id = UserId(17);
|
||||
|
||||
assert_eq!(id.url(), "tg://user/?id=17".parse().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue