mirror of
https://github.com/logto-io/logto.git
synced 2024-12-23 20:33:16 -05:00
0957899d57
* refactor(test): refactor me,logs, dashboard refactor me,logs, dashboard * fix(test): cr update cr update
54 lines
1.5 KiB
TypeScript
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();
|
|
});
|
|
});
|