mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Add tests for avatars, banners and more
This commit is contained in:
parent
93f681bf7a
commit
cdb02c992c
5 changed files with 135 additions and 17 deletions
|
@ -22,6 +22,9 @@ import {
|
|||
API,
|
||||
delay,
|
||||
} from './shared';
|
||||
import {
|
||||
Comment,
|
||||
} from 'lemmy-js-client';
|
||||
|
||||
import { PostResponse } from 'lemmy-js-client';
|
||||
|
||||
|
@ -44,6 +47,19 @@ afterAll(async () => {
|
|||
await unfollowRemotes(gamma);
|
||||
});
|
||||
|
||||
function assertCommentFederation(
|
||||
commentOne: Comment,
|
||||
commentTwo: Comment) {
|
||||
expect(commentOne.ap_id).toBe(commentOne.ap_id);
|
||||
expect(commentOne.content).toBe(commentTwo.content);
|
||||
expect(commentOne.creator_name).toBe(commentTwo.creator_name);
|
||||
expect(commentOne.community_actor_id).toBe(commentTwo.community_actor_id);
|
||||
expect(commentOne.published).toBe(commentTwo.published);
|
||||
expect(commentOne.updated).toBe(commentOne.updated);
|
||||
expect(commentOne.deleted).toBe(commentOne.deleted);
|
||||
expect(commentOne.removed).toBe(commentOne.removed);
|
||||
}
|
||||
|
||||
test('Create a comment', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
expect(commentRes.comment.content).toBeDefined();
|
||||
|
@ -59,6 +75,7 @@ test('Create a comment', async () => {
|
|||
expect(betaComment.community_local).toBe(true);
|
||||
expect(betaComment.creator_local).toBe(false);
|
||||
expect(betaComment.score).toBe(1);
|
||||
assertCommentFederation(betaComment, commentRes.comment);
|
||||
});
|
||||
|
||||
test('Create a comment in a non-existent post', async () => {
|
||||
|
@ -68,6 +85,10 @@ test('Create a comment in a non-existent post', async () => {
|
|||
|
||||
test('Update a comment', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
// Federate the comment first
|
||||
let searchBeta = await searchComment(beta, commentRes.comment);
|
||||
assertCommentFederation(searchBeta.comments[0], commentRes.comment);
|
||||
|
||||
await delay();
|
||||
let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
|
||||
expect(updateCommentRes.comment.content).toBe(
|
||||
|
@ -78,9 +99,8 @@ test('Update a comment', async () => {
|
|||
await delay();
|
||||
|
||||
// Make sure that post is updated on beta
|
||||
let searchBeta = await searchComment(beta, commentRes.comment);
|
||||
let betaComment = searchBeta.comments[0];
|
||||
expect(betaComment.content).toBe('A jest test federated comment update');
|
||||
let searchBetaUpdated = await searchComment(beta, commentRes.comment);
|
||||
assertCommentFederation(searchBetaUpdated.comments[0], updateCommentRes.comment);
|
||||
});
|
||||
|
||||
test('Delete a comment', async () => {
|
||||
|
@ -113,6 +133,7 @@ test('Delete a comment', async () => {
|
|||
let searchBeta2 = await searchComment(beta, commentRes.comment);
|
||||
let betaComment2 = searchBeta2.comments[0];
|
||||
expect(betaComment2.deleted).toBe(false);
|
||||
assertCommentFederation(searchBeta2.comments[0], undeleteCommentRes.comment);
|
||||
});
|
||||
|
||||
test('Remove a comment from admin and community on the same instance', async () => {
|
||||
|
@ -139,6 +160,7 @@ test('Remove a comment from admin and community on the same instance', async ()
|
|||
// Make sure that comment is unremoved on beta
|
||||
let refetchedPost2 = await getPost(alpha, postRes.post.id);
|
||||
expect(refetchedPost2.comments[0].removed).toBe(false);
|
||||
assertCommentFederation(refetchedPost2.comments[0], unremoveCommentRes.comment);
|
||||
});
|
||||
|
||||
test('Remove a comment from admin and community on different instance', async () => {
|
||||
|
@ -167,6 +189,7 @@ test('Remove a comment from admin and community on different instance', async ()
|
|||
// Make sure its not removed on alpha
|
||||
let refetchedPost = await getPost(newAlphaApi, newPost.post.id);
|
||||
expect(refetchedPost.comments[0].removed).toBe(false);
|
||||
assertCommentFederation(refetchedPost.comments[0], commentRes.comment);
|
||||
});
|
||||
|
||||
test('Unlike a comment', async () => {
|
||||
|
@ -231,6 +254,7 @@ test('Reply to a comment', async () => {
|
|||
expect(alphaComment.community_local).toBe(false);
|
||||
expect(alphaComment.creator_local).toBe(false);
|
||||
expect(alphaComment.score).toBe(1);
|
||||
assertCommentFederation(alphaComment, replyRes.comment);
|
||||
});
|
||||
|
||||
test('Mention beta', async () => {
|
||||
|
@ -261,7 +285,7 @@ test('Comment Search', async () => {
|
|||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
let searchBeta = await searchComment(beta, commentRes.comment);
|
||||
expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id);
|
||||
assertCommentFederation(searchBeta.comments[0], commentRes.comment);
|
||||
});
|
||||
|
||||
test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
|
||||
|
@ -294,6 +318,7 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
|
|||
expect(alphaPost2.comments[0].community_local).toBe(true);
|
||||
expect(alphaPost2.comments[0].creator_local).toBe(false);
|
||||
expect(alphaPost2.comments[0].score).toBe(1);
|
||||
assertCommentFederation(alphaPost2.comments[0], commentRes.comment);
|
||||
|
||||
// Make sure beta has mentions
|
||||
let mentionsRes = await getMentions(beta);
|
||||
|
@ -360,8 +385,8 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
|||
|
||||
let alphaPost = await getPost(alpha, alphaPostB.id);
|
||||
expect(alphaPost.post.name).toBeDefined();
|
||||
expect(alphaPost.comments[1].content).toBe(parentCommentContent);
|
||||
expect(alphaPost.comments[0].content).toBe(updatedCommentContent);
|
||||
assertCommentFederation(alphaPost.comments[1], parentCommentRes.comment);
|
||||
assertCommentFederation(alphaPost.comments[0], updateRes.comment);
|
||||
expect(alphaPost.post.community_local).toBe(false);
|
||||
expect(alphaPost.post.creator_local).toBe(false);
|
||||
});
|
||||
|
|
|
@ -10,11 +10,31 @@ import {
|
|||
removeCommunity,
|
||||
delay,
|
||||
} from './shared';
|
||||
import {
|
||||
Community,
|
||||
} from 'lemmy-js-client';
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
});
|
||||
|
||||
function assertCommunityFederation(
|
||||
communityOne: Community,
|
||||
communityTwo: Community) {
|
||||
expect(communityOne.actor_id).toBe(communityTwo.actor_id);
|
||||
expect(communityOne.name).toBe(communityTwo.name);
|
||||
expect(communityOne.title).toBe(communityTwo.title);
|
||||
expect(communityOne.description).toBe(communityTwo.description);
|
||||
expect(communityOne.icon).toBe(communityTwo.icon);
|
||||
expect(communityOne.banner).toBe(communityTwo.banner);
|
||||
expect(communityOne.published).toBe(communityTwo.published);
|
||||
expect(communityOne.creator_actor_id).toBe(communityTwo.creator_actor_id);
|
||||
expect(communityOne.nsfw).toBe(communityTwo.nsfw);
|
||||
expect(communityOne.category_id).toBe(communityTwo.category_id);
|
||||
expect(communityOne.removed).toBe(communityTwo.removed);
|
||||
expect(communityOne.deleted).toBe(communityTwo.deleted);
|
||||
}
|
||||
|
||||
test('Create community', async () => {
|
||||
let communityRes = await createCommunity(alpha);
|
||||
expect(communityRes.community.name).toBeDefined();
|
||||
|
@ -29,11 +49,7 @@ test('Create community', async () => {
|
|||
let searchShort = `!${prevName}@lemmy-alpha:8541`;
|
||||
let search = await searchForCommunity(beta, searchShort);
|
||||
let communityOnBeta = search.communities[0];
|
||||
expect(communityOnBeta.name).toBe(communityRes.community.name);
|
||||
expect(communityOnBeta.title).toBe(communityRes.community.title);
|
||||
expect(communityOnBeta.description).toBe(communityRes.community.description);
|
||||
expect(communityOnBeta.icon).toBe(communityRes.community.icon);
|
||||
expect(communityOnBeta.banner).toBe(communityRes.community.banner);
|
||||
assertCommunityFederation(communityOnBeta, communityRes.community);
|
||||
});
|
||||
|
||||
test('Delete community', async () => {
|
||||
|
@ -52,6 +68,7 @@ test('Delete community', async () => {
|
|||
let communityA = search.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA.deleted).toBe(true);
|
||||
// assertCommunityFederation(communityA, communityRes.community);
|
||||
|
||||
// Undelete
|
||||
let undeleteCommunityRes = await deleteCommunity(
|
||||
|
@ -67,6 +84,7 @@ test('Delete community', async () => {
|
|||
let communityA2 = search2.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA2.deleted).toBe(false);
|
||||
// assertCommunityFederation(communityA2, undeleteCommunityRes.community);
|
||||
});
|
||||
|
||||
test('Remove community', async () => {
|
||||
|
@ -84,6 +102,7 @@ test('Remove community', async () => {
|
|||
let communityA = search.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA.removed).toBe(true);
|
||||
// assertCommunityFederation(communityA, communityRes.community);
|
||||
await delay();
|
||||
|
||||
// unremove
|
||||
|
@ -100,6 +119,7 @@ test('Remove community', async () => {
|
|||
let communityA2 = search2.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA2.removed).toBe(false);
|
||||
// assertCommunityFederation(communityA2, unremoveCommunityRes.community);
|
||||
});
|
||||
|
||||
test('Search for beta community', async () => {
|
||||
|
|
|
@ -21,6 +21,9 @@ import {
|
|||
unfollowRemotes,
|
||||
delay,
|
||||
} from './shared';
|
||||
import {
|
||||
Post,
|
||||
} from 'lemmy-js-client';
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
|
@ -38,6 +41,24 @@ afterAll(async () => {
|
|||
await unfollowRemotes(epsilon);
|
||||
});
|
||||
|
||||
function assertPostFederation(
|
||||
postOne: Post,
|
||||
postTwo: Post) {
|
||||
expect(postOne.ap_id).toBe(postTwo.ap_id);
|
||||
expect(postOne.name).toBe(postTwo.name);
|
||||
expect(postOne.body).toBe(postTwo.body);
|
||||
expect(postOne.url).toBe(postTwo.url);
|
||||
expect(postOne.nsfw).toBe(postTwo.nsfw);
|
||||
expect(postOne.embed_title).toBe(postTwo.embed_title);
|
||||
expect(postOne.embed_description).toBe(postTwo.embed_description);
|
||||
expect(postOne.embed_html).toBe(postTwo.embed_html);
|
||||
expect(postOne.published).toBe(postTwo.published);
|
||||
expect(postOne.community_actor_id).toBe(postTwo.community_actor_id);
|
||||
expect(postOne.locked).toBe(postTwo.locked);
|
||||
expect(postOne.removed).toBe(postTwo.removed);
|
||||
expect(postOne.deleted).toBe(postTwo.deleted);
|
||||
}
|
||||
|
||||
test('Create a post', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
await delay();
|
||||
|
@ -56,10 +77,7 @@ test('Create a post', async () => {
|
|||
expect(betaPost.community_local).toBe(true);
|
||||
expect(betaPost.creator_local).toBe(false);
|
||||
expect(betaPost.score).toBe(1);
|
||||
expect(betaPost.name).toBe(postRes.post.name);
|
||||
expect(betaPost.body).toBe(postRes.post.body);
|
||||
expect(betaPost.url).toBe(postRes.post.url);
|
||||
expect(betaPost.nsfw).toBe(postRes.post.nsfw);
|
||||
assertPostFederation(betaPost, postRes.post);
|
||||
|
||||
// Delta only follows beta, so it should not see an alpha ap_id
|
||||
let searchDelta = await searchPost(delta, postRes.post);
|
||||
|
@ -96,6 +114,7 @@ test('Unlike a post', async () => {
|
|||
expect(betaPost.community_local).toBe(true);
|
||||
expect(betaPost.creator_local).toBe(false);
|
||||
expect(betaPost.score).toBe(0);
|
||||
assertPostFederation(betaPost, postRes.post);
|
||||
});
|
||||
|
||||
test('Update a post', async () => {
|
||||
|
@ -116,6 +135,7 @@ test('Update a post', async () => {
|
|||
expect(betaPost.community_local).toBe(true);
|
||||
expect(betaPost.creator_local).toBe(false);
|
||||
expect(betaPost.name).toBe(updatedName);
|
||||
assertPostFederation(betaPost, updatedPost.post);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy beta cannot update the post
|
||||
|
@ -227,6 +247,7 @@ test('Delete a post', async () => {
|
|||
let searchBeta2 = await searchPost(beta, postRes.post);
|
||||
let betaPost2 = searchBeta2.posts[0];
|
||||
expect(betaPost2.deleted).toBe(false);
|
||||
assertPostFederation(betaPost2, undeletedPost.post);
|
||||
|
||||
// Make sure lemmy beta cannot delete the post
|
||||
let deletedPostBeta = await deletePost(beta, true, betaPost2);
|
||||
|
@ -257,6 +278,7 @@ test('Remove a post from admin and community on different instance', async () =>
|
|||
let searchBeta2 = await searchPost(beta, postRes.post);
|
||||
let betaPost2 = searchBeta2.posts[0];
|
||||
expect(betaPost2.removed).toBe(false);
|
||||
assertPostFederation(betaPost2, undeletedPost.post);
|
||||
});
|
||||
|
||||
test('Remove a post from admin and community on same instance', async () => {
|
||||
|
@ -277,6 +299,7 @@ test('Remove a post from admin and community on same instance', async () => {
|
|||
// Make sure lemmy alpha sees post is removed
|
||||
let alphaPost = await getPost(alpha, postRes.post.id);
|
||||
expect(alphaPost.post.removed).toBe(true);
|
||||
assertPostFederation(alphaPost.post, removePostRes.post);
|
||||
await delay();
|
||||
|
||||
// Undelete
|
||||
|
@ -287,6 +310,7 @@ test('Remove a post from admin and community on same instance', async () => {
|
|||
// Make sure lemmy alpha sees post is undeleted
|
||||
let alphaPost2 = await getPost(alpha, postRes.post.id);
|
||||
expect(alphaPost2.post.removed).toBe(false);
|
||||
assertPostFederation(alphaPost2.post, undeletedPost.post);
|
||||
});
|
||||
|
||||
test('Search for a post', async () => {
|
||||
|
|
|
@ -496,6 +496,13 @@ export async function saveUserSettingsBio(
|
|||
bio: 'a changed bio',
|
||||
auth,
|
||||
};
|
||||
return saveUserSettings(api, form);
|
||||
}
|
||||
|
||||
export async function saveUserSettings(
|
||||
api: API,
|
||||
form: UserSettingsForm
|
||||
): Promise<LoginResponse> {
|
||||
return api.client.saveUserSettings(form);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,28 @@ import {
|
|||
registerUser,
|
||||
searchForUser,
|
||||
saveUserSettingsBio,
|
||||
saveUserSettings,
|
||||
getSite,
|
||||
} from './shared';
|
||||
import {
|
||||
UserView,
|
||||
UserSettingsForm,
|
||||
} from 'lemmy-js-client';
|
||||
|
||||
let auth: string;
|
||||
let apShortname: string;
|
||||
|
||||
function assertUserFederation(
|
||||
userOne: UserView,
|
||||
userTwo: UserView) {
|
||||
expect(userOne.name).toBe(userTwo.name);
|
||||
expect(userOne.preferred_username).toBe(userTwo.preferred_username);
|
||||
expect(userOne.bio).toBe(userTwo.bio);
|
||||
expect(userOne.actor_id).toBe(userTwo.actor_id);
|
||||
expect(userOne.avatar).toBe(userTwo.avatar);
|
||||
expect(userOne.banner).toBe(userTwo.banner);
|
||||
}
|
||||
|
||||
test('Create user', async () => {
|
||||
let userRes = await registerUser(alpha);
|
||||
expect(userRes.jwt).toBeDefined();
|
||||
|
@ -28,8 +44,34 @@ test('Save user settings, check changed bio from beta', async () => {
|
|||
|
||||
let site = await getSite(alpha, auth);
|
||||
expect(site.my_user.bio).toBe(bio);
|
||||
let searchAlpha = await searchForUser(alpha, site.my_user.actor_id);
|
||||
|
||||
// Make sure beta sees this bio is changed
|
||||
let search = await searchForUser(beta, apShortname);
|
||||
expect(search.users[0].bio).toBe(bio);
|
||||
let searchBeta = await searchForUser(beta, apShortname);
|
||||
assertUserFederation(searchAlpha.users[0], searchBeta.users[0]);
|
||||
});
|
||||
|
||||
test('Set avatar and banner, check that they are federated', async () => {
|
||||
let avatar = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
||||
let banner = 'https://image.flaticon.com/icons/png/512/36/35896.png';
|
||||
let form: UserSettingsForm = {
|
||||
show_nsfw: false,
|
||||
theme: "",
|
||||
default_sort_type: 0,
|
||||
default_listing_type: 0,
|
||||
lang: "",
|
||||
avatar,
|
||||
banner,
|
||||
preferred_username: "user321",
|
||||
show_avatars: false,
|
||||
send_notifications_to_email: false,
|
||||
auth,
|
||||
}
|
||||
let settingsRes = await saveUserSettings(alpha, form);
|
||||
|
||||
let searchAlpha = await searchForUser(beta, apShortname);
|
||||
let userOnAlpha = searchAlpha.users[0];
|
||||
let searchBeta = await searchForUser(beta, apShortname);
|
||||
let userOnBeta = searchBeta.users[0];
|
||||
assertUserFederation(userOnAlpha, userOnBeta);
|
||||
});
|
Loading…
Reference in a new issue