clerk_rs/models/
email_address_verification.rs1#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
12pub struct EmailAddressVerification {
13 #[serde(rename = "status")]
14 pub status: Status,
15 #[serde(rename = "strategy")]
16 pub strategy: Strategy,
17 #[serde(rename = "attempts", deserialize_with = "Option::deserialize")]
18 pub attempts: Option<i64>,
19 #[serde(rename = "expire_at", deserialize_with = "Option::deserialize")]
20 pub expire_at: Option<i64>,
21}
22
23impl EmailAddressVerification {
24 pub fn new(status: Status, strategy: Strategy, attempts: Option<i64>, expire_at: Option<i64>) -> EmailAddressVerification {
25 EmailAddressVerification {
26 status,
27 strategy,
28 attempts,
29 expire_at,
30 }
31 }
32}
33
34#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
36pub enum Status {
37 #[serde(rename = "verified")]
38 Verified,
39 #[serde(rename = "expired")]
40 Expired,
41 #[serde(rename = "failed")]
42 Failed,
43}
44
45impl Default for Status {
46 fn default() -> Status {
47 Self::Verified
48 }
49}
50#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
52pub enum Strategy {
53 #[serde(rename = "admin")]
54 Admin,
55 #[serde(rename = "phone_code")]
56 PhoneCode,
57 #[serde(rename = "email_code")]
58 EmailCode,
59 #[serde(rename = "from_oauth_google")]
60 FromOAuthGoogle,
61 #[serde(rename = "from_oauth_twitter")]
62 FromOAuthTwitter,
63 #[serde(other)]
64 Other,
65}
66
67impl Default for Strategy {
68 fn default() -> Strategy {
69 Self::Admin
70 }
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_deserialize_email_address_verification() {
79 let json = r#"
81 {
82 "status": "verified",
83 "strategy": "admin",
84 "attempts": 0,
85 "expire_at": 0
86 }
87 "#;
88
89 let deserialized: EmailAddressVerification = serde_json::from_str(json).expect("Failed to deserialize");
91
92 let expected = EmailAddressVerification {
94 status: Status::Verified,
95 strategy: Strategy::Admin,
96 attempts: Some(0),
97 expire_at: Some(0),
98 };
99
100 assert_eq!(deserialized, expected);
102 }
103
104 #[test]
105 fn test_deserialize_email_address_verification_other_strategy() {
106 let json = r#"
108 {
109 "status": "verified",
110 "strategy": "foobar",
111 "attempts": 0,
112 "expire_at": 0
113 }
114 "#;
115
116 let deserialized: EmailAddressVerification = serde_json::from_str(json).expect("Failed to deserialize");
118
119 let expected = EmailAddressVerification {
121 status: Status::Verified,
122 strategy: Strategy::Other,
123 attempts: Some(0),
124 expire_at: Some(0),
125 };
126
127 assert_eq!(deserialized, expected);
129 }
130}