0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-17 22:31:28 -05:00

fix(core): patch /users/:userId should not fail if only name or avatar is provided

This commit is contained in:
Xiao Yijun 2022-02-28 13:18:17 +08:00 committed by GitHub
parent 755176e252
commit 3a583e81e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -167,6 +167,25 @@ describe('adminUserRoutes', () => {
});
});
it('PATCH /users/:userId should updated with one field if the other is undefined', async () => {
const name = 'Micheal';
const updateNameResponse = await userRequest.patch('/users/foo').send({ name });
expect(updateNameResponse.status).toEqual(200);
expect(updateNameResponse.body).toEqual({
...mockUserResponse,
name,
});
const avatar = 'https://www.miceal.png';
const updateAvatarResponse = await userRequest.patch('/users/foo').send({ avatar });
expect(updateAvatarResponse.status).toEqual(200);
expect(updateAvatarResponse.body).toEqual({
...mockUserResponse,
avatar,
});
});
it('PATCH /users/:userId throw with invalid input params', async () => {
const name = 'Micheal';
const avatar = 'http://www.micheal.png';

View file

@ -116,14 +116,13 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
async (ctx, next) => {
const {
params: { userId },
body: { name, avatar },
body,
} = ctx.guard;
await findUserById(userId);
const user = await updateUserById(userId, {
name,
avatar,
...body,
});
ctx.body = pick(user, ...userInfoSelectFields);