twilight_model/guild/
preview.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use crate::{
    channel::message::Sticker,
    guild::Emoji,
    id::{marker::GuildMarker, Id},
    util::image_hash::ImageHash,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct GuildPreview {
    pub approximate_member_count: u64,
    pub approximate_presence_count: u64,
    pub description: Option<String>,
    pub discovery_splash: Option<ImageHash>,
    pub emojis: Vec<Emoji>,
    pub features: Vec<String>,
    pub id: Id<GuildMarker>,
    pub name: String,
    pub icon: Option<ImageHash>,
    pub splash: Option<ImageHash>,
    /// Guild's custom stickers.
    pub stickers: Vec<Sticker>,
}

#[cfg(test)]
mod tests {
    use super::{Emoji, GuildPreview};
    use crate::{id::Id, test::image_hash};
    use serde_test::Token;

    #[test]
    fn guild_preview() {
        let value = GuildPreview {
            approximate_member_count: 1_000,
            approximate_presence_count: 500,
            description: Some("guild description".to_owned()),
            discovery_splash: Some(image_hash::SPLASH),
            emojis: vec![Emoji {
                animated: false,
                available: true,
                id: Id::new(2),
                managed: false,
                name: "test".to_owned(),
                require_colons: true,
                roles: Vec::new(),
                user: None,
            }],
            features: vec!["a feature".to_owned()],
            id: Id::new(1),
            name: "guild name".to_owned(),
            icon: Some(image_hash::ICON),
            splash: Some(image_hash::SPLASH),
            stickers: Vec::new(),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "GuildPreview",
                    len: 11,
                },
                Token::Str("approximate_member_count"),
                Token::U64(1_000),
                Token::Str("approximate_presence_count"),
                Token::U64(500),
                Token::Str("description"),
                Token::Some,
                Token::Str("guild description"),
                Token::Str("discovery_splash"),
                Token::Some,
                Token::Str(image_hash::SPLASH_INPUT),
                Token::Str("emojis"),
                Token::Seq { len: Some(1) },
                Token::Struct {
                    name: "Emoji",
                    len: 6,
                },
                Token::Str("animated"),
                Token::Bool(false),
                Token::Str("available"),
                Token::Bool(true),
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("2"),
                Token::Str("managed"),
                Token::Bool(false),
                Token::Str("name"),
                Token::Str("test"),
                Token::Str("require_colons"),
                Token::Bool(true),
                Token::StructEnd,
                Token::SeqEnd,
                Token::Str("features"),
                Token::Seq { len: Some(1) },
                Token::Str("a feature"),
                Token::SeqEnd,
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("1"),
                Token::Str("name"),
                Token::Str("guild name"),
                Token::Str("icon"),
                Token::Some,
                Token::Str(image_hash::ICON_INPUT),
                Token::Str("splash"),
                Token::Some,
                Token::Str(image_hash::SPLASH_INPUT),
                Token::Str("stickers"),
                Token::Seq { len: Some(0) },
                Token::SeqEnd,
                Token::StructEnd,
            ],
        );
    }
}