Skip to content

Commit d143168

Browse files
committed
test: add integration tests for delete mfa
1 parent 505f3ca commit d143168

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

packages/integration-tests/src/api/my-account.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,12 @@ export const addMfaVerification = async (
9090
json: body,
9191
headers: { [verificationRecordIdHeader]: verificationRecordId },
9292
});
93+
94+
export const deleteMfaVerification = async (
95+
api: KyInstance,
96+
verificationId: string,
97+
verificationRecordId: string
98+
) =>
99+
api.delete(`api/my-account/mfa-verifications/${verificationId}`, {
100+
headers: { [verificationRecordIdHeader]: verificationRecordId },
101+
});

packages/integration-tests/src/tests/api/account/mfa.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MfaFactor } from '@logto/schemas';
44
import { enableAllAccountCenterFields } from '#src/api/account-center.js';
55
import {
66
addMfaVerification,
7+
deleteMfaVerification,
78
generateTotpSecret,
89
getMfaVerifications,
910
} from '#src/api/my-account.js';
@@ -98,6 +99,41 @@ describe('my-account (mfa)', () => {
9899
});
99100
});
100101

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+
101137
describe('POST /my-account/mfa-verifications/web-authn/registration', () => {
102138
it('should be able to get webauthn registration options', async () => {
103139
const { user, username, password } = await createDefaultTenantUserWithPassword();

0 commit comments

Comments
 (0)