2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2020-08-04 15:06:27 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
registerUser,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolvePerson,
|
2020-09-17 15:41:51 +00:00
|
|
|
saveUserSettings,
|
2020-08-04 15:06:27 +00:00
|
|
|
getSite,
|
2022-04-07 20:52:17 +00:00
|
|
|
createPost,
|
|
|
|
resolveCommunity,
|
|
|
|
createComment,
|
|
|
|
resolveBetaCommunity,
|
|
|
|
deleteUser,
|
|
|
|
resolvePost,
|
|
|
|
API,
|
|
|
|
resolveComment,
|
2020-08-04 15:06:27 +00:00
|
|
|
} from './shared';
|
2020-09-17 15:41:51 +00:00
|
|
|
import {
|
2021-03-12 19:09:03 +00:00
|
|
|
PersonViewSafe,
|
2020-12-20 21:16:57 +00:00
|
|
|
SaveUserSettings,
|
|
|
|
SortType,
|
|
|
|
ListingType,
|
2020-09-17 15:41:51 +00:00
|
|
|
} from 'lemmy-js-client';
|
2020-08-04 15:06:27 +00:00
|
|
|
|
|
|
|
let apShortname: string;
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) {
|
|
|
|
expect(userOne.person.name).toBe(userTwo.person.name);
|
2021-08-19 20:54:15 +00:00
|
|
|
expect(userOne.person.display_name).toBe(userTwo.person.display_name);
|
2021-03-12 19:09:03 +00:00
|
|
|
expect(userOne.person.bio).toBe(userTwo.person.bio);
|
|
|
|
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
|
|
|
|
expect(userOne.person.avatar).toBe(userTwo.person.avatar);
|
|
|
|
expect(userOne.person.banner).toBe(userTwo.person.banner);
|
|
|
|
expect(userOne.person.published).toBe(userTwo.person.published);
|
2020-09-17 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
test('Create user', async () => {
|
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
2021-08-19 20:54:15 +00:00
|
|
|
alpha.auth = userRes.jwt;
|
|
|
|
|
|
|
|
let site = await getSite(alpha);
|
2020-08-04 15:06:27 +00:00
|
|
|
expect(site.my_user).toBeDefined();
|
2021-08-19 20:54:15 +00:00
|
|
|
apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
2020-08-04 15:06:27 +00:00
|
|
|
});
|
|
|
|
|
2020-12-17 19:01:33 +00:00
|
|
|
test('Set some user settings, check that they are federated', async () => {
|
2020-09-17 15:41:51 +00:00
|
|
|
let avatar = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
|
|
|
let banner = 'https://image.flaticon.com/icons/png/512/36/35896.png';
|
2020-12-17 19:01:33 +00:00
|
|
|
let bio = 'a changed bio';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: SaveUserSettings = {
|
2020-09-17 15:41:51 +00:00
|
|
|
show_nsfw: false,
|
2020-12-20 21:16:57 +00:00
|
|
|
theme: '',
|
2021-01-04 19:09:53 +00:00
|
|
|
default_sort_type: Object.keys(SortType).indexOf(SortType.Hot),
|
|
|
|
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
2020-12-20 21:16:57 +00:00
|
|
|
lang: '',
|
2020-09-17 15:41:51 +00:00
|
|
|
avatar,
|
|
|
|
banner,
|
2021-08-19 20:54:15 +00:00
|
|
|
display_name: 'user321',
|
2020-09-17 15:41:51 +00:00
|
|
|
show_avatars: false,
|
|
|
|
send_notifications_to_email: false,
|
2020-12-17 19:01:33 +00:00
|
|
|
bio,
|
2021-08-19 20:54:15 +00:00
|
|
|
auth: alpha.auth,
|
2020-12-20 21:16:57 +00:00
|
|
|
};
|
2020-12-17 19:01:33 +00:00
|
|
|
await saveUserSettings(alpha, form);
|
2020-09-17 15:41:51 +00:00
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
|
|
|
let betaPerson = (await resolvePerson(beta, apShortname)).person;
|
|
|
|
assertUserFederation(alphaPerson, betaPerson);
|
2020-09-18 11:04:12 +00:00
|
|
|
});
|
2022-04-07 20:52:17 +00:00
|
|
|
|
|
|
|
test('Delete user', async () => {
|
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
|
|
|
let user: API = {
|
|
|
|
client: alpha.client,
|
|
|
|
auth: userRes.jwt
|
|
|
|
}
|
|
|
|
|
|
|
|
// make a local post and comment
|
|
|
|
let alphaCommunity = (await resolveCommunity(user, '!main@lemmy-alpha:8541')).community;
|
|
|
|
let localPost = (await createPost(user, alphaCommunity.community.id)).post_view.post;
|
|
|
|
expect(localPost).toBeDefined();
|
|
|
|
let localComment = (await createComment(user, localPost.id)).comment_view.comment;
|
|
|
|
expect(localComment).toBeDefined();
|
|
|
|
|
|
|
|
// make a remote post and comment
|
|
|
|
let betaCommunity = (await resolveBetaCommunity(user)).community;
|
|
|
|
let remotePost = (await createPost(user, betaCommunity.community.id)).post_view.post;
|
|
|
|
expect(remotePost).toBeDefined();
|
|
|
|
let remoteComment = (await createComment(user, remotePost.id)).comment_view.comment;
|
|
|
|
expect(remoteComment).toBeDefined();
|
|
|
|
|
|
|
|
await deleteUser(user);
|
|
|
|
|
|
|
|
expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
|
|
|
|
expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
|
|
|
|
expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
|
|
|
|
expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
|
|
|
|
});
|