clerk-rs 0.4.2

The official community Rust SDK for the Clerk API
Documentation
/*
 * Clerk Backend API
 *
 * The Clerk REST Backend API, meant to be accessed by backend servers. Please see https://clerk.com/docs for more information.
 *
 * The version of the OpenAPI document: v1
 * Contact: support@clerk.com
 * Generated by: https://openapi-generator.tech
 */

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EmailAddressVerification {
	#[serde(rename = "status")]
	pub status: Status,
	#[serde(rename = "strategy")]
	pub strategy: Strategy,
	#[serde(rename = "attempts")]
	pub attempts: Option<i64>,
	#[serde(rename = "expire_at")]
	pub expire_at: Option<i64>,
}

impl EmailAddressVerification {
	pub fn new(status: Status, strategy: Strategy, attempts: Option<i64>, expire_at: Option<i64>) -> EmailAddressVerification {
		EmailAddressVerification {
			status,
			strategy,
			attempts,
			expire_at,
		}
	}
}

///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
	#[serde(rename = "verified")]
	Verified,
	#[serde(rename = "unverified")]
	Unverified,
	#[serde(rename = "expired")]
	Expired,
	#[serde(rename = "failed")]
	Failed,
}

impl Default for Status {
	fn default() -> Status {
		Self::Verified
	}
}
///
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Strategy {
	#[serde(rename = "admin")]
	Admin,
	#[serde(rename = "phone_code")]
	PhoneCode,
	#[serde(rename = "email_code")]
	EmailCode,
	#[serde(rename = "from_oauth_google")]
	FromOAuthGoogle,
	#[serde(rename = "from_oauth_twitter")]
	FromOAuthTwitter,
	#[serde(other)]
	Other,
}

impl Default for Strategy {
	fn default() -> Strategy {
		Self::Admin
	}
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn test_deserialize_email_address_verification() {
		// Define a JSON string that represents an EmailAddressVerification object
		let json = r#"
            {
                "status": "verified",
                "strategy": "admin",
                "attempts": 0,
                "expire_at": 0
            }
        "#;

		// Deserialize the JSON string
		let deserialized: EmailAddressVerification = serde_json::from_str(json).expect("Failed to deserialize");

		// Define the expected EmailAddressVerification object
		let expected = EmailAddressVerification {
			status: Status::Verified,
			strategy: Strategy::Admin,
			attempts: Some(0),
			expire_at: Some(0),
		};

		// Assert that the deserialized object matches the expected object
		assert_eq!(deserialized, expected);
	}

	#[test]
	fn test_deserialize_email_address_verification_other_strategy() {
		// Define a JSON string that represents an EmailAddressVerification object
		let json = r#"
            {
                "status": "verified",
                "strategy": "foobar",
                "attempts": 0,
                "expire_at": 0
            }
        "#;

		// Deserialize the JSON string
		let deserialized: EmailAddressVerification = serde_json::from_str(json).expect("Failed to deserialize");

		// Define the expected EmailAddressVerification object
		let expected = EmailAddressVerification {
			status: Status::Verified,
			strategy: Strategy::Other,
			attempts: Some(0),
			expire_at: Some(0),
		};

		// Assert that the deserialized object matches the expected object
		assert_eq!(deserialized, expected);
	}
}