Made test pass

This commit is contained in:
bitfl0wer 2023-04-23 13:45:52 +02:00
parent d1d8b6f237
commit 82bfec0612
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
2 changed files with 75 additions and 62 deletions

View File

@ -58,7 +58,7 @@ pub mod register {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::api::schemas::schemas::RegisterSchema; use crate::api::schemas::schemas::{AuthEmail, AuthPassword, AuthUsername, RegisterSchema};
use crate::errors::InstanceServerError; use crate::errors::InstanceServerError;
use crate::instance::Instance; use crate::instance::Instance;
use crate::limit::LimitedRequester; use crate::limit::LimitedRequester;
@ -75,10 +75,10 @@ mod test {
.await .await
.unwrap(); .unwrap();
let reg = RegisterSchema::new( let reg = RegisterSchema::new(
"aaa".to_string(), AuthUsername::new("hiiii".to_string()).unwrap(),
None, None,
true, true,
Some("me@mail.xy".to_string()), Some(AuthEmail::new("me@mail.xy".to_string()).unwrap()),
None, None,
None, None,
None, None,
@ -108,10 +108,10 @@ mod test {
.await .await
.unwrap(); .unwrap();
let reg = RegisterSchema::new( let reg = RegisterSchema::new(
"Hiiii".to_string(), AuthUsername::new("Hiiii".to_string()).unwrap(),
Some("mysupersecurepass123!".to_string()), Some(AuthPassword::new("mysupersecurepass123!".to_string()).unwrap()),
true, true,
Some("flori@mail.xyz".to_string()), Some(AuthEmail::new("flori@aaaa.xyz".to_string()).unwrap()),
None, None,
None, None,
Some("2000-01-01".to_string()), Some("2000-01-01".to_string()),

View File

@ -1,14 +1,14 @@
pub mod schemas { pub mod schemas {
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt; use std::{collections::HashMap, fmt};
use crate::errors::FieldFormatError; use crate::errors::FieldFormatError;
/** /**
A struct that represents a well-formed email address. A struct that represents a well-formed email address.
*/ */
#[derive(Clone)] #[derive(Clone, PartialEq, Eq, Debug)]
pub struct AuthEmail { pub struct AuthEmail {
pub email: String, pub email: String,
} }
@ -40,7 +40,7 @@ pub mod schemas {
You will receive a [`FieldFormatError`], if: You will receive a [`FieldFormatError`], if:
- The username is not between 2 and 32 characters. - The username is not between 2 and 32 characters.
*/ */
#[derive(Clone)] #[derive(Clone, PartialEq, Eq, Debug)]
pub struct AuthUsername { pub struct AuthUsername {
pub username: String, pub username: String,
} }
@ -71,7 +71,7 @@ pub mod schemas {
You will receive a [`FieldFormatError`], if: You will receive a [`FieldFormatError`], if:
- The password is not between 1 and 72 characters. - The password is not between 1 and 72 characters.
*/ */
#[derive(Clone)] #[derive(Clone, PartialEq, Eq, Debug)]
pub struct AuthPassword { pub struct AuthPassword {
pub password: String, 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<String>,
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<i32>,
gateway_connected: bool,
gif_auto_play: bool,
guild_folders: Vec<GuildFolder>,
guild_positions: Vec<i64>,
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<i64>,
show_current_game: bool,
status: String,
stream_notifications_enabled: bool,
theme: String,
timezone_offset: i32,
view_nsfw_guilds: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FriendSourceFlags {
all: Option<bool>,
mutual_friends: Option<bool>,
mutual_guilds: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GuildFolder {
id: String,
guild_ids: Vec<i64>,
name: String,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct TotpSchema { pub struct TotpSchema {
@ -335,18 +392,7 @@ mod schemas_tests {
#[test] #[test]
fn password_too_short() { fn password_too_short() {
assert_eq!( assert_eq!(
RegisterSchema::new( AuthPassword::new("".to_string()),
"Test".to_string(),
Some("".to_string()),
true,
None,
None,
None,
None,
None,
None,
None,
),
Err(FieldFormatError::PasswordError) Err(FieldFormatError::PasswordError)
); );
} }
@ -358,18 +404,7 @@ mod schemas_tests {
long_pw = long_pw + "a"; long_pw = long_pw + "a";
} }
assert_eq!( assert_eq!(
RegisterSchema::new( AuthPassword::new(long_pw),
"Test".to_string(),
Some(long_pw),
true,
None,
None,
None,
None,
None,
None,
None,
),
Err(FieldFormatError::PasswordError) Err(FieldFormatError::PasswordError)
); );
} }
@ -377,18 +412,7 @@ mod schemas_tests {
#[test] #[test]
fn username_too_short() { fn username_too_short() {
assert_eq!( assert_eq!(
RegisterSchema::new( AuthUsername::new("T".to_string()),
"T".to_string(),
None,
true,
None,
None,
None,
None,
None,
None,
None,
),
Err(FieldFormatError::UsernameError) Err(FieldFormatError::UsernameError)
); );
} }
@ -400,7 +424,7 @@ mod schemas_tests {
long_un = long_un + "a"; long_un = long_un + "a";
} }
assert_eq!( assert_eq!(
RegisterSchema::new(long_un, None, true, None, None, None, None, None, None, None,), AuthUsername::new(long_un),
Err(FieldFormatError::UsernameError) Err(FieldFormatError::UsernameError)
); );
} }
@ -409,7 +433,7 @@ mod schemas_tests {
fn consent_false() { fn consent_false() {
assert_eq!( assert_eq!(
RegisterSchema::new( RegisterSchema::new(
"Test".to_string(), AuthUsername::new("Test".to_string()).unwrap(),
None, None,
false, false,
None, None,
@ -427,18 +451,7 @@ mod schemas_tests {
#[test] #[test]
fn invalid_email() { fn invalid_email() {
assert_eq!( assert_eq!(
RegisterSchema::new( AuthEmail::new("p@p.p".to_string()),
"Test".to_string(),
None,
true,
Some("p@p.p".to_string()),
None,
None,
None,
None,
None,
None,
),
Err(FieldFormatError::EmailError) Err(FieldFormatError::EmailError)
) )
} }
@ -446,10 +459,10 @@ mod schemas_tests {
#[test] #[test]
fn valid_email() { fn valid_email() {
let reg = RegisterSchema::new( let reg = RegisterSchema::new(
"Test".to_string(), AuthUsername::new("Testy".to_string()).unwrap(),
None, None,
true, true,
Some("me@mail.xy".to_string()), Some(AuthEmail::new("me@mail.de".to_string()).unwrap()),
None, None,
None, None,
None, None,