diff --git a/src/model/user.rs b/src/model/user.rs index 9883bd1d893..af026eaecc8 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -37,7 +37,7 @@ impl CurrentUser { /// Returns the formatted URL of the user's icon, if one exists. pub fn avatar_url(&self) -> Option { self.avatar.as_ref().map(|av| - format!(cdn!("/avatars/{}/{}.jpg"), self.id, av)) + format!(cdn!("/avatars/{}/{}.jpg"), self.id.0, av)) } /// Edits the current user's profile settings. @@ -101,7 +101,7 @@ impl User { /// Returns the formatted URL of the user's icon, if one exists. pub fn avatar_url(&self) -> Option { self.avatar.as_ref().map(|av| - format!(cdn!("/avatars/{}/{}.jpg"), self.id, av)) + format!(cdn!("/avatars/{}/{}.jpg"), self.id.0, av)) } /// Gets user as `Member` of a guild. diff --git a/tests/test_formatters.rs b/tests/test_formatters.rs new file mode 100644 index 00000000000..922fb419033 --- /dev/null +++ b/tests/test_formatters.rs @@ -0,0 +1,12 @@ +extern crate serenity; + +use serenity::model::*; + +#[test] +fn test_formatters() { + assert_eq!(format!("{}", ChannelId(1)), "<#1>"); + assert_eq!(format!("{}", EmojiId(2)), "2"); + assert_eq!(format!("{}", GuildId(3)), "3"); + assert_eq!(format!("{}", RoleId(4)), "<@&4>"); + assert_eq!(format!("{}", UserId(5)), "<@5>"); +} diff --git a/tests/test_user.rs b/tests/test_user.rs new file mode 100644 index 00000000000..b4509f3cbcb --- /dev/null +++ b/tests/test_user.rs @@ -0,0 +1,24 @@ +extern crate serenity; + +use serenity::model::{User, UserId}; + +fn gen() -> User { + User { + id: UserId(210), + avatar: Some("abc".to_owned()), + bot: true, + discriminator: "1432".to_owned(), + name: "test".to_owned(), + } +} + +#[test] +fn test_core() { + let mut user = gen(); + + assert!(user.avatar_url().unwrap().ends_with("/avatars/210/abc.jpg")); + + user.avatar = None; + + assert!(user.avatar_url().is_none()); +}