File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed
ui-react/apps/admin/src/pages Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import PageHeader from "../components/common/PageHeader";
44import Drawer from "../components/common/Drawer" ;
55import { AxiosError } from "axios" ;
66import { LABEL , INPUT } from "../utils/styles" ;
7+ import { validateRecoveryEmail } from "./profile/validate" ;
78import {
89 UserIcon ,
910 PencilSquareIcon ,
@@ -41,13 +42,6 @@ function validateEmail(v: string): string | null {
4142 return null ;
4243}
4344
44- function validateRecoveryEmail ( recoveryEmail : string , primaryEmail : string ) : string | null {
45- if ( ! recoveryEmail ) return null ;
46- if ( ! / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( recoveryEmail ) ) return "Invalid email format" ;
47- if ( recoveryEmail . toLowerCase ( ) === primaryEmail . toLowerCase ( ) ) return "Must be different from your email" ;
48- return null ;
49- }
50-
5145function validatePassword ( v : string ) : string | null {
5246 if ( v . length < 5 ) return "Password must be at least 5 characters" ;
5347 if ( v . length > 32 ) return "Password must be at most 32 characters" ;
Original file line number Diff line number Diff line change 1+ import { describe , it , expect } from "vitest" ;
2+ import { validateRecoveryEmail } from "../validate" ;
3+
4+ describe ( "validateRecoveryEmail" , ( ) => {
5+ it ( "returns null when recovery email is empty" , ( ) => {
6+ expect ( validateRecoveryEmail ( "" , "user@example.com" ) ) . toBeNull ( ) ;
7+ } ) ;
8+
9+ it ( "rejects invalid email format" , ( ) => {
10+ expect ( validateRecoveryEmail ( "not-an-email" , "user@example.com" ) ) . toBe ( "Invalid email format" ) ;
11+ } ) ;
12+
13+ it ( "rejects when emails match exactly" , ( ) => {
14+ expect ( validateRecoveryEmail ( "user@example.com" , "user@example.com" ) ) . toBe ( "Must be different from your email" ) ;
15+ } ) ;
16+
17+ it ( "rejects when emails match case-insensitively" , ( ) => {
18+ expect ( validateRecoveryEmail ( "User@Example.COM" , "user@example.com" ) ) . toBe ( "Must be different from your email" ) ;
19+ } ) ;
20+
21+ it ( "rejects when primary email has mixed case" , ( ) => {
22+ expect ( validateRecoveryEmail ( "user@example.com" , "User@Example.COM" ) ) . toBe ( "Must be different from your email" ) ;
23+ } ) ;
24+
25+ it ( "returns null for a valid different email" , ( ) => {
26+ expect ( validateRecoveryEmail ( "other@example.com" , "user@example.com" ) ) . toBeNull ( ) ;
27+ } ) ;
28+ } ) ;
Original file line number Diff line number Diff line change 1+ export function validateRecoveryEmail ( recoveryEmail : string , primaryEmail : string ) : string | null {
2+ if ( ! recoveryEmail ) return null ;
3+ if ( ! / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( recoveryEmail ) ) return "Invalid email format" ;
4+ if ( recoveryEmail . toLowerCase ( ) === primaryEmail . toLowerCase ( ) ) return "Must be different from your email" ;
5+ return null ;
6+ }
You can’t perform that action at this time.
0 commit comments