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:
parent
755176e252
commit
3a583e81e4
2 changed files with 21 additions and 3 deletions
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue