@@ -890,6 +890,133 @@ describe('SignIn', () => {
890890 } ) ;
891891 } ) ;
892892
893+ describe ( 'sendResetPasswordPhoneCode' , ( ) => {
894+ afterEach ( ( ) => {
895+ vi . clearAllMocks ( ) ;
896+ } ) ;
897+
898+ it ( 'creates signIn with phoneNumber when no existing signIn' , async ( ) => {
899+ const mockFetch = vi
900+ . fn ( )
901+ . mockResolvedValueOnce ( {
902+ client : null ,
903+ response : {
904+ id : 'signin_123' ,
905+ identifier : '+15551234567' ,
906+ supported_first_factors : [
907+ {
908+ strategy : 'reset_password_phone_code' ,
909+ phone_number_id : 'phone_123' ,
910+ safe_identifier : '+15551234567' ,
911+ } ,
912+ ] ,
913+ } ,
914+ } )
915+ . mockResolvedValueOnce ( {
916+ client : null ,
917+ response : { id : 'signin_123' } ,
918+ } ) ;
919+ BaseResource . _fetch = mockFetch ;
920+
921+ const signIn = new SignIn ( ) ;
922+ await signIn . __internal_future . resetPasswordPhoneCode . sendCode ( { phoneNumber : '+15551234567' } ) ;
923+
924+ expect ( mockFetch ) . toHaveBeenNthCalledWith ( 1 , {
925+ method : 'POST' ,
926+ path : '/client/sign_ins' ,
927+ body : { identifier : '+15551234567' } ,
928+ } ) ;
929+
930+ expect ( mockFetch ) . toHaveBeenNthCalledWith ( 2 , {
931+ method : 'POST' ,
932+ path : '/client/sign_ins/signin_123/prepare_first_factor' ,
933+ body : {
934+ phoneNumberId : 'phone_123' ,
935+ strategy : 'reset_password_phone_code' ,
936+ } ,
937+ } ) ;
938+ } ) ;
939+
940+ it ( 'prepares first factor with reset password phone code' , async ( ) => {
941+ const mockFetch = vi . fn ( ) . mockResolvedValue ( {
942+ client : null ,
943+ response : { id : 'signin_123' } ,
944+ } ) ;
945+ BaseResource . _fetch = mockFetch ;
946+
947+ const signIn = new SignIn ( {
948+ id : 'signin_123' ,
949+ supported_first_factors : [
950+ {
951+ strategy : 'reset_password_phone_code' ,
952+ phone_number_id : 'phone_123' ,
953+ safe_identifier : '+15551234567' ,
954+ } ,
955+ ] ,
956+ } as any ) ;
957+ await signIn . __internal_future . resetPasswordPhoneCode . sendCode ( ) ;
958+
959+ expect ( mockFetch ) . toHaveBeenCalledWith ( {
960+ method : 'POST' ,
961+ path : '/client/sign_ins/signin_123/prepare_first_factor' ,
962+ body : {
963+ phoneNumberId : 'phone_123' ,
964+ strategy : 'reset_password_phone_code' ,
965+ } ,
966+ } ) ;
967+ } ) ;
968+
969+ it ( 'throws error when no signIn ID and no phoneNumber' , async ( ) => {
970+ const signIn = new SignIn ( ) ;
971+
972+ await expect ( signIn . __internal_future . resetPasswordPhoneCode . sendCode ( ) ) . rejects . toThrow ( ) ;
973+ } ) ;
974+
975+ it ( 'returns error when reset password phone code factor not found' , async ( ) => {
976+ const mockFetch = vi . fn ( ) . mockResolvedValue ( {
977+ client : null ,
978+ response : {
979+ id : 'signin_123' ,
980+ identifier : '+15551234567' ,
981+ supported_first_factors : [ { strategy : 'password' } ] ,
982+ } ,
983+ } ) ;
984+ BaseResource . _fetch = mockFetch ;
985+
986+ const signIn = new SignIn ( ) ;
987+ const result = await signIn . __internal_future . resetPasswordPhoneCode . sendCode ( { phoneNumber : '+15551234567' } ) ;
988+
989+ expect ( result . error ) . toBeTruthy ( ) ;
990+ expect ( result . error ?. code ) . toBe ( 'factor_not_found' ) ;
991+ } ) ;
992+ } ) ;
993+
994+ describe ( 'verifyResetPasswordPhoneCode' , ( ) => {
995+ afterEach ( ( ) => {
996+ vi . clearAllMocks ( ) ;
997+ } ) ;
998+
999+ it ( 'attempts first factor with reset password phone code' , async ( ) => {
1000+ const mockFetch = vi . fn ( ) . mockResolvedValue ( {
1001+ client : null ,
1002+ response : { id : 'signin_123' } ,
1003+ } ) ;
1004+ BaseResource . _fetch = mockFetch ;
1005+
1006+ const signIn = new SignIn ( { id : 'signin_123' } as any ) ;
1007+ await signIn . __internal_future . resetPasswordPhoneCode . verifyCode ( { code : '123456' } ) ;
1008+
1009+ expect ( mockFetch ) . toHaveBeenCalledWith ( {
1010+ method : 'POST' ,
1011+ path : '/client/sign_ins/signin_123/attempt_first_factor' ,
1012+ body : {
1013+ code : '123456' ,
1014+ strategy : 'reset_password_phone_code' ,
1015+ } ,
1016+ } ) ;
1017+ } ) ;
1018+ } ) ;
1019+
8931020 describe ( 'submitResetPassword' , ( ) => {
8941021 afterEach ( ( ) => {
8951022 vi . clearAllMocks ( ) ;
0 commit comments