0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/integration-tests/tests/me.test.ts
simeng-li 0957899d57
refactor(test): refactor log, dashboard, me (#1692)
* refactor(test): refactor me,logs, dashboard

refactor me,logs, dashboard

* fix(test): cr update

cr update
2022-07-28 02:30:37 +00:00

54 lines
1.5 KiB
TypeScript

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();
});
});