twilight_model/application/monetization/
sku.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
use serde::{Deserialize, Serialize};

use crate::id::{
    marker::{ApplicationMarker, SkuMarker},
    Id,
};

use super::{SkuFlags, SkuType};

/// SKUs (stock-keeping units) in Discord represent premium offerings that can be made available to your application's users or guilds.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Sku {
    /// ID of the parent application.
    application_id: Id<ApplicationMarker>,
    /// Flags for the SKU.
    flags: SkuFlags,
    /// ID of SKU.
    id: Id<SkuMarker>,
    /// Type of SKU.
    #[serde(rename = "type")]
    kind: SkuType,
    /// Customer-facing name of your premium offering.
    name: String,
    /// System-generated URL slug based on the SKU's name.
    slug: String,
}

#[cfg(test)]
mod tests {
    use serde_test::Token;

    use crate::{
        application::monetization::{SkuFlags, SkuType},
        id::Id,
    };

    use super::Sku;

    #[test]
    fn sku() {
        let value = Sku {
            application_id: Id::new(1),
            flags: SkuFlags::GUILD_SUBSCRIPTION,
            id: Id::new(2),
            kind: SkuType::Subscription,
            name: "a name".to_owned(),
            slug: "a-slug".to_owned(),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "Sku",
                    len: 6,
                },
                Token::Str("application_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("1"),
                Token::Str("flags"),
                Token::U64(1 << 7),
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("2"),
                Token::Str("type"),
                Token::U8(5),
                Token::Str("name"),
                Token::Str("a name"),
                Token::Str("slug"),
                Token::Str("a-slug"),
                Token::StructEnd,
            ],
        );
    }
}