Skip to content

Commit

Permalink
chore(core): fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie committed Oct 29, 2024
1 parent dc90d91 commit 326cebe
Showing 1 changed file with 19 additions and 39 deletions.
58 changes: 19 additions & 39 deletions packages/core/src/routes/admin-user/mfa-verifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ const usersLibraries = {
),
} satisfies Partial<Libraries['users']>;

const codes = [
'd94c2f29ae',
'74fa801bb7',
'2cbcc9323c',
'87299f89aa',
'0d95df8598',
'78eedbf35d',
'0fa4c1fd19',
'7384b69eb5',
'7bf2481db7',
'f00febc9ae',
];

const adminUserRoutes = await pickDefault(import('./mfa-verifications.js'));

describe('adminUserRoutes', () => {
Expand Down Expand Up @@ -169,7 +182,7 @@ describe('adminUserRoutes', () => {
it('should fail for wrong length', async () => {
findUserById.mockResolvedValueOnce({
...mockUser,
mfaVerifications: [],
mfaVerifications: [mockUserTotpMfaVerification],
});
const response = await userRequest.post(`/users/${mockUser.id}/mfa-verifications`).send({
type: MfaFactor.BackupCode,
Expand All @@ -181,60 +194,27 @@ describe('adminUserRoutes', () => {
it('should fail for wrong characters', async () => {
findUserById.mockResolvedValueOnce({
...mockUser,
mfaVerifications: [],
mfaVerifications: [mockUserTotpMfaVerification],
});
const response = await userRequest.post(`/users/${mockUser.id}/mfa-verifications`).send({
type: MfaFactor.BackupCode,
codes: [
'd94c2f29ae',
'74fa801bb7',
'2cbcc9323c',
'87299f89aa',
'0d95df8598',
'78eedbf35d',
'0fa4c1xd19',
'7384b69eb5',
'7bf2481db7',
'f00febc9ae',
],
codes: [...codes, '0fa4c1xd19'],
});
expect(response.status).toEqual(422);
});

it('should return the supplied codes', async () => {
findUserById.mockResolvedValueOnce({
...mockUser,
mfaVerifications: [],
mfaVerifications: [mockUserTotpMfaVerification],
});
const response = await userRequest.post(`/users/${mockUser.id}/mfa-verifications`).send({
type: MfaFactor.BackupCode,
codes: [
'd94c2f29ae',
'74fa801bb7',
'2cbcc9323c',
'87299f89aa',
'0d95df8598',
'78eedbf35d',
'0fa4c1fd19',
'7384b69eb5',
'7bf2481db7',
'f00febc9ae',
],
codes,
});
expect(response.body).toMatchObject({
type: MfaFactor.BackupCode,
codes: [
'd94c2f29ae',
'74fa801bb7',
'2cbcc9323c',
'87299f89aa',
'0d95df8598',
'78eedbf35d',
'0fa4c1fd19',
'7384b69eb5',
'7bf2481db7',
'f00febc9ae',
],
codes,
});
});
});
Expand Down

0 comments on commit 326cebe

Please sign in to comment.