@@ -21,7 +21,7 @@ vi.mock('@/lib/core/utils/urls', () => ({
2121function setupAuthApiMocks (
2222 options : {
2323 operations ?: {
24- forgetPassword ?: { success ?: boolean ; error ?: string }
24+ requestPasswordReset ?: { success ?: boolean ; error ?: string }
2525 resetPassword ?: { success ?: boolean ; error ?: string }
2626 }
2727 } = { }
@@ -34,7 +34,11 @@ function setupAuthApiMocks(
3434
3535 const { operations = { } } = options
3636 const defaultOperations = {
37- forgetPassword : { success : true , error : 'Forget password error' , ...operations . forgetPassword } ,
37+ requestPasswordReset : {
38+ success : true ,
39+ error : 'Forget password error' ,
40+ ...operations . requestPasswordReset ,
41+ } ,
3842 resetPassword : { success : true , error : 'Reset password error' , ...operations . resetPassword } ,
3943 }
4044
@@ -50,7 +54,7 @@ function setupAuthApiMocks(
5054 vi . doMock ( '@/lib/auth' , ( ) => ( {
5155 auth : {
5256 api : {
53- forgetPassword : createAuthMethod ( defaultOperations . forgetPassword ) ,
57+ requestPasswordReset : createAuthMethod ( defaultOperations . requestPasswordReset ) ,
5458 resetPassword : createAuthMethod ( defaultOperations . resetPassword ) ,
5559 } ,
5660 } ,
@@ -69,7 +73,7 @@ describe('Forget Password API Route', () => {
6973 it ( 'should send password reset email successfully with same-origin redirectTo' , async ( ) => {
7074 setupAuthApiMocks ( {
7175 operations : {
72- forgetPassword : { success : true } ,
76+ requestPasswordReset : { success : true } ,
7377 } ,
7478 } )
7579
@@ -87,7 +91,7 @@ describe('Forget Password API Route', () => {
8791 expect ( data . success ) . toBe ( true )
8892
8993 const auth = await import ( '@/lib/auth' )
90- expect ( auth . auth . api . forgetPassword ) . toHaveBeenCalledWith ( {
94+ expect ( auth . auth . api . requestPasswordReset ) . toHaveBeenCalledWith ( {
9195 body : {
9296 email : 'test@example.com' ,
9397 redirectTo : 'https://app.example.com/reset' ,
@@ -99,7 +103,7 @@ describe('Forget Password API Route', () => {
99103 it ( 'should reject external redirectTo URL' , async ( ) => {
100104 setupAuthApiMocks ( {
101105 operations : {
102- forgetPassword : { success : true } ,
106+ requestPasswordReset : { success : true } ,
103107 } ,
104108 } )
105109
@@ -117,13 +121,13 @@ describe('Forget Password API Route', () => {
117121 expect ( data . message ) . toBe ( 'Redirect URL must be a valid same-origin URL' )
118122
119123 const auth = await import ( '@/lib/auth' )
120- expect ( auth . auth . api . forgetPassword ) . not . toHaveBeenCalled ( )
124+ expect ( auth . auth . api . requestPasswordReset ) . not . toHaveBeenCalled ( )
121125 } )
122126
123127 it ( 'should send password reset email without redirectTo' , async ( ) => {
124128 setupAuthApiMocks ( {
125129 operations : {
126- forgetPassword : { success : true } ,
130+ requestPasswordReset : { success : true } ,
127131 } ,
128132 } )
129133
@@ -140,7 +144,7 @@ describe('Forget Password API Route', () => {
140144 expect ( data . success ) . toBe ( true )
141145
142146 const auth = await import ( '@/lib/auth' )
143- expect ( auth . auth . api . forgetPassword ) . toHaveBeenCalledWith ( {
147+ expect ( auth . auth . api . requestPasswordReset ) . toHaveBeenCalledWith ( {
144148 body : {
145149 email : 'test@example.com' ,
146150 redirectTo : undefined ,
@@ -163,7 +167,7 @@ describe('Forget Password API Route', () => {
163167 expect ( data . message ) . toBe ( 'Email is required' )
164168
165169 const auth = await import ( '@/lib/auth' )
166- expect ( auth . auth . api . forgetPassword ) . not . toHaveBeenCalled ( )
170+ expect ( auth . auth . api . requestPasswordReset ) . not . toHaveBeenCalled ( )
167171 } )
168172
169173 it ( 'should handle empty email' , async ( ) => {
@@ -182,15 +186,15 @@ describe('Forget Password API Route', () => {
182186 expect ( data . message ) . toBe ( 'Please provide a valid email address' )
183187
184188 const auth = await import ( '@/lib/auth' )
185- expect ( auth . auth . api . forgetPassword ) . not . toHaveBeenCalled ( )
189+ expect ( auth . auth . api . requestPasswordReset ) . not . toHaveBeenCalled ( )
186190 } )
187191
188192 it ( 'should handle auth service error with message' , async ( ) => {
189193 const errorMessage = 'User not found'
190194
191195 setupAuthApiMocks ( {
192196 operations : {
193- forgetPassword : {
197+ requestPasswordReset : {
194198 success : false ,
195199 error : errorMessage ,
196200 } ,
@@ -222,7 +226,7 @@ describe('Forget Password API Route', () => {
222226 vi . doMock ( '@/lib/auth' , ( ) => ( {
223227 auth : {
224228 api : {
225- forgetPassword : vi . fn ( ) . mockRejectedValue ( 'Unknown error' ) ,
229+ requestPasswordReset : vi . fn ( ) . mockRejectedValue ( 'Unknown error' ) ,
226230 } ,
227231 } ,
228232 } ) )
0 commit comments