twilight_model/user/
connection.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
use crate::{guild::GuildIntegration, user::ConnectionVisibility};
use serde::{Deserialize, Serialize};

#[allow(clippy::struct_excessive_bools)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Connection {
    pub friend_sync: bool,
    pub id: String,
    #[serde(default)]
    pub integrations: Vec<GuildIntegration>,
    #[serde(rename = "type")]
    pub kind: String,
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub revoked: Option<bool>,
    pub show_activity: bool,
    /// Whether this connection has a corresponding third party OAuth2 token.
    pub two_way_link: bool,
    pub verified: bool,
    pub visibility: ConnectionVisibility,
}

#[cfg(test)]
mod tests {
    use super::{Connection, ConnectionVisibility};
    use serde_test::Token;

    #[test]
    fn connection() {
        let value = Connection {
            friend_sync: true,
            id: "connection id".to_owned(),
            integrations: Vec::new(),
            kind: "integration type".to_owned(),
            name: "integration name".to_owned(),
            revoked: Some(false),
            show_activity: true,
            verified: true,
            two_way_link: false,
            visibility: ConnectionVisibility::Everyone,
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "Connection",
                    len: 10,
                },
                Token::Str("friend_sync"),
                Token::Bool(true),
                Token::Str("id"),
                Token::Str("connection id"),
                Token::Str("integrations"),
                Token::Seq { len: Some(0) },
                Token::SeqEnd,
                Token::Str("type"),
                Token::Str("integration type"),
                Token::Str("name"),
                Token::Str("integration name"),
                Token::Str("revoked"),
                Token::Some,
                Token::Bool(false),
                Token::Str("show_activity"),
                Token::Bool(true),
                Token::Str("two_way_link"),
                Token::Bool(false),
                Token::Str("verified"),
                Token::Bool(true),
                Token::Str("visibility"),
                Token::U8(1),
                Token::StructEnd,
            ],
        );
    }
}