0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-13 21:30:30 -05:00
logto/packages/integration-tests/tests/me.test.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

import { userInfoSelectFields } from '@logto/schemas';
import { assert } from '@silverhand/essentials';
import {
getCurrentUserInfo,
getCurrentUserCustomData,
updateCurrentUserCustomData,
changeCurrentUserPassword,
} from '@/api';
import { createUserByAdmin, signIn } from '@/helpers';
import { generatePassword } from '@/utils';
describe('api `/me`', () => {
it('should get user info successfully', async () => {
const user = await createUserByAdmin();
const userInfo = await getCurrentUserInfo(user.id);
expect(userInfo.id).toBe(user.id);
for (const field of userInfoSelectFields) {
expect(userInfo).toHaveProperty(field);
}
});
it('should get user custom data successfully', async () => {
const user = await createUserByAdmin();
const customData = await getCurrentUserCustomData(user.id);
expect(customData).toEqual({});
});
it('should update user custom data successfully', async () => {
const user = await createUserByAdmin();
const foo = 'bar';
await updateCurrentUserCustomData(user.id, { foo });
const customData = await getCurrentUserCustomData(user.id);
expect(customData).toEqual({ foo });
});
it('should change user password successfully', async () => {
const user = await createUserByAdmin();
const password = generatePassword();
await changeCurrentUserPassword(user.id, password);
assert(user.username, new Error('empty username'));
void expect(signIn(user.username, password)).resolves.not.toThrow();
});
});