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 162998f414
refactor(test): refactor integration test step 1 (#1684)
* chore(test): integration test update

add dotenv

* chore(core): update pnpm lock

update pnpm lock

* refactor(test): refactor integration test step 1

extract api, and orgnize test case following core/route structure

* chore(test): update path

update path

* fix(test): update path

update path

* fix(test): cr update
cr update
2022-07-27 03:23:10 +00:00

75 lines
1.8 KiB
TypeScript

import { ArbitraryObject, UserInfo, userInfoSelectFields } from '@logto/schemas';
import { api } from '@/api';
import { createUser } from '@/helpers';
import { generatePassword } from '@/utils';
describe('api `/me`', () => {
it('should get user info successfully', async () => {
const user = await createUser();
const userInfo = await api
.get(`me`, { headers: { 'development-user-id': user.id } })
.json<UserInfo>();
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 createUser();
const customData = await api
.get('me/custom-data', {
headers: {
'development-user-id': user.id,
},
})
.json<ArbitraryObject>();
expect(customData).toEqual({});
});
it('should update user custom data successfully', async () => {
const user = await createUser();
const headers = Object.freeze({
'development-user-id': user.id,
});
const newCustomData = {
foo: 'bar',
};
await api.patch('me/custom-data', {
headers,
json: {
customData: newCustomData,
},
});
const customData = await api
.get('me/custom-data', {
headers,
})
.json<ArbitraryObject>();
expect(customData).toEqual(newCustomData);
});
it('should change user password successfully', async () => {
const user = await createUser();
const password = generatePassword();
const changePasswordResponse = await api.patch('me/password', {
headers: {
'development-user-id': user.id,
},
json: {
password,
},
});
expect(changePasswordResponse.statusCode).toBe(204);
});
});