From 33b5e2e6b02e0d273a7de69f45f9eca8c09e46a0 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Thu, 10 Nov 2022 15:41:43 +0800 Subject: [PATCH] refactor(core): remove SIE identifier check from user management API --- packages/core/src/routes/admin-user.test.ts | 58 --------------------- packages/core/src/routes/admin-user.ts | 3 +- 2 files changed, 1 insertion(+), 60 deletions(-) diff --git a/packages/core/src/routes/admin-user.test.ts b/packages/core/src/routes/admin-user.test.ts index c155fc7e9..756dfdecd 100644 --- a/packages/core/src/routes/admin-user.test.ts +++ b/packages/core/src/routes/admin-user.test.ts @@ -251,64 +251,6 @@ describe('adminUserRoutes', () => { expect(updateUserById).not.toBeCalled(); }); - it('PATCH /users/:userId should throw if required sign-up identifier username is missing', async () => { - mockFindDefaultSignInExperience.mockImplementationOnce(async () => ({ - signUp: { - identifier: SignUpIdentifier.Username, - password: false, - verify: false, - }, - })); - - await expect( - userRequest - .patch('/users/foo') - .send({ primaryEmail: 'test@abc.com', primaryPhone: '18688886666' }) - ).resolves.toHaveProperty('status', 422); - }); - - it('PATCH /users/:userId should throw if required sign-up identifier email is missing', async () => { - mockFindDefaultSignInExperience.mockImplementationOnce(async () => ({ - signUp: { - identifier: SignUpIdentifier.Email, - password: false, - verify: false, - }, - })); - - await expect( - userRequest.patch('/users/foo').send({ username: 'test', primaryPhone: '18688886666' }) - ).resolves.toHaveProperty('status', 422); - }); - - it('PATCH /users/:userId should throw if required sign-up identifier phone is missing', async () => { - mockFindDefaultSignInExperience.mockImplementationOnce(async () => ({ - signUp: { - identifier: SignUpIdentifier.Sms, - password: false, - verify: false, - }, - })); - - await expect( - userRequest.patch('/users/foo').send({ username: 'test', primaryEmail: 'test@abc.com' }) - ).resolves.toHaveProperty('status', 422); - }); - - it('PATCH /users/:userId should throw if required sign-up identifiers email and phone are both missing', async () => { - mockFindDefaultSignInExperience.mockImplementationOnce(async () => ({ - signUp: { - identifier: SignUpIdentifier.EmailOrSms, - password: false, - verify: false, - }, - })); - - await expect( - userRequest.patch('/users/foo').send({ username: 'test' }) - ).resolves.toHaveProperty('status', 422); - }); - it('PATCH /users/:userId should throw if new username is already in use', async () => { mockHasUser.mockImplementationOnce(async () => true); diff --git a/packages/core/src/routes/admin-user.ts b/packages/core/src/routes/admin-user.ts index 4c9f895c7..36ebf2ce4 100644 --- a/packages/core/src/routes/admin-user.ts +++ b/packages/core/src/routes/admin-user.ts @@ -21,7 +21,7 @@ import { } from '@/queries/user'; import assertThat from '@/utils/assert-that'; -import { checkExistingSignUpIdentifiers, checkRequiredSignUpIdentifiers } from './session/utils'; +import { checkExistingSignUpIdentifiers } from './session/utils'; import type { AuthedRouter } from './types'; export default function adminUserRoutes(router: T) { @@ -175,7 +175,6 @@ export default function adminUserRoutes(router: T) { } = ctx.guard; await findUserById(userId); - await checkRequiredSignUpIdentifiers(body); await checkExistingSignUpIdentifiers(body); // Temp solution to validate the existence of input roleNames