From b8038f52bfb2654ebd2d93abaa922a27588bdd91 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 16 Apr 2023 12:30:30 +0200 Subject: [PATCH] write tests to check username validation --- src/api/schemas.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/api/schemas.rs b/src/api/schemas.rs index eedd39c..6eaf96e 100644 --- a/src/api/schemas.rs +++ b/src/api/schemas.rs @@ -160,4 +160,39 @@ mod schemas_tests { }) ); } + + #[test] + fn username_too_short() { + assert_eq!( + RegisterSchema::new( + "T".to_string(), + None, + true, + None, + None, + None, + None, + None, + None, + None, + ), + Err(RegisterSchemaError { + message: "Username must be between 2 and 32 characters".to_string() + }) + ); + } + + #[test] + fn username_too_long() { + let mut long_un = String::new(); + for _ in 0..33 { + long_un = long_un + "a"; + } + assert_eq!( + RegisterSchema::new(long_un, None, true, None, None, None, None, None, None, None,), + Err(RegisterSchemaError { + message: "Username must be between 2 and 32 characters".to_string() + }) + ); + } }