mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor(core): remove unused /users/:userId/custom-data
APIs (#1086)
This commit is contained in:
parent
5afbe9d70b
commit
b9ca929ccc
2 changed files with 1 additions and 107 deletions
|
@ -298,67 +298,6 @@ describe('adminUserRoutes', () => {
|
|||
expect(deleteUserById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('PATCH /users/:userId/custom-data', async () => {
|
||||
const customData = { level: 1 };
|
||||
const response = await userRequest.patch('/users/foo/custom-data').send({ customData });
|
||||
expect(findUserById).toHaveBeenCalledTimes(1);
|
||||
expect(updateUserById).toHaveBeenCalledTimes(1);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toHaveProperty('customData', customData);
|
||||
});
|
||||
|
||||
it('PATCH /users/:userId/custom-data should throw if user not found', async () => {
|
||||
const notExistedUserId = 'notExisitedUserId';
|
||||
const mockedFindUserById = findUserById as jest.Mock;
|
||||
mockedFindUserById.mockImplementationOnce((userId) => {
|
||||
if (userId === notExistedUserId) {
|
||||
throw new Error(' ');
|
||||
}
|
||||
});
|
||||
await expect(
|
||||
userRequest.patch(`/users/${notExistedUserId}/custom-data`).send({ customData: { level: 1 } })
|
||||
).resolves.toHaveProperty('status', 500);
|
||||
expect(updateUserById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('PATCH /users/:userId/custom-data should throw if customData is not an object', async () => {
|
||||
await expect(
|
||||
userRequest.patch(`/users/foo/custom-data`).send({ customData: 123_456 })
|
||||
).resolves.toHaveProperty('status', 400);
|
||||
|
||||
await expect(
|
||||
userRequest.patch(`/users/foo/custom-data`).send({ customData: ['customDataContent'] })
|
||||
).resolves.toHaveProperty('status', 400);
|
||||
|
||||
await expect(
|
||||
userRequest.patch(`/users/foo/custom-data`).send({ customData: 'customDataContent' })
|
||||
).resolves.toHaveProperty('status', 400);
|
||||
|
||||
expect(updateUserById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('DELETE /users/:userId/custom-data', async () => {
|
||||
const response = await userRequest.delete('/users/foo/custom-data');
|
||||
expect(findUserById).toHaveBeenCalledTimes(1);
|
||||
expect(clearUserCustomDataById).toHaveBeenCalledTimes(1);
|
||||
expect(response.status).toEqual(200);
|
||||
});
|
||||
|
||||
it('DELETE /users/:userId/custom-data should throw if user not found', async () => {
|
||||
const notExistedUserId = 'notExisitedUserId';
|
||||
const mockedFindUserById = findUserById as jest.Mock;
|
||||
mockedFindUserById.mockImplementationOnce((userId) => {
|
||||
if (userId === notExistedUserId) {
|
||||
throw new Error(' ');
|
||||
}
|
||||
});
|
||||
await expect(
|
||||
userRequest.delete(`/users/${notExistedUserId}/custom-data`)
|
||||
).resolves.toHaveProperty('status', 500);
|
||||
expect(findUserById).toHaveBeenCalledTimes(1);
|
||||
expect(clearUserCustomDataById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('DELETE /users/:userId/identities/:connectorId should throw if user not found', async () => {
|
||||
const notExistedUserId = 'notExisitedUserId';
|
||||
const arbitraryConnectorId = 'arbitraryConnectorId';
|
||||
|
|
|
@ -123,8 +123,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
|
||||
await findUserById(userId);
|
||||
|
||||
// Clear customData to achieve full replacement,
|
||||
// to partial update, call patch /users/:userId/custom-data
|
||||
// Clear customData to achieve full replacement
|
||||
if (body.customData) {
|
||||
await clearUserCustomDataById(userId);
|
||||
}
|
||||
|
@ -200,50 +199,6 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/users/:userId/custom-data',
|
||||
koaGuard({
|
||||
params: object({ userId: string() }),
|
||||
body: object({ customData: arbitraryObjectGuard }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
body: { customData },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
const user = await updateUserById(userId, {
|
||||
customData,
|
||||
});
|
||||
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/users/:userId/custom-data',
|
||||
koaGuard({
|
||||
params: object({ userId: string() }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
await clearUserCustomDataById(userId);
|
||||
|
||||
ctx.status = 200;
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/users/:userId/identities/:connectorId',
|
||||
koaGuard({ params: object({ userId: string(), connectorId: string() }) }),
|
||||
|
|
Loading…
Add table
Reference in a new issue