66import { createMockRequest } from '@sim/testing'
77import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
88
9- const { mockForgetPassword , mockLogger } = vi . hoisted ( ( ) => {
9+ const { mockRequestPasswordReset , mockLogger } = vi . hoisted ( ( ) => {
1010 const logger = {
1111 info : vi . fn ( ) ,
1212 warn : vi . fn ( ) ,
@@ -17,7 +17,7 @@ const { mockForgetPassword, mockLogger } = vi.hoisted(() => {
1717 child : vi . fn ( ) ,
1818 }
1919 return {
20- mockForgetPassword : vi . fn ( ) ,
20+ mockRequestPasswordReset : vi . fn ( ) ,
2121 mockLogger : logger ,
2222 }
2323} )
@@ -28,7 +28,7 @@ vi.mock('@/lib/core/utils/urls', () => ({
2828vi . mock ( '@/lib/auth' , ( ) => ( {
2929 auth : {
3030 api : {
31- forgetPassword : mockForgetPassword ,
31+ requestPasswordReset : mockRequestPasswordReset ,
3232 } ,
3333 } ,
3434} ) )
@@ -43,7 +43,7 @@ import { POST } from '@/app/api/auth/forget-password/route'
4343describe ( 'Forget Password API Route' , ( ) => {
4444 beforeEach ( ( ) => {
4545 vi . clearAllMocks ( )
46- mockForgetPassword . mockResolvedValue ( undefined )
46+ mockRequestPasswordReset . mockResolvedValue ( undefined )
4747 } )
4848
4949 afterEach ( ( ) => {
@@ -62,7 +62,7 @@ describe('Forget Password API Route', () => {
6262 expect ( response . status ) . toBe ( 200 )
6363 expect ( data . success ) . toBe ( true )
6464
65- expect ( mockForgetPassword ) . toHaveBeenCalledWith ( {
65+ expect ( mockRequestPasswordReset ) . toHaveBeenCalledWith ( {
6666 body : {
6767 email : 'test@example.com' ,
6868 redirectTo : 'https://app.example.com/reset' ,
@@ -83,7 +83,7 @@ describe('Forget Password API Route', () => {
8383 expect ( response . status ) . toBe ( 400 )
8484 expect ( data . message ) . toBe ( 'Redirect URL must be a valid same-origin URL' )
8585
86- expect ( mockForgetPassword ) . not . toHaveBeenCalled ( )
86+ expect ( mockRequestPasswordReset ) . not . toHaveBeenCalled ( )
8787 } )
8888
8989 it ( 'should send password reset email without redirectTo' , async ( ) => {
@@ -97,7 +97,7 @@ describe('Forget Password API Route', () => {
9797 expect ( response . status ) . toBe ( 200 )
9898 expect ( data . success ) . toBe ( true )
9999
100- expect ( mockForgetPassword ) . toHaveBeenCalledWith ( {
100+ expect ( mockRequestPasswordReset ) . toHaveBeenCalledWith ( {
101101 body : {
102102 email : 'test@example.com' ,
103103 redirectTo : undefined ,
@@ -115,7 +115,7 @@ describe('Forget Password API Route', () => {
115115 expect ( response . status ) . toBe ( 400 )
116116 expect ( data . message ) . toBe ( 'Email is required' )
117117
118- expect ( mockForgetPassword ) . not . toHaveBeenCalled ( )
118+ expect ( mockRequestPasswordReset ) . not . toHaveBeenCalled ( )
119119 } )
120120
121121 it ( 'should handle empty email' , async ( ) => {
@@ -129,13 +129,13 @@ describe('Forget Password API Route', () => {
129129 expect ( response . status ) . toBe ( 400 )
130130 expect ( data . message ) . toBe ( 'Please provide a valid email address' )
131131
132- expect ( mockForgetPassword ) . not . toHaveBeenCalled ( )
132+ expect ( mockRequestPasswordReset ) . not . toHaveBeenCalled ( )
133133 } )
134134
135135 it ( 'should handle auth service error with message' , async ( ) => {
136136 const errorMessage = 'User not found'
137137
138- mockForgetPassword . mockRejectedValue ( new Error ( errorMessage ) )
138+ mockRequestPasswordReset . mockRejectedValue ( new Error ( errorMessage ) )
139139
140140 const req = createMockRequest ( 'POST' , {
141141 email : 'nonexistent@example.com' ,
@@ -153,7 +153,7 @@ describe('Forget Password API Route', () => {
153153 } )
154154
155155 it ( 'should handle unknown error' , async ( ) => {
156- mockForgetPassword . mockRejectedValue ( 'Unknown error' )
156+ mockRequestPasswordReset . mockRejectedValue ( 'Unknown error' )
157157
158158 const req = createMockRequest ( 'POST' , {
159159 email : 'test@example.com' ,
0 commit comments