@@ -4,6 +4,7 @@ import { MfaFactor } from '@logto/schemas';
4
4
import { enableAllAccountCenterFields } from '#src/api/account-center.js' ;
5
5
import {
6
6
addMfaVerification ,
7
+ deleteMfaVerification ,
7
8
generateTotpSecret ,
8
9
getMfaVerifications ,
9
10
} from '#src/api/my-account.js' ;
@@ -98,6 +99,41 @@ describe('my-account (mfa)', () => {
98
99
} ) ;
99
100
} ) ;
100
101
102
+ devFeatureTest . describe ( 'DELETE /my-account/mfa-verifications/:verificationId' , ( ) => {
103
+ devFeatureTest . it ( 'should be able to delete totp verification' , async ( ) => {
104
+ await enableAllAccountCenterFields ( ) ;
105
+
106
+ const { user, username, password } = await createDefaultTenantUserWithPassword ( ) ;
107
+ const api = await signInAndGetUserApi ( username , password , {
108
+ scopes : [ UserScope . Profile , UserScope . Identities ] ,
109
+ } ) ;
110
+ const { secret } = await generateTotpSecret ( api ) ;
111
+ const verificationRecordId = await createVerificationRecordByPassword ( api , password ) ;
112
+
113
+ // Add TOTP verification
114
+ await addMfaVerification ( api , verificationRecordId , {
115
+ type : MfaFactor . TOTP ,
116
+ secret,
117
+ } ) ;
118
+
119
+ const mfaVerifications = await getMfaVerifications ( api ) ;
120
+ expect ( mfaVerifications ) . toHaveLength ( 1 ) ;
121
+ expect ( mfaVerifications [ 0 ] ?. type ) . toBe ( MfaFactor . TOTP ) ;
122
+
123
+ const totpVerificationId = mfaVerifications [ 0 ] ?. id ;
124
+ expect ( totpVerificationId ) . toBeTruthy ( ) ;
125
+
126
+ // Delete TOTP verification
127
+ const deleteVerificationRecordId = await createVerificationRecordByPassword ( api , password ) ;
128
+ await deleteMfaVerification ( api , totpVerificationId ! , deleteVerificationRecordId ) ;
129
+
130
+ const updatedMfaVerifications = await getMfaVerifications ( api ) ;
131
+ expect ( updatedMfaVerifications ) . toHaveLength ( 0 ) ;
132
+
133
+ await deleteDefaultTenantUser ( user . id ) ;
134
+ } ) ;
135
+ } ) ;
136
+
101
137
describe ( 'POST /my-account/mfa-verifications/web-authn/registration' , ( ) => {
102
138
it ( 'should be able to get webauthn registration options' , async ( ) => {
103
139
const { user, username, password } = await createDefaultTenantUserWithPassword ( ) ;
0 commit comments