2022-07-26 22:23:10 -05:00
|
|
|
import { HTTPError } from 'got';
|
|
|
|
|
2022-08-03 04:20:22 -05:00
|
|
|
import {
|
|
|
|
mockSocialConnectorConfig,
|
|
|
|
mockSocialConnectorId,
|
|
|
|
mockSocialConnectorTarget,
|
|
|
|
} from '@/__mocks__/connectors-mock';
|
|
|
|
import {
|
|
|
|
getUser,
|
|
|
|
getUsers,
|
|
|
|
updateUser,
|
|
|
|
deleteUser,
|
|
|
|
updateUserPassword,
|
|
|
|
deleteUserIdentity,
|
|
|
|
} from '@/api';
|
|
|
|
import { createUserByAdmin, bindSocialToNewCreatedUser, setUpConnector } from '@/helpers';
|
2022-07-26 22:23:10 -05:00
|
|
|
|
|
|
|
describe('admin console user management', () => {
|
|
|
|
it('should create user successfully', async () => {
|
2022-07-27 21:13:21 -05:00
|
|
|
const user = await createUserByAdmin();
|
2022-07-26 22:23:10 -05:00
|
|
|
|
|
|
|
const userDetails = await getUser(user.id);
|
|
|
|
expect(userDetails.id).toBe(user.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get user list successfully', async () => {
|
2022-07-27 21:13:21 -05:00
|
|
|
await createUserByAdmin();
|
2022-07-26 22:23:10 -05:00
|
|
|
const users = await getUsers();
|
|
|
|
|
|
|
|
expect(users.length).not.toBeLessThan(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update userinfo successfully', async () => {
|
2022-07-27 21:13:21 -05:00
|
|
|
const user = await createUserByAdmin();
|
2022-07-26 22:23:10 -05:00
|
|
|
|
|
|
|
const newUserData = {
|
|
|
|
name: 'new name',
|
|
|
|
avatar: 'https://new.avatar.com/avatar.png',
|
|
|
|
customData: {
|
|
|
|
level: 1,
|
|
|
|
},
|
|
|
|
roleNames: ['admin'],
|
|
|
|
};
|
|
|
|
|
|
|
|
const updatedUser = await updateUser(user.id, newUserData);
|
|
|
|
|
|
|
|
expect(updatedUser).toMatchObject(newUserData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete user successfully', async () => {
|
2022-07-27 21:13:21 -05:00
|
|
|
const user = await createUserByAdmin();
|
2022-07-26 22:23:10 -05:00
|
|
|
|
|
|
|
const userEntity = await getUser(user.id);
|
|
|
|
expect(userEntity).toMatchObject(user);
|
|
|
|
|
|
|
|
await deleteUser(user.id);
|
|
|
|
|
|
|
|
const response = await getUser(user.id).catch((error: unknown) => error);
|
|
|
|
expect(response instanceof HTTPError && response.response.statusCode === 404).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update user password successfully', async () => {
|
2022-07-27 21:13:21 -05:00
|
|
|
const user = await createUserByAdmin();
|
2022-07-26 22:23:10 -05:00
|
|
|
const userEntity = await updateUserPassword(user.id, 'new_password');
|
|
|
|
expect(userEntity).toMatchObject(user);
|
|
|
|
});
|
2022-08-03 04:20:22 -05:00
|
|
|
|
|
|
|
it('should delete user identities successfully', async () => {
|
|
|
|
await setUpConnector(mockSocialConnectorId, mockSocialConnectorConfig);
|
|
|
|
|
|
|
|
const createdUserId = await bindSocialToNewCreatedUser();
|
|
|
|
|
|
|
|
const userInfo = await getUser(createdUserId);
|
|
|
|
expect(userInfo.identities).toHaveProperty(mockSocialConnectorTarget);
|
|
|
|
|
|
|
|
await deleteUserIdentity(createdUserId, mockSocialConnectorTarget);
|
|
|
|
|
|
|
|
const updatedUser = await getUser(createdUserId);
|
|
|
|
|
|
|
|
expect(updatedUser.identities).not.toHaveProperty(mockSocialConnectorTarget);
|
|
|
|
});
|
2022-07-26 22:23:10 -05:00
|
|
|
});
|