twilight_model/guild/onboarding/
prompt.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
use crate::id::{marker::OnboardingPromptMarker, Id};
use serde::{Deserialize, Serialize};

use super::{OnboardingPromptOption, OnboardingPromptType};

/// A prompt in the onboarding flow.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct OnboardingPrompt {
    /// ID of the prompt.
    pub id: Id<OnboardingPromptMarker>,
    /// Whether this prompt is in the onboarding flow.
    pub in_onboarding: bool,
    /// [`OnboardingPromptType`] of the prompt.
    #[serde(rename = "type")]
    pub kind: OnboardingPromptType,
    /// Array of [`OnboardingPromptOption`]s available to the prompt.
    pub options: Vec<OnboardingPromptOption>,
    /// Whether this prompt is required in the onboarding flow.
    pub required: bool,
    /// Whether this prompt allows selecting only one option.
    pub single_select: bool,
    /// Title of the prompt.
    pub title: String,
}

#[cfg(test)]
mod tests {
    use super::OnboardingPrompt;
    use crate::{guild::onboarding::OnboardingPromptType, id::Id};
    use serde_test::Token;

    #[test]
    fn onboarding_prompt() {
        let prompt = OnboardingPrompt {
            id: Id::new(123_456_789),
            in_onboarding: true,
            kind: OnboardingPromptType::MultipleChoice,
            options: Vec::new(),
            required: true,
            single_select: true,
            title: String::from("a prompt"),
        };

        serde_test::assert_tokens(
            &prompt,
            &[
                Token::Struct {
                    name: "OnboardingPrompt",
                    len: 7,
                },
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("123456789"),
                Token::Str("in_onboarding"),
                Token::Bool(true),
                Token::Str("type"),
                Token::U8(0),
                Token::Str("options"),
                Token::Seq { len: Some(0) },
                Token::SeqEnd,
                Token::Str("required"),
                Token::Bool(true),
                Token::Str("single_select"),
                Token::Bool(true),
                Token::Str("title"),
                Token::Str("a prompt"),
                Token::StructEnd,
            ],
        );
    }
}