From 8b40b4c3b2991497f40f09e44546ff2250690a26 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 23 Apr 2023 13:45:52 +0200 Subject: [PATCH] Made test pass --- src/api/auth/register.rs | 12 ++-- src/api/schemas.rs | 125 +++++++++++++++++++++------------------ 2 files changed, 75 insertions(+), 62 deletions(-) diff --git a/src/api/auth/register.rs b/src/api/auth/register.rs index de78b88..63c89b9 100644 --- a/src/api/auth/register.rs +++ b/src/api/auth/register.rs @@ -58,7 +58,7 @@ pub mod register { #[cfg(test)] mod test { - use crate::api::schemas::schemas::RegisterSchema; + use crate::api::schemas::schemas::{AuthEmail, AuthPassword, AuthUsername, RegisterSchema}; use crate::errors::InstanceServerError; use crate::instance::Instance; use crate::limit::LimitedRequester; @@ -75,10 +75,10 @@ mod test { .await .unwrap(); let reg = RegisterSchema::new( - "aaa".to_string(), + AuthUsername::new("hiiii".to_string()).unwrap(), None, true, - Some("me@mail.xy".to_string()), + Some(AuthEmail::new("me@mail.xy".to_string()).unwrap()), None, None, None, @@ -108,10 +108,10 @@ mod test { .await .unwrap(); let reg = RegisterSchema::new( - "Hiiii".to_string(), - Some("mysupersecurepass123!".to_string()), + AuthUsername::new("Hiiii".to_string()).unwrap(), + Some(AuthPassword::new("mysupersecurepass123!".to_string()).unwrap()), true, - Some("flori@mail.xyz".to_string()), + Some(AuthEmail::new("flori@aaaa.xyz".to_string()).unwrap()), None, None, Some("2000-01-01".to_string()), diff --git a/src/api/schemas.rs b/src/api/schemas.rs index b188e2c..4a68488 100644 --- a/src/api/schemas.rs +++ b/src/api/schemas.rs @@ -1,14 +1,14 @@ pub mod schemas { use regex::Regex; use serde::{Deserialize, Serialize}; - use std::fmt; + use std::{collections::HashMap, fmt}; use crate::errors::FieldFormatError; /** A struct that represents a well-formed email address. */ - #[derive(Clone)] + #[derive(Clone, PartialEq, Eq, Debug)] pub struct AuthEmail { pub email: String, } @@ -40,7 +40,7 @@ pub mod schemas { You will receive a [`FieldFormatError`], if: - The username is not between 2 and 32 characters. */ - #[derive(Clone)] + #[derive(Clone, PartialEq, Eq, Debug)] pub struct AuthUsername { pub username: String, } @@ -71,7 +71,7 @@ pub mod schemas { You will receive a [`FieldFormatError`], if: - The password is not between 1 and 72 characters. */ - #[derive(Clone)] + #[derive(Clone, PartialEq, Eq, Debug)] pub struct AuthPassword { pub password: String, } @@ -233,6 +233,63 @@ pub mod schemas { } } + #[derive(Debug, Serialize, Deserialize)] + pub struct LoginResult { + token: String, + settings: UserSettings, + } + + #[derive(Debug, Serialize, Deserialize)] + pub struct UserSettings { + afk_timeout: i32, + allow_accessibility_detection: bool, + animate_emoji: bool, + animate_stickers: i32, + contact_sync_enabled: bool, + convert_emoticons: bool, + custom_status: Option, + default_guilds_restricted: bool, + detect_platform_accounts: bool, + developer_mode: bool, + disable_games_tab: bool, + enable_tts_command: bool, + explicit_content_filter: i32, + friend_source_flags: FriendSourceFlags, + friend_discovery_flags: Option, + gateway_connected: bool, + gif_auto_play: bool, + guild_folders: Vec, + guild_positions: Vec, + inline_attachment_media: bool, + inline_embed_media: bool, + locale: String, + message_display_compact: bool, + native_phone_integration_enabled: bool, + render_embeds: bool, + render_reactions: bool, + restricted_guilds: Vec, + show_current_game: bool, + status: String, + stream_notifications_enabled: bool, + theme: String, + timezone_offset: i32, + view_nsfw_guilds: Option, + } + + #[derive(Debug, Serialize, Deserialize)] + pub struct FriendSourceFlags { + all: Option, + mutual_friends: Option, + mutual_guilds: Option, + } + + #[derive(Debug, Serialize, Deserialize)] + pub struct GuildFolder { + id: String, + guild_ids: Vec, + name: String, + } + #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub struct TotpSchema { @@ -335,18 +392,7 @@ mod schemas_tests { #[test] fn password_too_short() { assert_eq!( - RegisterSchema::new( - "Test".to_string(), - Some("".to_string()), - true, - None, - None, - None, - None, - None, - None, - None, - ), + AuthPassword::new("".to_string()), Err(FieldFormatError::PasswordError) ); } @@ -358,18 +404,7 @@ mod schemas_tests { long_pw = long_pw + "a"; } assert_eq!( - RegisterSchema::new( - "Test".to_string(), - Some(long_pw), - true, - None, - None, - None, - None, - None, - None, - None, - ), + AuthPassword::new(long_pw), Err(FieldFormatError::PasswordError) ); } @@ -377,18 +412,7 @@ mod schemas_tests { #[test] fn username_too_short() { assert_eq!( - RegisterSchema::new( - "T".to_string(), - None, - true, - None, - None, - None, - None, - None, - None, - None, - ), + AuthUsername::new("T".to_string()), Err(FieldFormatError::UsernameError) ); } @@ -400,7 +424,7 @@ mod schemas_tests { long_un = long_un + "a"; } assert_eq!( - RegisterSchema::new(long_un, None, true, None, None, None, None, None, None, None,), + AuthUsername::new(long_un), Err(FieldFormatError::UsernameError) ); } @@ -409,7 +433,7 @@ mod schemas_tests { fn consent_false() { assert_eq!( RegisterSchema::new( - "Test".to_string(), + AuthUsername::new("Test".to_string()).unwrap(), None, false, None, @@ -427,18 +451,7 @@ mod schemas_tests { #[test] fn invalid_email() { assert_eq!( - RegisterSchema::new( - "Test".to_string(), - None, - true, - Some("p@p.p".to_string()), - None, - None, - None, - None, - None, - None, - ), + AuthEmail::new("p@p.p".to_string()), Err(FieldFormatError::EmailError) ) } @@ -446,10 +459,10 @@ mod schemas_tests { #[test] fn valid_email() { let reg = RegisterSchema::new( - "Test".to_string(), + AuthUsername::new("Testy".to_string()).unwrap(), None, true, - Some("me@mail.xy".to_string()), + Some(AuthEmail::new("me@mail.de".to_string()).unwrap()), None, None, None,