aboutsummaryrefslogtreecommitdiff
path: root/src/builder/create_embed.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-08-01 08:08:23 -0700
committerZeyla Hellyer <[email protected]>2018-08-01 08:10:05 -0700
commit3fed313193356c6784a33b79d1c2f583ea3944f9 (patch)
tree875b4bab989fc573850d30317a1797bca5027e9f /src/builder/create_embed.rs
parentReword the inner doc comment in `complex_bucket` (diff)
downloadserenity-3fed313193356c6784a33b79d1c2f583ea3944f9.tar.xz
serenity-3fed313193356c6784a33b79d1c2f583ea3944f9.zip
Move unit tests into source
Move the unit tests into the relevant source files. There's no need for them to be seprate, especially when the `tests` directory is meant to be for integration tests. The deserialization tests that include JSON files are still in the `tests` dir, along with the public prelude re-export tests.
Diffstat (limited to 'src/builder/create_embed.rs')
-rw-r--r--src/builder/create_embed.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs
index 7604386..35172e1 100644
--- a/src/builder/create_embed.rs
+++ b/src/builder/create_embed.rs
@@ -515,3 +515,92 @@ impl<'a, Tz: TimeZone> From<&'a DateTime<Tz>> for Timestamp
}
}
}
+
+#[cfg(test)]
+mod test {
+ use model::channel::{Embed, EmbedField, EmbedFooter, EmbedImage, EmbedVideo};
+ use serde_json::Value;
+ use super::CreateEmbed;
+ use utils::{self, Colour};
+
+ #[test]
+ fn test_from_embed() {
+ let embed = Embed {
+ author: None,
+ colour: Colour::new(0xFF0011),
+ description: Some("This is a test description".to_string()),
+ fields: vec![
+ EmbedField {
+ inline: false,
+ name: "a".to_string(),
+ value: "b".to_string(),
+ },
+ EmbedField {
+ inline: true,
+ name: "c".to_string(),
+ value: "z".to_string(),
+ },
+ ],
+ footer: Some(EmbedFooter {
+ icon_url: Some("https://i.imgur.com/XfWpfCV.gif".to_string()),
+ proxy_icon_url: None,
+ text: "This is a hakase footer".to_string(),
+ }),
+ image: Some(EmbedImage {
+ height: 213,
+ proxy_url: "a".to_string(),
+ url: "https://i.imgur.com/XfWpfCV.gif".to_string(),
+ width: 224,
+ }),
+ kind: "rich".to_string(),
+ provider: None,
+ thumbnail: None,
+ timestamp: None,
+ title: Some("hakase".to_string()),
+ url: Some("https://i.imgur.com/XfWpfCV.gif".to_string()),
+ video: Some(EmbedVideo {
+ height: 213,
+ url: "https://i.imgur.com/XfWpfCV.mp4".to_string(),
+ width: 224,
+ }),
+ };
+
+ let builder = CreateEmbed::from(embed)
+ .colour(0xFF0011)
+ .description("This is a hakase description")
+ .image("https://i.imgur.com/XfWpfCV.gif")
+ .title("still a hakase")
+ .url("https://i.imgur.com/XfWpfCV.gif");
+
+ let built = Value::Object(utils::vecmap_to_json_map(builder.0));
+
+ let obj = json!({
+ "color": 0xFF0011,
+ "description": "This is a hakase description",
+ "title": "still a hakase",
+ "type": "rich",
+ "url": "https://i.imgur.com/XfWpfCV.gif",
+ "fields": [
+ {
+ "inline": false,
+ "name": "a",
+ "value": "b",
+ },
+ {
+ "inline": true,
+ "name": "c",
+ "value": "z",
+ },
+ ],
+ "image": {
+ "url": "https://i.imgur.com/XfWpfCV.gif",
+ },
+ "footer": {
+ "text": "This is a hakase footer",
+ "icon_url": "https://i.imgur.com/XfWpfCV.gif",
+ }
+ });
+
+ assert_eq!(built, obj);
+ }
+}