@@ -979,6 +979,48 @@ describe('SignIn', () => {
979979 } ) ;
980980 } ) ;
981981
982+ describe ( 'sendMFAEmailCode' , ( ) => {
983+ afterEach ( ( ) => {
984+ vi . clearAllMocks ( ) ;
985+ } ) ;
986+
987+ it ( 'prepares second factor with email code' , async ( ) => {
988+ const mockFetch = vi . fn ( ) . mockResolvedValue ( {
989+ client : null ,
990+ response : { id : 'signin_123' } ,
991+ } ) ;
992+ BaseResource . _fetch = mockFetch ;
993+
994+ const signIn = new SignIn ( {
995+ id : 'signin_123' ,
996+ supported_second_factors : [
997+ { strategy :
'email_code' , email_address_id :
'email_123' , safe_identifier :
'[email protected] ' } , 998+ ] ,
999+ } as any ) ;
1000+ await signIn . __internal_future . mfa . sendEmailCode ( ) ;
1001+
1002+ expect ( mockFetch ) . toHaveBeenCalledWith ( {
1003+ method : 'POST' ,
1004+ path : '/client/sign_ins/signin_123/prepare_second_factor' ,
1005+ body : {
1006+ emailAddressId : 'email_123' ,
1007+ strategy : 'email_code' ,
1008+ } ,
1009+ } ) ;
1010+ } ) ;
1011+
1012+ it ( 'returns error when email code factor not found' , async ( ) => {
1013+ const signIn = new SignIn ( {
1014+ id : 'signin_123' ,
1015+ supported_second_factors : [ { strategy : 'totp' } ] ,
1016+ } as any ) ;
1017+ const result = await signIn . __internal_future . mfa . sendEmailCode ( ) ;
1018+
1019+ expect ( result . error ) . toBeTruthy ( ) ;
1020+ expect ( result . error ?. code ) . toBe ( 'factor_not_found' ) ;
1021+ } ) ;
1022+ } ) ;
1023+
9821024 describe ( 'passkey' , ( ) => {
9831025 afterEach ( ( ) => {
9841026 vi . clearAllMocks ( ) ;
0 commit comments